Java Client API data indexed but not available in a search, works in debug mode

Hi guys,

I'm a bit stuck on a problem I don't understand. I'm basically doing the following, using the Java Client API in ES 7.17:

            RestClient restClient = RestClient.builder("...some url...")
                .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder
            this.transport = new RestClientTransport(
                restClient, new JacksonJsonpMapper());
            this.client = new ElasticsearchClient(this.transport);
            client.index(builder -> builder
        SearchResponse<Ping> search = -> s
            , Ping.class);
        assertEquals(1, search.hits().hits().size());

As you can see I'm not using an Async Client. Yet the assertEquals fails (I get 0 hits). And that's true even if I uncomment the Thread.sleep() line.

However, if I put a breakpoint in my IDE on the assertEquals line and go through it, it works.

Any clue for me? :slight_smile:


Remember that if you want to search right after having indexed some documents, you need to refresh the index. Recommended only for integration tests.

ok cool, didn't know that (and yes I'm writing integration tests :)). I don't remember doing any refresh in the past but maybe the framework I was using was doing it (JestClient).

Thanks @dadoonet that was super helpful and I got it to work by inserting:


This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.