In the Document Relations section in Chapter 3, Modeling Your Data and Document Relations, we described how to store nested documents. In this section, we will discuss how to query them. To better explain querying nested documents, we will change the mappings of the chapter7 index to store the variations of a product as nested documents. For example, an iPhone is available in several storage options, such as 32GB, 64GB, and so on. Each variation has a different price. Each variation of a product will be stored as a nested document. A product can have one or more variations. In the following query, we will change the mapping of the type product to include the variations as nested documents:
#Delete existing index
DELETE chapter7
#Set mappings
PUT chapter7
{
"settings": {},
"mappings": {
"product": {
...