Using a parent-child approach
A parent-child datatype is yet another alternative to establish relational data. In the parent-child approach, we establish the parent-child relation during index time. In a map reduce or sharded architecture, it's not possible for a map or shard to communicate with each other. The work has to be done independently by each shard. Keeping that in mind, relational data can't be maintained as a cross shard, which means I can't have the school information document in one shard and student information in another.
Hence, to establish a parent-child relation, it's required that the parent and child documents be in the same shard. Let's first see how to index parent and child documents and then how this rule is imposed.
Let's index some documents first. The index and type names are posts and post, respectively and the IDs corresponding them are manually given as 1
, 2
, and 3
, as shown in the following code:
curl -XPOST localhost:9200/posts/post/1 -d '{ "question":" elasticsearch...