Search code examples
databaseelasticsearchforeign-keys

Elastic Search: Parent child vs Nested Document


P.S: We are using Elastic 6.x

AS Elastic Search is upgraded few breaking changes are also popped out. We have some relational data which requires to be managed either nested or parent/child mode.

For Final decision I was wondering with following questions:

  • How many nested documents/array size I can save in one field
  • We have to manipulate the fields often so whats the recommendation if we use nested field type
  • What are the limitations of Parent/child if we use 4 types of relations

I believe, answers of the above questions can help me decide the field type, let me know if there is any other thing I should consider

Thanks in advance


Solution

  • How many nested documents/array size i can save in one field

    By default, you can have a maximum of 50 nested fields defined per index. In each of those nested fields arrays, you may store any number of elements.

    We have to manipulate the fields often so whats the recommendation if we use nested field type

    That's where nested fields come short, as whenever a nested document changes, you either have to reindex the whole parent document or figure out via scripting which nested document to update, but it can quickly get quite convoluted.

    What are the limitations of Parent/child if we use 4 types of relations

    In ES 6.x onwards, you're limited to a single join field per index.

    As it looks like, it doesn't seem like either nested fields nor parent/child would work well in your case... Maybe there's another possible design if you are willing to denormalize a little bit more your data, but hard to say without getting more detailed information about your preceise use case.

    Choosing Parent/Child vs Nested Document