0
0
Elasticsearchquery~5 mins

Index refresh interval in Elasticsearch - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Index refresh interval
O(n)
Understanding Time Complexity

When working with Elasticsearch, the index refresh interval controls how often new data becomes visible for searching.

We want to understand how changing this interval affects the time it takes for data to appear in search results.

Scenario Under Consideration

Analyze the time complexity of the index refresh operation with this setting.


PUT /my-index/_settings
{
  "index" : {
    "refresh_interval" : "1s"
  }
}

POST /my-index/_doc
{
  "message": "Hello Elasticsearch"
}

GET /my-index/_search
{
  "query": { "match_all": {} }
}
    

This code sets the refresh interval to 1 second, indexes a document, then searches the index.

Identify Repeating Operations

Look at what repeats during index refresh:

  • Primary operation: Periodic refresh of the index to make new data searchable.
  • How many times: Once every refresh interval (e.g., every 1 second).
How Execution Grows With Input

The refresh operation runs regularly regardless of how many documents are added.

Input Size (n)Approx. Operations
10 documentsRefresh runs every interval, processing 10 new docs
100 documentsRefresh runs every interval, processing 100 new docs
1000 documentsRefresh runs every interval, processing 1000 new docs

Pattern observation: The cost per refresh grows roughly linearly with the number of new documents since each must be made searchable.

Final Time Complexity

Time Complexity: O(n)

This means the time to refresh grows in direct proportion to the number of new documents waiting to be made searchable.

Common Mistake

[X] Wrong: "The refresh interval time directly controls how fast each refresh operation runs."

[OK] Correct: The interval controls how often refresh happens, not how long each refresh takes. The refresh time depends on how many new documents need processing.

Interview Connect

Understanding how refresh intervals affect indexing and search latency helps you balance speed and resource use in real Elasticsearch setups.

Self-Check

What if we changed the refresh interval from 1 second to 30 seconds? How would the time complexity of each refresh operation change?