0
votes

While going through elasticsearch documentation on Parent-Child relationship I found this line and I am not to sure about it.

the parent document and all of its children must live on the same shard.

Use Case:

  • I have a Elasticsearch index in parent-child relationship with two types company[parent] and employee[child]
  • The records to be indexed are in these pattern 1 parent has more than 100 child.
  • The volume of the index is big so we need to shard them across multiple systems

As per the statement both parent and child as to reside in the same shard since we are sharding across multiple systems is there chance that parent and child may reside in different shard.

if so how to avoid them? if not please explain?

1

1 Answers

1
votes

Every document use _routing field that points to some shard. Read more about routing here.

The default value used for _routing is the document’s _id or the document’s _parent ID, if present.

It means that by default all your child documents will be on the same shard with their parent documents.
Your case is pretty simple, so using defaults there is no chance that parent and child may reside in different shard.

But if relation is grand-parent or even more complex, you need to set routing manually. More details here