# Retrieve data from elasticsearch 5.6.0 using java API

**URL:** <https://discuss.elastic.co/t/retrieve-data-from-elasticsearch-5-6-0-using-java-api/214729>\
**Category:** Elasticsearch\
**Created:** [January 12, 2020, 12:44pm UTC](https://discuss.elastic.co/t/retrieve-data-from-elasticsearch-5-6-0-using-java-api/214729 "2020-01-12T12:44:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Venkatesh\_Ponnusami](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatesh_ponnusami/32/60668_2.png) [@Venkatesh\_Ponnusami](https://discuss.elastic.co/u/Venkatesh_Ponnusami)\
**Post date:** [January 12, 2020, 12:44pm UTC](https://discuss.elastic.co/t/retrieve-data-from-elasticsearch-5-6-0-using-java-api/214729/1 "2020-01-12T12:44:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 13, 2020, 1:39pm UTC](https://discuss.elastic.co/t/retrieve-data-from-elasticsearch-5-6-0-using-java-api/214729/2 "2020-01-13T13:39:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Venkatesh\_Ponnusami](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatesh_ponnusami/32/60668_2.png) [@Venkatesh\_Ponnusami](https://discuss.elastic.co/u/Venkatesh_Ponnusami)\
**Post date:** [January 17, 2020, 12:17pm UTC](https://discuss.elastic.co/t/retrieve-data-from-elasticsearch-5-6-0-using-java-api/214729/3 "2020-01-17T12:17:53Z")

</div>

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");

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 14, 2020, 12:17pm UTC](https://discuss.elastic.co/t/retrieve-data-from-elasticsearch-5-6-0-using-java-api/214729/4 "2020-02-14T12:17:59Z")

</div>

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