Force synchronous refresh

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);
        }
    }

Hello!

Setting refresh_interval to -1 does effectively disable automatic refreshes, meaning newly added documents won’t be searchable. If you were following the Tune for indexing speed guide, it recommends enabling automatic refreshing again after the indexing has been completed.

Another option is to manual refresh, which is what your code is doing with the call to the Refresh API, which works, but note that “Refresh requests are synchronous and do not return a response until the refresh operation completes” (from the refresh docs), so it might affect the application’s performance.