HShetty
HShetty

Reputation: 21

How to write elasticsearch-sql query using Java High-Level REST Client API

This is my Elasticsearch-sql query. I executed this query using Kibana and getting valid output.

GET _sql?format=json { "query": "SELECT Count(appId) FROM eps_stbl_logs where cast(timestamp AS DATE) = TODAY() and status = 'COMPLETED'" }

This needs to be written in restHighLevelClient java API. Could you please help to write java API as I am new to ElasticSearch with Java.

Upvotes: 2

Views: 3065

Answers (1)

Alexander Raithel
Alexander Raithel

Reputation: 41

It could work like this:

        Request request = new Request("GET", "/_sql");
        request.setJsonEntity("{\"query\":\"SELECT Count(appId) FROM eps_stbl_logs where cast(timestamp AS DATE) = TODAY() and status = 'COMPLETED'\"}");
        Response response = restHighLevelClient.getLowLevelClient().performRequest(request);
        String responseBody = EntityUtils.toString(response.getEntity());

Upvotes: 3

Related Questions