# Elasticsearch Java client async term query not working

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-client-async-term-query-not-working/47084>\
**Category:** Elasticsearch\
**Created:** [April 12, 2016, 8:07am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-async-term-query-not-working/47084 "2016-04-12T08:07:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0c00l.g33k](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@g0c00l.g33k](https://discuss.elastic.co/u/g0c00l.g33k)\
**Post date:** [April 12, 2016, 8:07am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-async-term-query-not-working/47084/1 "2016-04-12T08:07:39Z")

</div>

Hi all,

I am trying to execute a term query from the elasticsearch java client and I am not getting any results. The code is as follows,

```
    final Client client = TransportClient.builder()
        .addPlugin(ShieldPlugin.class)
        .settings(Settings.builder()
                .put("shield.user", "admin:password12")
                .put("client.transport.sniff", true)
                .build())
        .build()
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
    client.prepareSearch("items")
        .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
        .setQuery(QueryBuilders.termQuery("itemid", "1234"))
        .setExplain(false)
        .execute(new ActionListener<SearchResponse>() {
            @Override
            public void onResponse(SearchResponse searchResponse) {
                System.out.println("Response : " + searchResponse.toString());
                }
            
            @Override
            public void onFailure(Throwable throwable) {
                System.err.println("Error :" + throwable.getMessage());
                }
            });

```

Whereas if I use it as `.execute().actionGet()` I am getting the results fine. What am I doing wrong here?

Thanks,  
G

---

<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:** [April 12, 2016, 8:46am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-async-term-query-not-working/47084/2 "2016-04-12T08:46:43Z")

</div>

Are you running that within a test?

I mean that is there any chance your application closes early?

---

<div class="post-metadata">

**Author:** ![g0c00l.g33k](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@g0c00l.g33k](https://discuss.elastic.co/u/g0c00l.g33k)\
**Post date:** [April 12, 2016, 8:47am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-async-term-query-not-working/47084/3 "2016-04-12T08:47:39Z")

</div>

I am running it inside the `main` method

---

<div class="post-metadata">

**Author:** ![g0c00l.g33k](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@g0c00l.g33k](https://discuss.elastic.co/u/g0c00l.g33k)\
**Post date:** [April 12, 2016, 8:50am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-async-term-query-not-working/47084/4 "2016-04-12T08:50:19Z")

</div>

My bad, if I introduce a `Thread.sleep(..)` it works fine.. sorry about that..Thanks David

---

<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:** [July 5, 2017, 11:00pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-async-term-query-not-working/47084/5 "2017-07-05T23:00:19Z")

</div>


