Skip to content

Instantly share code, notes, and snippets.

@kimchy
Created December 11, 2010 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimchy/737631 to your computer and use it in GitHub Desktop.
Save kimchy/737631 to your computer and use it in GitHub Desktop.
curl -XPUT localhost:9200/test/type1/1 -d '{
"value" : 1
}'
curl -XPUT localhost:9200/test/type1/2 -d '{
"value" : 2
}'
curl -XPUT localhost:9200/test/type1/3 -d '{
"value" : 3
}'
curl -XPUT localhost:9200/test/type1/4 -d '{
"value" : 4
}'
curl -XPOST localhost:9200/_refresh
#Term query on 2
curl -XGET localhost:9200/test/_search -d '{
"query" : {
"term" : {
"value" : 2
}
}
}'
# Query String on 2
curl -XGET localhost:9200/test/_search -d '{
"query" : {
"query_string" : {
"query" : "value:2"
}
}
}'
#Query String on 2 or 3
curl -XGET localhost:9200/test/_search -d '{
"query" : {
"query_string" : {
"query" : "value:2 OR value:3"
}
}
}'
# Query String on 2 or 3 without needing to prefix by field, since value
# is the default field
curl -XGET localhost:9200/test/_search -d '{
"query" : {
"query_string" : {
"default_field" : "value",
"query" : "2 OR 3"
}
}
}'
# And field query, which is similar to query_string, simply auto
# setting the default_field to the field in queries on
curl -XGET localhost:9200/test/_search -d '{
"query" : {
"field" : {
"value" : "2 OR 3"
}
}
}'
#And last, OR can be done with bool on term queries as well...
curl -XGET localhost:9200/test/_search -d '{
"query" : {
"bool" : {
"should" : [
{ "term" : { "value" : 2 } },
{ "term" : { "value" : 3 } }
]
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment