0
0
Elasticsearchquery~5 mins

Index refresh interval in Elasticsearch

Choose your learning style9 modes available
Introduction
The index refresh interval controls how often Elasticsearch makes new data searchable. It helps balance speed and performance.
When you want new data to appear quickly in search results.
When you want to reduce system load by refreshing less often.
When you are indexing large amounts of data and want to optimize speed.
When you want to control how fresh your search results are.
When tuning Elasticsearch for different workloads like logging or analytics.
Syntax
Elasticsearch
PUT /my_index/_settings
{
  "index": {
    "refresh_interval": "30s"
  }
}
The refresh_interval value can be set in seconds (e.g., "30s") or milliseconds (e.g., "500ms").
Setting refresh_interval to -1 disables automatic refreshes.
Examples
Sets the refresh interval to 1 second, so new data becomes searchable every second.
Elasticsearch
PUT /my_index/_settings
{
  "index": {
    "refresh_interval": "1s"
  }
}
Disables automatic refresh. Use this during heavy indexing to improve speed.
Elasticsearch
PUT /my_index/_settings
{
  "index": {
    "refresh_interval": -1
  }
}
Sets refresh interval to 5 seconds, balancing freshness and performance.
Elasticsearch
PUT /my_index/_settings
{
  "index": {
    "refresh_interval": "5s"
  }
}
Sample Program
Creates an index named 'test_index' with a refresh interval of 10 seconds, then retrieves the settings to confirm.
Elasticsearch
PUT /test_index
{
  "settings": {
    "index": {
      "refresh_interval": "10s"
    }
  }
}

GET /test_index/_settings
OutputSuccess
Important Notes
A shorter refresh interval means data appears in search results faster but uses more resources.
A longer refresh interval improves indexing speed but delays data visibility in searches.
You can change the refresh interval anytime without reindexing your data.
Summary
The index refresh interval controls how often new data is searchable.
Set it shorter for fresh data or longer for better indexing performance.
You can disable automatic refresh during heavy indexing to speed up the process.