Elasticsearch Java client async term query not working

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()
                .put("shield.user", "admin:password12")
                .put("client.transport.sniff", true)
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
        .setQuery(QueryBuilders.termQuery("itemid", "1234"))
        .execute(new ActionListener<SearchResponse>() {
            public void onResponse(SearchResponse searchResponse) {
                System.out.println("Response : " + searchResponse.toString());
            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?


Are you running that within a test?

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

1 Like

I am running it inside the main method

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