ElasticSearch SearchHit field to 5.3 from 2.3

I have been using this code for ES 2.3 and it worked fine. I'm query against data already loaded in Elastic search. I'm Unable to do this in ES 5.3. I'm just trying to get values for certain fields from 300 fields loaded into ES. Instead of JSON I want result into "|" delimited. Is there a way to do similar with ES 5.3 ?

for( SearchHit hit : response.getHits())
{
 String s0 = hit.field("first_name").getValue().toString();
 result.add(s0);
 String s1 = hit.field("last_name").getValue().toString();
 result.add(s1);
 String s2 ="";
 if(hit.fields().containsKey("middle_name"))
{
 String s2 = hit.field("middle_name").getValue().toString();
 result.add(s2);
}

finalresult = s0 + "|" + s1 + "|" + s2;
}

Hi, Are you reading a 2.3 cluster with a 5.3 java code ? If yes, that's not possible. Else can you provide log or stacktrace ?

bye,
Xavier

for( SearchHit hit : response.getHits())
{
Map<String,Object> map = hit.getSource();
 String s0 = map.get("first_name")map.get
 result.add(s0);
 String s1 = map.get("last_name").toString();
 result.add(s1);
 String s2 ="";
 if(map.containsValue("middle_name"))
{
 String s2 = map.get("middle_name").toString();
 result.add(s2);
}

finalresult = s0 + "|" + s1 + "|" + s2;
}

This worked for me fine. Thanks

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