Created
February 10, 2015 15:35
-
-
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
This file contains 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
# 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