Skip to content

Instantly share code, notes, and snippets.

@bbansal
Created February 22, 2013 02:41
Show Gist options
  • Save bbansal/5010329 to your computer and use it in GitHub Desktop.
Save bbansal/5010329 to your computer and use it in GitHub Desktop.
Elastic search nested query issue
# Create a new index
curl -XPUT http://localhost:9200/newindex
# Create a nested mapping
curl -XPUT http://localhost:9200/newindex/foo/_mapping -d '{"foo" : {"properties": { "nested_field" : { "type": "nested" }} }}'
# Add a document
curl -XPUT http://localhost:9200/newindex/foo/5812395 -d '{ "nested_field" : [ { "name" : "blue", "count" : 4 }, { "name" : "green", "count" : 6 } ], "id":5812395 }'
# Refresh the index
curl -XPOST http://localhost:9200/newindex/_refresh
# Query the nested for one pair of nested values.
curl -XGET http://localhost:9200/newindex/foo/_search?pretty=true -d '{ "query" : {"nested" : { "path" : "nested_field", "query": { "query_string": { "query": "name:blue AND count:4" }}}}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment