Using a has_parent query/filter
In the previous recipes, we have seen the has_child
query. ElasticSearch provides a query to search child documents based on the parent query: the has_parent
query.
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_parent
query/filter, perform the following steps:
- Search for the
test-type2
children of which thetest-type
parents have a termjoe
in theparsedtext
field. Create the query as follows:curl -XPOST 'http://127.0.0.1:9200/test-index/test-type2/_search?pretty=true' -d '{ "query": { "has_parent" : { "type" : "test-type", "query" : { "term" : {
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.