Disadvantages of using nested type over flat type mapping

(Sankalp Sood) #1

Please tell me the disadvantages of using nested type mapping in terms of-

  1. response time
  2. data integrity
  3. transaction consistency
  4. data lay out
  5. querying data

(Junaid) #2

As per my knowledge, nested type mapping has more impact in terms of indexing over flat type mappings. Since Lucene does not have any concept of nested object types, and everything is stored as flat objects. So there is an additional operation performed at the indexing time. ES works best for flat documents. For more details, you can refer to the following links.

  1. https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-objects.html
  2. https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html#_how_arrays_of_objects_are_flattened

I don't think so there are any significant query performance impacts for nested documents. It is usually the indexing operation that suffers the most. A similar older post can be found here.

(Christian Dahlqvist) #3

When you update a nested document, all parts are updated and made available for search at the same time, which seems to be what you are looking for. As each nested document is represented by a separate document behind the scenes and all of these are reindexed for every change to the document, you can pay a significant performance penalty at index time.

As an example, let us assume we have a large nested document that translates to 10000 internal documents and compare this to a flat data model where we have indexed the 10000 parts as independent documents. If we add a single nested document at the deepest, nested level, this would add a single flat document while the nested document would end up reindexing 10001 documents. If you on the other hand change something at the root, all documents need to be updated in both cases.

This means that large nested documents are well suited for use cases with few and/or infrequent modifications.

Another disadvantage I believe is that nested documents also result in higher heap usage.

(system) closed #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.