Getting fields out of JSON using SearchResponse class ElasticSearch


(Sarthak) #1

{
Executive Info = {
Executive Location = Delhi,
Executive Name = Mr.Rajiiv,
Executive Id = 3289423908
}, State Property = {
Supervisor = Mr Sam,
Area = Rohtak,
SupervisorId = 2187870,
City = Haryana,
Id = 9574833,
Name = Sumit
}, Task Timinig = {
Status = Not Complete,
Starting Time = 10 AM,
Duration = 6,
Timing = 10 AM - 11 PM,
EndingTime = 5 PM,
Date = 2 / 5 / 2017
}, Task Category = {
Sub Task Name = Testing,
Sub Task ID = 8744993,
Subcategory = QA Testing,
Id = 90344622,
Name = Selinium
}
}

I have to get City and its value out of the state property. How can i do it. I have tried this..

SearchResponse search = client.prepareSearch("data").setFetchSource("State Property", null).execute().actionGet(); SearchHit hit = search.getHits().getAt(0);

but its giving me whole JSON


(Zachary Tong) #2

You can do something like:

String city = hit.getFields().get("City").getValue().toString();

(Sarthak) #3

Thanks for the help


(system) #4

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