Accessing Suggestion fields - payload


(redrubia) #1

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.
To view this discussion on the web visit 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.


(Binh Ly) #2

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.
To view this discussion on the web visit 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.


(system) #3