Elasticsearch java Rest High level Client


(David Pilato) #10

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.


(Dv Thiyanesh) #11

Thank you for your guidance i got an idea


(Dv Thiyanesh) #12

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?


(David Pilato) #13

Did you try the translate API?


(Dv Thiyanesh) #14

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


(Dv Thiyanesh) #15

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?


(David Pilato) #16

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


(David Pilato) #17

May be I'm not clear.

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


(Dv Thiyanesh) #18

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?


(David Pilato) #19

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.


(Dv Thiyanesh) #20

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


(Dv Thiyanesh) #21

okay You got Me why i went to Java Rest Client Api bcz in kibana for dashboard restriction we need X-pack that's we went to java api right

Then For us our requirement is we need to combine more condition and fetch record for ex: i have index(about bank details) in elasticsearch and client need a record from (last one hour transaction details AND the Gender should be Male) when these condition matches that record should be dispalyed For that How i need to do? your idea?


(Dv Thiyanesh) #22

mostly we use data range query for that How I proceed in java rest api?


(David Pilato) #23

You are mixing so many questions that I can not follow.

There is no relationship between security feature:

in kibana for dashboard restriction we need X-pack that's we went to java api right

And the way you are going to request elasticsearch in Java.

we need to combine more condition and fetch record for ex: i have index(about bank details) in elasticsearch and client need a record from (last one hour transaction details AND the Gender should be Male) when these condition matches that record should be dispalyed For that How i need to do? your idea?

You need to learn elasticsearch first.
Forget everything about the Java client for now. Just start Elasticsearch and Kibana.
Then go to the developer Console and start playing with elasticsearch.

If you already indexed data, just use the GET /_search endpoint to learn the QueryDSL.

Once you found the right query for your use case, then you can start to think about writing you code in Java. That's just another way to write a QueryDSL request.

If you need more help, please provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.


(Dv Thiyanesh) #24

In kibana Dashboard only user option is used when x-pack is activated for this case We are using java rest api to take the record out

I have learned elasticsearch and kibana that you have mentioned above But i need How to use some types of query in java for that i don't know How to code and which method used for giving multiple condition(AND,NOT,OR). i stuck in it?


(David Pilato) #25

Look at https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html


(Dv Thiyanesh) #26

Great it is working! but slight change is client.performRequest(request);


(Mashhur S) #27

I have been also using ES for several years and when it comes to upgrade ES verion, you anytime need to rewrite all you app queries. So I made very simple query builder library based on High Rest client, where you can customise later on. If you dont mind you can freely use it.


(Dv Thiyanesh) #28

Instead of using this, we can use querybuilders methods itself know?
any difference?


(system) closed #29

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.