# Does adding new fields to an existing document works like updating?

**URL:** <https://discuss.elastic.co/t/does-adding-new-fields-to-an-existing-document-works-like-updating/296720>\
**Category:** Elasticsearch\
**Created:** [February 9, 2022, 12:09pm UTC](https://discuss.elastic.co/t/does-adding-new-fields-to-an-existing-document-works-like-updating/296720 "2022-02-09T12:09:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ilia/32/60042_2.png) [@Ilia](https://discuss.elastic.co/u/Ilia)\
**Post date:** [February 9, 2022, 12:09pm UTC](https://discuss.elastic.co/t/does-adding-new-fields-to-an-existing-document-works-like-updating/296720/1 "2022-02-09T12:09:26Z")

</div>

I know the structure of `inverted index` data structure and worked with `inverted index compression algorithms`. So, I know why updating a document is not possible in inverted index and why this is simulated by inserting new document and adding the old docid to deleted docid list. I've also read how `elasticsearch` considers this deleted docids in search and hence I know `updating` is `anti-pattern`. My question is whether adding a new field to an existing document is like updating document? Considering Inverted index structure I guess no. But since adding new field is done by `update_by_query` api, the word `update` sounds misleading.

Knowing the backstage of adding new fields is so important especially for cases with dynamic and high growing fields over time.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 9, 2022, 12:23pm UTC](https://discuss.elastic.co/t/does-adding-new-fields-to-an-existing-document-works-like-updating/296720/2 "2022-02-09T12:23:52Z")

</div>

Elasticsearch relies on Lucene, which stores data in immutable segments. This means that any change (even a delete) is an update that goes into a new segment. If you add a field the document is retrieved, modified and then written as an update.

---

<div class="post-metadata">

**Author:** ![Ilia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ilia/32/60042_2.png) [@Ilia](https://discuss.elastic.co/u/Ilia)\
**Post date:** [February 9, 2022, 1:11pm UTC](https://discuss.elastic.co/t/does-adding-new-fields-to-an-existing-document-works-like-updating/296720/3 "2022-02-09T13:11:33Z")

</div>

Oh, I forgot the `segment`s! and only considered the logical structure of inverted indices. Moreover,  
I thought each field logically has its own inverted index (if so, each unique value in a field has separated inverted list) and a typical document with multiple fields can have multiple `docid`s (not necessarily the same and each of which in an specific inverted index). With having a mapping from these `docid`s to the original document, searching on multiple fields and joining the results will be possible, at least in theory!! ... and whit this implementation adding new fields will be possible whiteout simulation.

Thank you, Christian.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 9, 2022, 1:12pm UTC](https://discuss.elastic.co/t/does-adding-new-fields-to-an-existing-document-works-like-updating/296720/4 "2022-03-09T13:12:27Z")

</div>

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