Returning inner hits in results
In Elasticsearch, via nested and child documents, we can have complex data models. Elasticsearch, by default, returns only documents that match the searched type and not the nested/children one that matches the query.
The inner_hits
function is introduced in Elasticsearch 5.x to provide this functionality.
Getting ready
You will need an up-and-running Elasticsearch installation as used in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via a command line, you need to install curl
for your operating system.
To correctly execute the following commands, you will need an index populated with the chapter_05/populate_query.sh
script available in the online code.
How to do it...
To return inner hits during a query, we will perform the following steps:
From the command line, we can execute a call adding
inner_hits
as follows:curl -XPOST 'http://127.0.0.1:9200/test-index/test- type/_search?pretty...