Elasticsearch java Rest High level Client

Hi All, I am using Elasticsearch java High Level Client to connect with my local Elasticsearch to fetch data
In Kibana DSL i used sql query to fetch data from my elasticsearch, likewise i need to use sql query in java High Level rest Client Api to fetch data is it possible? How? or any other way

Why do you want to use sql from the java client?

Use the normal way to query elasticsearch instead.

I don't think elasticsearch client exposes (yet?) this feature. But you can always use the low level instance if you really need it.

Sorry I mean Normal query like

POST /_xpack/sql?format=json
{
"query": "SELECT id,year FROM bankloan WHERE year = 2013 "
}

GET bankloan/_search?q=issue_d:01-12-2013 AND final_d:1062015 AND region:munster

In kibana I used these ways same I need use in rest api? these are my criteria?

java low level client has these features? to use Sql query?

i use high level rest client to query elastic search.
restHighLevelClient = new RestHighLevelClient(
RestClient.builder(
new HttpHost(EsHost, 9200, "http")));

And then you can use other methods exposed by the Rest client to query elastic search

Thank you for this i have connected it i have used simple get to check it is working

In kibana I used Sql query to fetch record from elasticsearch like:

POST /_xpack/sql?format=json
{
"query": "SELECT id,year FROM bankloan WHERE year = 2013 "
}

GET bankloan/_search?q=issue_d:01-12-2013 AND final_d:1062015 AND region:munster

which specific method in high level client used to query these kind and fetch record

which specific method in high level client used to query these kind and fetch record using AND OR operation query

Thank you for this i have connected it i have used simple get to check it is working

In kibana I used Sql query to fetch record from elasticsearch like:

POST /_xpack/sql?format=json
{
"query": "SELECT id,year FROM bankloan WHERE year = 2013 "
}

GET bankloan/_search?q=issue_d:01-12-2013 AND final_d:1062015 AND region:munster

which specific method in high level client used to query these kind and fetch record or any alternate ways available? Guide Me

This is a SQL Query not using the standard QueryDSL. Query DSL | Elasticsearch Guide [8.11] | Elastic

You can use SQL Translate API | Elasticsearch Guide [6.6] | Elastic to see how your sql query is actually converted to the QueryDSL.

SELECT id,year FROM bankloan WHERE year = 2013

Here I guess you can just use a term query like:

POST _search
{
  "query": {
    "term" : { "year" : 2013 } 
  }
}

Translating that to Java is then easy using https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.6.1/org/elasticsearch/index/query/TermQueryBuilder.html:

QueryBuilders.termQuery("year", 2013);

HTH

No. But it can run any HTTP request you want against an elasticsearch URL.

Request request = new Request( "POST", "/_xpack/sql");
request.addParameter("format", "json");
request.setJsonEntity("{\"query\":\"SELECT id,year FROM bankloan WHERE year = 2013\"}");
client.getLowLevelClient().performRequest(request);

Something like this (not tested). But then you need to manually read the JSON.

Thank you for your guidance i got an idea

okay i got it, i need use AND condition ex: (year is so and so AND Name is so and so) for this what i need to do?

Did you try the translate API?

Nope!! It is available in High level client or Low Level Client?

I understood i have used Sql rest api in kibana My doubt is i can use same sql rest api like query in java High or low level client? which method need to use for it?

No. It's not. Run it in Kibana.

May be I'm not clear.

My recommandation is : "Do not use SQL API from the Java Rest Client".

1 Like

I have got your idea, But For My project if i use kibana for charting easily but to share dashboard to client we need x-pack to restrict the dashboard only user user
(in our office they are not ready to buy x-pack that's we trying these idea)

for this we have got idea to take record using java rest api and with that data i need to chart using d3.js
that's why i need sql like query in java api client? i think you got my idea?

i think you got my idea?

No.

that's why i need sql like query in java api client?

I don't think you need it.

It throws an error says that (The constructor Request(String, String) is undefined)
What i need to do?