Using a has_child query/filter
ElasticSearch does not only support simple documents, but it also lets you define a hierarchy based on parent and children. The has_child
query allows you to query for the parent documents of which children match some queries.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script chapter_05/populate_query.sh
, available in the code bundle for this book.
How to do it...
In order to execute the has_child
queries/filters, perform the following steps:
- Search for the parents,
test-type
, for which the children,test-type2
, 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?pretty=true' -d ...
Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.