Using the has_child query
Elasticsearch does not only support simple unrelated documents but also lets you define a hierarchy based on parents and children. The has_child
query allows you to query parent documents of children by matching other queries.
Getting ready
As we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started, you need an up-and-running Elasticsearch installation to execute the current recipe code.
To execute the code in the following section, any HTTP client can be used. This includes curl (https://curl.haxx.se/), Postman (https://www.getpostman.com/), or other similar versions. 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, available in the online code.
The index used in this recipe is mybooks...