Created
April 26, 2013 18:45
-
-
Save telvis07/5469479 to your computer and use it in GitHub Desktop.
Working example for https://github.com/elasticsearch/elasticsearch/issues/2674
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# index the information for user with id 2, specifically, its friends | |
curl -XPUT localhost:9200/users/user/2 -d '{ | |
"friends" : ["1", "3"] | |
}' | |
# index a tweet, from user with id 2 | |
curl -XPUT localhost:9200/tweets/tweet/1 -d '{ | |
"user" : "1", | |
"tweet" : "hi i am user 1 " | |
}' | |
# index a tweet, from user with id 2 | |
curl -XPUT localhost:9200/tweets/tweet/2 -d '{ | |
"user" : "2", | |
"tweet" : "hi i am user 2 " | |
}' | |
# index a tweet, from user with id 2 | |
curl -XPUT localhost:9200/tweets/tweet/3 -d '{ | |
"user" : "3", | |
"tweet" : "hi i am user 3 " | |
}' | |
curl -XPOST localhost:9200/_refresh | |
# search on all the tweets that match the friends of user 2 | |
curl -XGET localhost:9200/tweets/_search?pretty=true -d '{ | |
"query" : { | |
"filtered" : { | |
"filter" : { | |
"terms" : { | |
"user" : { | |
"index" : "users", | |
"type" : "user", | |
"id" : "2", | |
"path" : "friends" | |
}, | |
"_cache_key" : "user_2_friends" | |
} | |
} | |
} | |
} | |
}' | |
# returns | |
#"hits" : { | |
# "total" : 2, | |
# "max_score" : 1.0, | |
# "hits" : [ { | |
# "_index" : "tweets", | |
# "_type" : "tweet", | |
# "_id" : "1", | |
# "_score" : 1.0, "_source" : { | |
# "user" : "1", | |
# "tweet" : "hi i am user 1 " | |
#} | |
# }, { | |
# "_index" : "tweets", | |
# "_type" : "tweet", | |
# "_id" : "3", | |
# "_score" : 1.0, "_source" : { | |
# "user" : "3", | |
# "tweet" : "hi i am user 3 " | |
#} | |
# } ] | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment