Bird
Raised Fist0
Elasticsearchquery~10 mins

Index refresh interval in Elasticsearch - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - Index refresh interval
Index receives new data
Data stored in memory (translog)
Wait for refresh interval timer
Refresh triggered
In-memory data made searchable
New data visible in search results
Wait for next refresh interval
New data is first stored in memory, then after the refresh interval, it becomes searchable.
Execution Sample
Elasticsearch
PUT /my_index/_settings
{
  "index.refresh_interval": "5s"
}
Sets the index refresh interval to 5 seconds, controlling how often new data becomes searchable.
Execution Table
StepActionRefresh Interval TimerData StateSearch Visibility
1Index receives new documentTimer startsData in memory (not searchable)No
2Wait 3 secondsTimer counting down (2s left)Data still in memoryNo
3Wait 2 more secondsTimer reaches 0Data refreshedYes
4New data visible in searchTimer resets to 5sData searchableYes
5Index receives another documentTimer runningNew data in memoryNo
6Wait 5 secondsTimer reaches 0Data refreshedYes
7New data visible in searchTimer resetsData searchableYes
8StopN/AN/AN/A
💡 Process repeats every refresh interval; stops here for demonstration.
Variable Tracker
VariableStartAfter Step 1After Step 3After Step 5After Step 6Final
Refresh Interval Timer5s5s (started)0s (refresh triggered)5s (started again)0s (refresh triggered)5s (ready for next)
Data StateNo dataIn memory (not searchable)Refreshed (searchable)In memory (new data)Refreshed (searchable)Searchable
Search VisibilityNoNoYesNoYesYes
Key Moments - 3 Insights
Why is new data not immediately searchable after indexing?
Because data is first stored in memory and only becomes searchable after the refresh interval timer reaches zero, as shown in execution_table rows 1 and 3.
What happens when the refresh interval timer reaches zero?
The in-memory data is refreshed and made searchable, as seen in execution_table row 3 where Search Visibility changes from No to Yes.
Does the refresh interval timer reset after each refresh?
Yes, the timer resets to the configured interval after each refresh, shown in execution_table rows 4 and 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the data become searchable for the first time?
AStep 1
BStep 5
CStep 3
DStep 6
💡 Hint
Check the 'Search Visibility' column in execution_table rows.
According to variable_tracker, what is the value of the Refresh Interval Timer after Step 5?
A5s
B0s
C3s
DN/A
💡 Hint
Look at the 'Refresh Interval Timer' row in variable_tracker after Step 5.
If the refresh interval is set to 10s instead of 5s, how would the timer values change in the execution_table?
ATimer would count down from 5s as before
BTimer would count down from 10s instead of 5s
CTimer would reset to 0s immediately
DTimer would stop running
💡 Hint
Consider the meaning of the refresh interval setting shown in execution_sample.
Concept Snapshot
Index refresh interval controls how often Elasticsearch makes new data searchable.
Data is first stored in memory, then refreshed at intervals (default 1s).
Setting a longer interval reduces overhead but delays search visibility.
Use PUT /index/_settings with "index.refresh_interval" to change it.
Example: "index.refresh_interval": "5s" means refresh every 5 seconds.
Full Transcript
The index refresh interval in Elasticsearch determines how often new data becomes visible in search results. When data is indexed, it is first stored in memory and not immediately searchable. A timer counts down the refresh interval, and when it reaches zero, Elasticsearch refreshes the index, making the new data searchable. This process repeats continuously. Setting a longer refresh interval reduces system load but delays when new data appears in searches. You can change the refresh interval using the index settings API, for example setting it to 5 seconds. The execution table shows the timer counting down and data state changes step by step, while the variable tracker records the timer and data visibility states. Key moments clarify why data isn't searchable immediately and how the timer resets after each refresh. The visual quiz tests understanding of these steps and timer behavior.

Practice

(1/5)
1. What does the index.refresh_interval setting control in Elasticsearch?
easy
A. The number of shards in the index
B. The size limit of the index
C. How often the index makes new data searchable
D. The maximum number of replicas

Solution

  1. Step 1: Understand the role of index.refresh_interval

    This setting controls the frequency at which Elasticsearch refreshes the index to make newly indexed data searchable.
  2. Step 2: Compare with other options

    The other options relate to the number of shards, size limits, and replicas, which are unrelated to refresh timing.
  3. Final Answer:

    How often the index makes new data searchable -> Option C
  4. Quick Check:

    Refresh interval = data searchable frequency [OK]
Hint: Refresh interval means how often new data appears [OK]
Common Mistakes:
  • Confusing refresh interval with shard count
  • Thinking it controls index size
  • Mixing it up with replica settings
2. Which of the following is the correct way to set the refresh interval to 5 seconds in an Elasticsearch index settings JSON?
easy
A. { "refresh_interval": 5 }
B. { "index": { "refresh_interval": "5000" } }
C. { "index": { "refresh_interval": 5 } }
D. { "index": { "refresh_interval": "5s" } }

Solution

  1. Step 1: Identify correct JSON structure for refresh interval

    The refresh interval must be a string with time units, inside the index object.
  2. Step 2: Validate options

    { "index": { "refresh_interval": "5s" } } uses "5s" (5 seconds) correctly as a string with units. Plain numbers like 5 without units are invalid. { "index": { "refresh_interval": "5000" } } uses "5000" without units, which is incorrect. Missing the index object is also invalid.
  3. Final Answer:

    { "index": { "refresh_interval": "5s" } } -> Option D
  4. Quick Check:

    Refresh interval needs string with units [OK]
Hint: Use string with time unit like "5s" for refresh interval [OK]
Common Mistakes:
  • Using number without time unit
  • Placing refresh_interval outside index object
  • Using milliseconds as plain number string
3. Given the following index setting:
{ "index": { "refresh_interval": "30s" } }

What happens if you index a document and immediately search for it within 10 seconds?
medium
A. The document will not be found until after 30 seconds
B. The document will be found immediately
C. The document will never be found
D. The document will be found after 10 seconds

Solution

  1. Step 1: Understand refresh interval effect on search

    With a 30-second refresh interval, Elasticsearch refreshes the index every 30 seconds to make new data searchable.
  2. Step 2: Analyze timing of search after indexing

    If you search within 10 seconds, the index has not refreshed yet, so the new document is not visible.
  3. Final Answer:

    The document will not be found until after 30 seconds -> Option A
  4. Quick Check:

    Refresh interval delays new data visibility [OK]
Hint: Search before refresh interval means no new data visible [OK]
Common Mistakes:
  • Assuming instant search visibility
  • Confusing refresh interval with indexing speed
  • Thinking document is never searchable
4. You set index.refresh_interval to -1 to disable automatic refresh during heavy indexing. After indexing, you want to make all data searchable immediately. What is the correct way to do this?
medium
A. Set index.refresh_interval back to 0
B. Run a manual _refresh API call on the index
C. Restart the Elasticsearch cluster
D. Delete and recreate the index

Solution

  1. Step 1: Understand disabling refresh with -1

    Setting refresh_interval to -1 disables automatic refresh, so new data is not searchable until manually refreshed.
  2. Step 2: Identify how to make data searchable immediately

    Using the _refresh API triggers an immediate refresh, making all indexed data searchable without restarting or recreating.
  3. Final Answer:

    Run a manual _refresh API call on the index -> Option B
  4. Quick Check:

    Manual refresh needed when auto refresh disabled [OK]
Hint: Use _refresh API to make data searchable after disabling refresh [OK]
Common Mistakes:
  • Setting refresh_interval to 0 instead of calling _refresh
  • Restarting cluster unnecessarily
  • Deleting index instead of refreshing
5. You have an index with heavy write load and want to optimize indexing speed without losing data visibility for search. Which approach best balances performance and freshness?
hard
A. Set index.refresh_interval to a higher value during indexing, then manually refresh after bulk load
B. Set index.refresh_interval to 0 to refresh after every write
C. Disable refresh permanently by setting index.refresh_interval to -1 and never refresh
D. Delete the index and create a new one for each bulk load

Solution

  1. Step 1: Understand trade-off between refresh interval and indexing speed

    Frequent refreshes slow indexing but improve data freshness; less frequent refreshes speed indexing but delay visibility.
  2. Step 2: Choose best practice for heavy write load

    Setting a higher refresh interval during bulk indexing reduces refresh overhead, then manually refreshing after bulk load balances speed and search freshness.
  3. Final Answer:

    Set index.refresh_interval to a higher value during indexing, then manually refresh after bulk load -> Option A
  4. Quick Check:

    Adjust refresh interval for bulk, then manual refresh [OK]
Hint: Increase refresh interval during bulk, refresh manually after [OK]
Common Mistakes:
  • Setting refresh_interval to 0 causes slow indexing
  • Disabling refresh permanently loses search freshness
  • Deleting index wastes resources