# Why lucene index files are deleted when document is inserted/updated?

**URL:** <https://discuss.elastic.co/t/why-lucene-index-files-are-deleted-when-document-is-inserted-updated/152808>\
**Category:** Elasticsearch\
**Created:** [October 17, 2018, 11:01am UTC](https://discuss.elastic.co/t/why-lucene-index-files-are-deleted-when-document-is-inserted-updated/152808 "2018-10-17T11:01:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikhil.k](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nikhil.k](https://discuss.elastic.co/u/nikhil.k)\
**Post date:** [October 17, 2018, 11:01am UTC](https://discuss.elastic.co/t/why-lucene-index-files-are-deleted-when-document-is-inserted-updated/152808/1 "2018-10-17T11:01:33Z")

</div>

Hi All,

Elasticsearch - 5.4.3

I'm updating a document by using the command:

# curl -X POST "node1:9200/index1/external/1/\_update?pretty" -H 'Content-Type: application/json' -d'

{  
"doc": { "name": "Elastic" }  
}'

When a document is updated, it is observed that first the data is inserted in the index and then in the lucene index files (such as \_1.cfs, \_1\_Lucene50\_0.doc, \_1\_Lucene50\_0.tim, \_1\_Lucene54\_0.dvd, etc. ) successfully using write system call.

For eg.

> write fd=171(/var/lib/elasticsearch/nodes/0/indices/fxXTEfKZScmU7emMgJg01Q/3/index/\_1\_Lucene54\_0.dvd) size=84

After writing the lucene files and all the files are closed.

But after closing all the files, these files are deleted using the unlink systemcall.  
For eg.

> unlink res=0 path=/var/lib/elasticsearch/nodes/0/indices/fxXTEfKZScmU7emMgJg01Q/3/index/\_1\_Lucene54\_0.dvd

When a GET API command is executed to get the updated document, it is observed that the document is fetched successfully.

Can anyone explain why elasticsearch deletes all the lucene index files after inserting data in them?

Note: This same behaviour is observed when the document is inserted in the elasticsearch

Regards  
Nikhil Kapoor

---

<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:** [October 17, 2018, 11:43am UTC](https://discuss.elastic.co/t/why-lucene-index-files-are-deleted-when-document-is-inserted-updated/152808/2 "2018-10-17T11:43:12Z")

</div>

All Lucerne segments are immutable, and are merged as data is indexed/updated. Once no longer in use following a merge, they are deleted.

---

<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:** [November 14, 2018, 11:43am UTC](https://discuss.elastic.co/t/why-lucene-index-files-are-deleted-when-document-is-inserted-updated/152808/3 "2018-11-14T11:43:18Z")

</div>

Closed on November 14, 2018, 11:43am UTC

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