ElasticSearch does not provide only simple documents, but it lets you define a hierarchy based on parent and child. The has_child
query allows querying for parent documents of which the children verify some queries.
You need a working ElasticSearch cluster and the data populated with the populate script.
For executing the has_child
query/filter, we need to perform the following steps:
We need to search the
test-type
parents of which thetest-type2
children have a term in the field value asvalue1
. We can create this kind of query as follows:curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search' -d '{ "query": { "has_child" : { "type" : "test-type2", "query" : { "term" : { "value" : "value1" } } } } } }'
If scoring is not important, it's better to reformulate the query as a...