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

**URL:** https://discuss.elastic.co/t/java-client-api-data-indexed-but-not-available-in-a-search-works-in-debug-mode/297399
**Category:** Elasticsearch
**Created:** [February 16, 2022, 4:44pm UTC](https://discuss.elastic.co/t/java-client-api-data-indexed-but-not-available-in-a-search-works-in-debug-mode/297399 "2022-02-16T16:44:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vmassol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vmassol/32/17398_2.png) [@vmassol](https://discuss.elastic.co/u/vmassol)
#### Post date: [February 16, 2022, 4:44pm UTC](https://discuss.elastic.co/t/java-client-api-data-indexed-but-not-available-in-a-search-works-in-debug-mode/297399/1 "2022-02-16T16:44:58Z")

</div>

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:

```auto
            RestClient restClient = RestClient.builder("...some url...")
                .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder
                    .useSystemProperties()
                .build();
            this.transport = new RestClientTransport(
                restClient, new JacksonJsonpMapper());
            this.client = new ElasticsearchClient(this.transport);
...
            client.index(builder -> builder
                .index(ElasticsearchClientManager.INDEX)
                .document(ping)
            );
...
        SearchResponse<Ping> search = client.search(s -> s
            .index(ElasticsearchClientManager.INDEX)
            , Ping.class);
        //Thread.sleep(10000L);
        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? 🙂

Thanks!

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 16, 2022, 5:32pm UTC](https://discuss.elastic.co/t/java-client-api-data-indexed-but-not-available-in-a-search-works-in-debug-mode/297399/2 "2022-02-16T17:32:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![vmassol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vmassol/32/17398_2.png) [@vmassol](https://discuss.elastic.co/u/vmassol)
#### Post date: [February 16, 2022, 5:56pm UTC](https://discuss.elastic.co/t/java-client-api-data-indexed-but-not-available-in-a-search-works-in-debug-mode/297399/3 "2022-02-16T17:56:02Z")

</div>

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:

```auto
client.indices().refresh();

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 16, 2022, 5:56pm UTC](https://discuss.elastic.co/t/java-client-api-data-indexed-but-not-available-in-a-search-works-in-debug-mode/297399/4 "2022-03-16T17:56:43Z")

</div>

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