2

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.

1 Answer 1

3

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());
Sign up to request clarification or add additional context in comments.

4 Comments

hank you Alexander :) I will try and get back toy you.
Thanks a lot. its working perfectly. I need one more suggestion from you for the below query. How can I add fitter query for existing java code. GET _sql?format=json { "query": "SELECT Count(appId) FROM eps_stbl_logs where status = 'COMPLETED'", "filter": { "range" : { "@timestamp" : { "from" : "10/05/2020", "to" : "13/05/2020", "format" : "dd/MM/yyyy" }}}}
Just add the filter condition: String query = "{\"query\":\"SELECT * FROM eps_stbl_logs\"," + "\"filter\": {" + " \"range\": {" + " \"@timestamp\": {" + " \"from\": \"10/05/2020\"," + " \"to\": \"13/05/2020\"," + " \"format\": \"dd/MM/yyyy\"" + " }" + " }" + "}}";
Thanks a Alexander for your quick response. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.