# When no write, why Elasticsearch performs indexing every 'n' seconds?

**URL:** <https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958>\
**Category:** Open Source Elasticsearch and Kibana\
**Tags:** discuss\
**Created:** [September 8, 2021, 8:53am UTC](https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958 "2021-09-08T08:53:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpatil](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dpatil](https://forum.opensearch.org/u/dpatil)\
**Post date:** [September 8, 2021, 8:53am UTC](https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958/1 "2021-09-08T08:53:10Z")

</div>

Hello All,

I have basic question regarding elastic search.

As per documentation : **By default, Elasticsearch periodically refreshes indices every second, but only on indices that have received one search request or more in the last 30 seconds.**  
Reference: [Refresh API | Elasticsearch Guide [8.4] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html#refresh-api-desc)

Also as per documentation: **When a document is stored, it is indexed and fully searchable in near real-time–within 1 second.**  
Reference : [Data in: documents and indices | Elasticsearch Guide [7.14] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.14/documents-indices.html)

So when write happens, indexing happen. When write is not happening and documents are already indexed, then why elastic search indexes every 1 second existing documents?

---

<div class="post-metadata">

**Author:** ![reta](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@reta](https://forum.opensearch.org/u/reta)\
**Post date:** [September 8, 2021, 12:52pm UTC](https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958/2 "2021-09-08T12:52:44Z")

</div>

Hey Deepak,

AFAIK, the refresh does not only apply to newly indexed data, but also tries to prune the tombstones along the way (previously deleted documents). So even nothing is being indexed, the routine index maintenance may be necessary. Hope it makes sense.

Best Regards,  
Andriy Redko

---

<div class="post-metadata">

**Author:** ![dpatil](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dpatil](https://forum.opensearch.org/u/dpatil)\
**Post date:** [September 8, 2021, 1:35pm UTC](https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958/3 "2021-09-08T13:35:29Z")

</div>

Hi Andriy,

Thank you very much for answer.

Your answer completely makes sense.

Thanks and regards,  
Deepak.

---

<div class="post-metadata">

**Author:** ![dpatil](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dpatil](https://forum.opensearch.org/u/dpatil)\
**Post date:** [September 9, 2021, 8:59am UTC](https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958/4 "2021-09-09T08:59:03Z")

</div>

Hi Andriy,

For my edification, does Inserting or Updating a single document, cause the entire Index to be re-created OR is the Index simply updated very optimally ? I believe it would be the latter.

Also is the performance of adding new records and indexes being updated an O(1) or an O( n) operation ?

Thanks in advance for your answer.

Thanks and Regards,  
Deepak

---

<div class="post-metadata">

**Author:** ![reta](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@reta](https://forum.opensearch.org/u/reta)\
**Post date:** [September 9, 2021, 3:16pm UTC](https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958/5 "2021-09-09T15:16:16Z")

</div>

Hi Deepak,

> For my edification, does Inserting or Updating a single document, cause the entire Index to be re-created OR is the Index simply updated very optimally ? I believe it would be the latter.

OpenSearch uses Apache Lucene under the hood. Index (ingest new document) operation is straightforward but update is not - it is equivalent to soft delete / insert new document. I am not sure what you mean by “entire Index to be re-created” though, could you elaborate a bit?

> Also is the performance of adding new records and indexes being updated an O(1) or an O( n) operation ?

I don’t think O() notation would strictly apply here, it is a function of index settings (mappings / replication / shards / routing / …), bulk / non-bulk operation and also the document size. But intuitively, indexing new documents should be more lightweight than updating the existing ones.

Best Regards,  
Andriy Redko

---

<div class="post-metadata">

**Author:** ![dpatil](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dpatil](https://forum.opensearch.org/u/dpatil)\
**Post date:** [September 15, 2021, 6:23am UTC](https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958/6 "2021-09-15T06:23:03Z")

</div>

Apologies for using the word re-create; I will paraphrase. I was wanting to know if inserting a single document causes the entire index to be re-built.

My question around O(1) Vs O ( n) was to confirm : That the time required to Index a new document remains same regardless of 10 or a million pre-existing documents in the Index. Meaning, the time required to Index new Documents does not increase, when I have a million records in the Index ?

---

<div class="post-metadata">

**Author:** ![reta](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@reta](https://forum.opensearch.org/u/reta)\
**Post date:** [September 15, 2021, 2:11pm UTC](https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958/7 "2021-09-15T14:11:28Z")

</div>

Thank you for clarifying. The index won’t be rebuilt and the amount of the documents in the index should not have noticeable impact on the new document insertion (in general, but there are exceptions, for example, when index has rollover policy, the new document insertion may lead to new index creation).

---

<div class="post-metadata">

**Author:** ![dpatil](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dpatil](https://forum.opensearch.org/u/dpatil)\
**Post date:** [September 21, 2021, 10:03am UTC](https://forum.opensearch.org/t/when-no-write-why-elasticsearch-performs-indexing-every-n-seconds/6958/8 "2021-09-21T10:03:08Z")

</div>

Thank you very much. That was great help.

Regards,  
Deepak
