Using the has_parent query
In the previous recipe, we saw the has_child
query. Elasticsearch also provides a query to search child documents based on the parent query, has_parent
, which complements the previous query.
Getting ready
You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.
To execute these commands, I suggest using the Kibana console, as this provides code completion and better character escaping for Elasticsearch.
To correctly execute the following commands, you will need an index populated with the ch04/populate_kibana.txt
commands, which are available in the online code. The index that's used in this recipe is mybooks-join
.
How to do it...
To execute the has_parent
query, we will perform the following steps:
- We want to search for the children (
author
) of the parent (book
) that has thebill
term in...