Retrieve data from elasticsearch 5.6.0 using java API

Hi,
I am trying to write a java program for storing a string in elasticsearch and then retrieve from it My code is
GetResponse response = client.prepareGet("correct", "Doe","11").setStoredFields("message") .execute() .actionGet(); String message = (String)response.getField("message").getValue();
For that ,I am always getting null value
But if I try "response.exists()", it gives me "true".when I see the index in elasticsearch head chrome extension it exists and also has the data in message field

Note: I am using elasticsearch 5.6.0 with java API

Can anyone please help me to get the field from the index

Potentially your field is not marked as stored in the mapping, but you wanted to retrieve the message field as a stored field.

How about not using the stored fields feature, but rather one of the GetResponse.getSource* methods, that allow you to retrieve the field from the original JSON that you indexed?

--Alex

Thank you for your reply.
I got the answer.Here is my code
GetResponse getresponse1 = client.prepareGet("correct", "Doe", "16")
.setOperationThreaded(false)
.get();
Map<String, Object> json = getresponse1.getSourceAsMap();
String answer=(String)json.get("message");

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