As an experienced full-stack and Elasticsearch developer, refresh is an operation that needs to be handled judiciously. When utilized correctly, it can provide up-to-date visibility into your latest index changes. However, excessive manual refreshing can degrade cluster performance.
In this comprehensive 3429 word guide, you‘ll gain an in-depth understanding of the internal workings of the Elasticsearch refresh API with stats, visualizations, and actionable insights on optimization best practices.
When Should You Manually Refresh?
Out of the box, Elasticsearch periodically refreshed indices every 30 seconds. This means updated documents won‘t appear in your search results for up to that duration after being indexed.
This higher latency is often acceptable in most production systems. However, certain use cases warrant forcing an immediate refresh:
- Populating indices from external databases– After using logstash or ingest pipelines to populate Elasticsearch from MongoDB, you need the new documents immediately available for querying without waiting for the next automated cycle:
// Index documents from MongoDB
ingestDataFromMongoDB()
// Refresh to make available for search
POST /my-index/_refresh
- Bulk loading data– When bulk importing JSON, CSV or other datasets directly (without ingest pipelines), a refresh makes the bulk operation visible:
// Bulk index large dataset
POST _bulk
{ "index": { "_index": "logs", "_id": 1 }}
{ "event": "User logged in" }
// Refresh to make new events searchable
POST /logs/_refresh
- Faster feedback loops when developing– During rapid iterations on an app posting data to Elasticsearch, frequent refreshes give faster feedback:
// Index document from app
indexDocument()
// Refresh to immediately test searches
POST /my-index/_refresh
// Query and inspect search results
GET /_search
However, outside of these specific use cases, Refreshing too often will just impose load without benefit.
How Refresh Compares to Other Data Stores
It‘s also insightful to compare the refresh handling across popular data stores:
| Store | Default Refresh Cycle | Notes |
|---|---|---|
| Elasticsearch | 30 seconds | Auto periodic refresh |
| MongoDB | Immediate | No async refresh needed |
| Redis | Instant | In-memory datastore |
As Elasticsearch is optimized for search use cases, the inverted indices and cached data structures require periodic re-syncing to lower storage overhead.
Let‘s now dive deeper into the manual refresh API…
Basic API Usage
The Refresh API supports both GET and POST HTTP methods. You can specify:
- Specific index name
- Index alias
_allfor all indices- No parameter to refresh all eligible open indices
Some examples:
// By index name
POST /users/_refresh
// By alias
POST /site_logs/_refresh
// All indices
POST /_refresh
// Blank refreshes all indices
POST /_refresh
The API will synchronously reload the specified indices and return a confirmation:
{
" _shards": {
"total": 2,
"successful": 2,
"failed": 0
}
}
Now let‘s analyze the performance impact and inner workings further…
What Happens During a Refresh?
Under the hood, when a refresh is triggered, Elasticsearch will reroute any new documents in the translog (write buffer) to the background indexing process. This makes document available to search by updating the _source field data stored on disk.

Diagram showing document flow during refresh. (Image source: Elastic)
Additionally, it recalculates the other inverted indices, caches and data structures powering performant queries.
As you can imagine, with large indices spanning hundreds of gigabytes and billions of documents, this can be a heavyweight process. Maximizing the automatic periodic refresh allows minimizing expensive disk i/o and recomputation.
Let‘s analyze the performance impact further…
Quantifying the Performance Overheads
While fast iterations are useful when developing, as datasets grow in production, you need to carefully monitor refresh cycles.
The _stats API provides numbers on the total refreshes and time for analysis:
GET /_stats/refresh
For example, here is sample output:
{
"indices": {
"index-1": {
"total": 1024,
"total_time": "2m"
},
"index-2": {
"total": 512
"total_time": "1m"
}
}
}
This reveals index-1 took 2 minutes for 1024 refreshes while index-2 took 1 minute for 512 refreshes.
We can also visualize this refresh frequency comparison:

You can derive the average time per automatic refresh from total_time / total. Faster than 40-50ms indicates possible contention.
Now let‘s explore shard level metrics…
Shard Statistics
As indices grow larger, it becomes critical to track refresh statistics by primary shard. The /_stats API exposes these details:
{
"indices": {
"index-1": {
"shards": {
"0": [
{
"refresh": {
"total": 205,
"total_time_in_millis": 102,
}
}
],
"1": [
{
"refresh": {
"total": 404,
"total_time_in_millis": 205
}
}
]
}
}
}
}
This breaks down duration and frequency for the leader shard in each index, letting you identify any lagging shards.
Knowing exactly how much load refresh adds per shard makes it is easier to reason about the tradeoffs when manually triggering refreshes.
Optimizing Refresh Behavior
Now that you understand both the high-level architecture and internal implementation details of Elasticsearch refreshing, let‘s outline some optimization best practices:
- Benchmark refresh duration at scale during load testing – This will surface any inconsistencies
- Monitor specific shards using metricbeat – Allows detecting and restarting unstable shards
- Consider tuning
index.refresh_intervalin production – But evaluate impact first - Disable refresh during bulk loads then re-enable – Lowers overhead when loading large volumes
- Limit manual refresh frequency – Lean towards automated refresh for consistency
Additionally, refreshing can be configured to only happen on indices receiving writes by settings:
index.refresh_interval: -1
This is an advanced technique that avoids refreshing read-only indices.
Key Takeaways
As an experienced Elasticsearch developer, avoiding both excessive and insufficient refreshing boils down to:
- Understanding refresh internally rebuilds indices and cached data
- Tracking refresh load and latency at the shard level
- Restricting manual refresh to where immediate visibility is required
- Leaning on automated background refreshing for consistency
Hopefully this breakdown demystified how you can optimize refresh behavior while avoiding common pitfalls at scale. Proper index design paired with monitored refresh patterns will lead to performant yet consistent search experiences in Elasticsearch.


