# Elasticsearch java Rest High level Client

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669>\
**Category:** Elasticsearch\
**Created:** [March 11, 2019, 5:37am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669 "2019-03-11T05:37:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 5:37am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/1 "2019-03-11T05:37:18Z")

</div>

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

---

<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:** [March 11, 2019, 5:54am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/2 "2019-03-11T05:54:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 5:58am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/3 "2019-03-11T05:58:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 5:59am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/4 "2019-03-11T05:59:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nikuland](https://avatars.discourse-cdn.com/v4/letter/n/7feea3/32.png) [@nikuland](https://discuss.elastic.co/u/nikuland)\
**Post date:** [March 11, 2019, 6:03am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/5 "2019-03-11T06:03:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 6:20am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/6 "2019-03-11T06:20:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 6:26am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/7 "2019-03-11T06:26:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 6:27am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/8 "2019-03-11T06:27:06Z")

</div>

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

---

<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:** [March 11, 2019, 6:54am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/9 "2019-03-11T06:54:49Z")

</div>

> [@Dv\_Thiyanesh](#):
>
> Sorry I mean Normal query like

This is a SQL Query not using the standard QueryDSL. [Query DSL | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html)

You can use [SQL Translate API | Elasticsearch Guide [6.6] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/sql-translate.html) 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:

```auto
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:](https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.6.1/org/elasticsearch/index/query/TermQueryBuilder.html:)

```auto
QueryBuilders.termQuery("year", 2013);

```

HTH

---

<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:** [March 11, 2019, 6:58am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/10 "2019-03-11T06:58:01Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 7:03am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/11 "2019-03-11T07:03:41Z")

</div>

Thank you for your guidance i got an idea

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 7:05am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/12 "2019-03-11T07:05:56Z")

</div>

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?

---

<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:** [March 11, 2019, 7:20am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/13 "2019-03-11T07:20:49Z")

</div>

Did you try the translate API?

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 7:24am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/14 "2019-03-11T07:24:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 7:29am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/15 "2019-03-11T07:29:08Z")

</div>

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?

---

<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:** [March 11, 2019, 7:36am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/16 "2019-03-11T07:36:57Z")

</div>

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

---

<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:** [March 11, 2019, 7:38am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/17 "2019-03-11T07:38:14Z")

</div>

May be I'm not clear.

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

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 7:43am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/18 "2019-03-11T07:43:57Z")

</div>

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?

---

<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:** [March 11, 2019, 8:00am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/19 "2019-03-11T08:00:37Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Dv\_Thiyanesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dv_thiyanesh/32/53965_2.png) [@Dv\_Thiyanesh](https://discuss.elastic.co/u/Dv_Thiyanesh)\
**Post date:** [March 11, 2019, 8:01am UTC](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669/20 "2019-03-11T08:01:39Z")

</div>

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

[Next page](https://discuss.elastic.co/t/elasticsearch-java-rest-high-level-client/171669.md?page=2)
