Java REST Client - Refresh API and Default Refresh Index

Hello, everyone!

I have a question about using the Java REST Client - Refresh API or the default refresh behavior in an Elasticsearch index.

In a certain part of an application I'm maintaining, I have an implementation that calls refresh after each indexing operation using:

RefreshResponse refreshResponse = client. Indices().refresh(request, RequestOptions.DEFAULT);

Doc: (Refresh API | Java REST Client [7.17] | Elastic)

I need to make an adjustment here for performance reasons.

When reading the Elasticsearch documentation, I came across the following parameter:

refresh_interval

Doc: (Refresh an index | Elasticsearch API documentation).

As I understand it, if this parameter is not explicitly set, Elasticsearch will perform a refresh operation every second on indexes that have received any requests in the last 30 seconds.

My question is: Do the two approaches serve the same purpose? In other words, is one an explicit API call on demand and the other the default automatic mechanism? If they are equivalent, I could reconsider my indexing approach and rely on the default update behavior instead of manually calling the API each time.

Thanks in advance for any insight!

Hello and welcome!

Your understanding is correct: calling the refresh api will trigger a manual, synchronous refresh operation, meaning the call won't return until refreshing is complete, while the automatic refresh mechanism will refresh, by default, every 1 second.

Here's the documentation for index.refresh_interval which explains more in depth how it works, from the settings documentation:

How often you want to refresh depends on the nature of the application, for example if you need to ingest a very large amount of data, and you need all data to be correctly indexed and made available for search before performing an operation, then performing a manual refresh at the end of the indexing is the best way to make sure that all of the records are available.