In the previous recipes, we have seen the has_child
query. ElasticSearch provides a query to search a child based on the has_parent
parent query.
You need a working ElasticSearch cluster and the data populated with the populate script.
For executing the has_parent
query/filter, we need to perform the following steps:
We want to search the
test-type2
children of which thetest-type
parents have a termjoe
in theparsedtext
field. We can create this kind of query as follows:curl -XPOST 'http://127.0.0.1:9200/test-index/test-type2/_search' -d '{ "query": { "has_parent" : { "type" : "test-type", "query" : { "term" : { "parsedtext" : "joe" } } } } } }'
If scoring is not important, it's better to reformulate the query as a filter in the following way:
curl -XPOST 'http://127.0.0.1:9200/test...