Force synchronous refresh

Elastic04
Wed, 19 Nov 2025 13:43:52 +0000
Elasticsearch

We have this part of code in indexing job.

1. turn off refresh_interval before indexing. (set refresh_interval to 0 or -1 through kibana)

2. After indexing is done, we to do manual refresh so that indexed products will be available for searching.

If we turn off indexing, will this part of code do the manual refresh after indexing or not?

​private void forceSynchronousRefresh(String indexId)
    {
        try (RuntimeSensor sensor = getPerformanceMgr().start(PerformanceMgr.SENSOR_TYPE_CLASS,
                        this.getClass().getSimpleName() + ".forceSynchronousRefresh()"))
        {
            if (null !=indexId || !indexId.trim().isEmpty())
            {
                RefreshResponse refreshResponse = server.getClient().indices().refresh(new RefreshRequest(indexId),
                                RequestOptions.DEFAULT);

            //    Logger.info(this, "Index refresh success for {}: totalShards={}, successfulShards={}, failedShards={}",
                   //             indexId, refreshResponse.getTotalShards(), refreshResponse.getSuccessfulShards(),
                //                refreshResponse.getFailedShards());

                System.out.println("Index refresh success for " + indexId +
                                ": totalShards=" + refreshResponse.getTotalShards() +
                                ", successfulShards=" + refreshResponse.getSuccessfulShards() +
                                ", failedShards=" + refreshResponse.getFailedShards());
            }
        }
        catch(Exception e)
        {
            Logger.error(this, MessageFormat.format("Index refresh failure for {0}", indexId), e);
        }
    }

2 posts - 2 participants