0
0
ElasticsearchConceptBeginner · 3 min read

What is refresh_interval in Elasticsearch: Explanation and Usage

refresh_interval in Elasticsearch is a setting that controls how often the index is refreshed to make newly indexed documents searchable. It defines the time interval between automatic refreshes, balancing search freshness and indexing performance.
⚙️

How It Works

Imagine you have a library where new books arrive regularly, but the catalog is only updated every few minutes. In Elasticsearch, refresh_interval works like the schedule for updating that catalog. When you add or change documents, they are not immediately visible in search results. Instead, Elasticsearch waits until the next refresh to make those changes searchable.

This refresh process creates a new "view" of the index, including the latest changes. A shorter refresh_interval means updates appear faster but can slow down indexing because refreshing uses system resources. A longer interval improves indexing speed but delays when new data becomes searchable.

💻

Example

This example shows how to set the refresh_interval to 5 seconds for an index named my_index. This means Elasticsearch will refresh the index every 5 seconds, making new documents searchable at that pace.

json
PUT /my_index/_settings
{
  "index" : {
    "refresh_interval" : "5s"
  }
}
Output
{ "acknowledged" : true }
🎯

When to Use

Use refresh_interval to balance search speed and indexing performance. For example:

  • If you need near real-time search results, set a low refresh_interval like 1s.
  • If you are bulk indexing large amounts of data and can tolerate some delay before data appears in search, increase the interval to reduce system load.
  • During heavy indexing, temporarily disabling refresh (-1) can speed up the process, then re-enable it afterward.

Adjusting refresh_interval helps optimize Elasticsearch for your specific use case, whether it's fast search or efficient data loading.

Key Points

  • refresh_interval controls how often Elasticsearch makes new data searchable.
  • Short intervals improve search freshness but can reduce indexing speed.
  • Long intervals improve indexing speed but delay search visibility.
  • You can change refresh_interval dynamically without restarting Elasticsearch.
  • Setting refresh_interval to -1 disables automatic refreshes.

Key Takeaways

refresh_interval sets how often Elasticsearch refreshes an index to show new data in searches.
Shorter intervals mean fresher search results but slower indexing performance.
Longer intervals improve indexing speed but delay when new data appears in search.
You can adjust refresh_interval anytime to fit your workload needs.
Disabling refresh temporarily speeds up bulk indexing but delays search visibility.