Using the parent-child relationship
In the previous section, we discussed the ability to index nested documents along with the parent one. However, even though the nested documents are indexed as separate documents in the index, we can't change a single nested document (unless we use the update API). However, Elasticsearch allows us to have a real parent-child relationship and we will look at it in the following section.
Index structure and data indexing
Let's use the same example that we used when discussing the nested documents—the hypothetical cloth store. However, what we would like to have is the ability to update sizes and colors without the need to index the whole document after each change.
Parent mappings
The only field we need to have in our parent document is name
. We don't need anything more than that. So, in order to create our cloth
type in the shop
index, we will run the following commands:
curl -XPOST 'localhost:9200/shop' curl -XPUT 'localhost:9200/shop/cloth/_mapping' -d '...