Skip to content

Instantly share code, notes, and snippets.

@brusic
Created February 16, 2012 06:54
Show Gist options
  • Save brusic/1842773 to your computer and use it in GitHub Desktop.
Save brusic/1842773 to your computer and use it in GitHub Desktop.
// TEST DATA
curl -XPUT http://localhost:9200/twitter/user/kimchy -d '{
"name" : "Shay Banon"
}'
curl -XPUT http://localhost:9200/twitter/tweet/1 -d '{
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out elasticsearch, so far so good?"
}'
curl -XPUT http://localhost:9200/twitter/tweet/2 -d '{
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "You know, for Search"
}'
// Successful GET requests
// no fields specified
$ curl "http://localhost:9200/twitter/tweet/2?pretty=true"
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "2",
"_version" : 1,
"exists" : true, "_source" : {
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "You know, for Search"
}
// specific fields
$ curl "http://localhost:9200/twitter/tweet/2?pretty=true&fields=user,message"
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "2",
"_version" : 1,
"exists" : true,
"fields" : {
"message" : "You know, for Search",
"user" : "kimchy"
}
}
// Unsuccessful GET requets - wildcard "*" fields requested
$ curl "http://localhost:9200/twitter/tweet/2?pretty=true&fields=*"
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "2",
"_version" : 1,
"exists" : true
}
// Search requests work with wildcard fields
curl "http://localhost:9200/twitter/tweet/_search?pretty=true&q=user:kimchy&fields=*"
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "2",
"_score" : 1.0, "_source" : {
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "You know, for Search"
}
}, {
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_score" : 0.30685282, "_source" : {
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out elasticsearch, so far so good?"
}
} ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment