Using the has_parent query
In the previous recipe, we saw the has_child query. Elasticsearch provides a query to search child documents based on the parent query, has_parent.
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 is 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
authorof the parentsbookthat has the termjoein thedescriptionfield. We can create this kind of query using the following code:
POST /mybooks-join/_search
{
"query": {
...