# Accessing Suggestion fields - payload

**URL:** <https://discuss.elastic.co/t/accessing-suggestion-fields-payload/15706>\
**Category:** Elasticsearch\
**Created:** [February 10, 2014, 8:12pm UTC](https://discuss.elastic.co/t/accessing-suggestion-fields-payload/15706 "2014-02-10T20:12:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![redrubia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redrubia/32/1554_2.png) [@redrubia](https://discuss.elastic.co/u/redrubia)\
**Post date:** [February 10, 2014, 8:12pm UTC](https://discuss.elastic.co/t/accessing-suggestion-fields-payload/15706/1 "2014-02-10T20:12:15Z")

</div>

I have a suggestion response being returned to me. One example is:

{  
"companies-1391214959789" : [ {  
"text" : "wells",  
"offset" : 0,  
"length" : 5,  
"options" : [ {  
"text" : "Wells Fargo",  
"score" : 3.0, "payload" : {"industry\_id":100,"company\_id":1}  
}, {  
"text" : "Wells Real Estate Funds",  
"score" : 1.0, "payload" : {"industry\_id":100,"company\_id":2}  
}, {  
"text" : "Wellstar Health System",  
"score" : 16.0, "payload" : {"industry\_id":19,"company\_id":3}  
}, {  
"text" : "Wells Fargo Insurance Services",  
"score" : 11, "payload" : {"industry\_id":183,"company\_id":4}  
}, {.  
"text" : "Wells Fargo/Wachovia",  
"score" : 95, "payload" : {"industry\_id":100,"company\_id":5}  
} ]  
} ]  
}

I can easily iterate through each suggestion, by:

val it = suggestResponse.getSuggest.iterator().next().getEntries().get(0).  
iterator()  
while(it.hasNext){ .... }

However although it is easy to access the text itself, it seems trickier to  
access the payload and I don't seem to be able to.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8854443f-9e96-4d95-9c82-0543f3a36a89%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8854443f-9e96-4d95-9c82-0543f3a36a89%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 10, 2014, 10:20pm UTC](https://discuss.elastic.co/t/accessing-suggestion-fields-payload/15706/2 "2014-02-10T22:20:57Z")

</div>

Maybe something like this?

```
  Iterator<? extends Option> it = 

```

suggestResponse.getSuggest().getSuggestion("s").getEntries().get(0).iterator();  
while (it.hasNext()) {  
CompletionSuggestion.Entry.Option option =  
(CompletionSuggestion.Entry.Option)(it.next());  
String payload = option.getPayloadAsString();  
System.out.println(payload);  
}

You can also do option.getPayloadAsMap().

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/aa7efbab-f9a9-417f-a149-0da28df30fad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/aa7efbab-f9a9-417f-a149-0da28df30fad%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 1:51am UTC](https://discuss.elastic.co/t/accessing-suggestion-fields-payload/15706/3 "2017-07-06T01:51:21Z")

</div>


