Skip to content

Instantly share code, notes, and snippets.

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 hkorte/ca5f91e2f4838213d956 to your computer and use it in GitHub Desktop.
Save hkorte/ca5f91e2f4838213d956 to your computer and use it in GitHub Desktop.
An Elasticsearch gist for the thread "exist filter also matching on nested fields": https://groups.google.com/forum/#!topic/elasticsearch/8R9XgVkCZIU
# Remove old data
curl -XDELETE "http://localhost:9200/nestedfiltertest?pretty"
# Create index with nested type mapping
curl -XPUT "http://localhost:9200/nestedfiltertest/?pretty" -d '
{
"mappings": {
"doc": {
"properties": {
"nested": {
"type": "nested",
"properties": {
"group_id": {
"type": "string"
}
}
}
}
}
}
}'
# Index some data
curl -XPUT "http://localhost:9200/nestedfiltertest/doc/1?pretty" -d '
{
"group_id": "xxx"
}'
curl -XPUT "http://localhost:9200/nestedfiltertest/doc/2?pretty" -d '
{
"nested": {
"group_id": "xxx"
}
}'
curl -XPUT "http://localhost:9200/nestedfiltertest/doc/3?pretty" -d '
{
"abc": "yyy"
}'
curl -XPOST 'http://localhost:9200/nestedfiltertest/_flush?pretty'
echo "### Test query: ###"
curl -XPOST "http://localhost:9200/nestedfiltertest/_search?pretty" -d '
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"exists": {
"field": "group_id"
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment