Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are documents in elasticsearch immutable?

I am trying to get a hang of elasticsearch. Was reading through the definitive guide.

They've mentioned that the update API does a retrieve-change-reindex cycle each time I update something in a document. And I completely get that this is done because they say that "Documents are immutable"(see this). What I am questioning here is why have it immutable in the first place. Wouldn't there be an advantage of allowing update and index of just a particular field hadn't this been the constraint?

like image 982
quickbrownfox Avatar asked Dec 11 '22 23:12

quickbrownfox


1 Answers

First , it's better to tell segments are immutable than telling documents are immutable. To understand the reason. You need to understand how lucene works. Lucerne is a java library on top of which elasticsearch is built. Under the hood a single shard is a lucene instance and it does the actual work of documents storage and search . Elasticsearch is more of a distributed REST based server layer on top of lucene.

In lucene in order to achieve high Indexing speed we have segment architecture. A bunch of files are kept in a segment where each segment is a single file in the disk. As file in between write operation is very heavy , a segment is made immutable so that all subsequent writes go to New segments.

like image 105
Vineeth Mohan Avatar answered Jan 12 '23 00:01

Vineeth Mohan