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?
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");
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.