In the previous recipe, the has_child
query consumes a large amount of memory because it requires to fetch IDs of all the children. To bypass this limitation in huge data contexts the top_children
query allows fetching only the top children results.
You need a working ElasticSearch cluster and the data populated with the populate script.
For executing the top_children
query, we need to perform the following steps:
We need to search the
test-type
parents of which thetest-type2
top 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": { "top_children" : { "type" : "test-type2", "query" : { "term" : { "value" : "value1" } }, "score" : "max", "factor" : 5, ...