Hi everyone - I am using a combination of term/phrase/completion as part of
my search query. However I am having some issues trying to iterate over the
list of suggestions returned.
I generate the "suggestion id" when I create the request object. Now when I
am try to parse the list of suggestions retrieved, I have no way to iterate
over the list of suggestions returned or get all of them as Map or any
other mechanism. I use SearchResponse#getSuggest()#iterator() but it uses
generics and it assume that I already know all the suggestions that I have
entered in the request.
My application server is stateless and I do not intend to store the
suggestion ids on the server while my request is getting processed. so
overall I am stuck and looking for a generic way to iterate over the
suggestions from the query response.
public void doMapping(SearchResponse response) {
Suggest suggest = response.getSuggest();
//Option 1:
suggest.getSuggestion(*NAME*); //where do I get the name from, given
that I am not storing the state on my server when creating the request
//Option 2
Iterator<*what should I specify here*> iter = suggest.iterator();
//Preferred way
Iterator<Suggestion> iter = suggest.iterator();
*//Then iterate over and typecast each object as necessary
using suggest.iterator() and then checking/casting if it is a
PhraseSuggestion/TermSuggestion/CompletionSuggestion while running through
the iterator, makes most sense from what I read so far.
Also if you only need to access get options and their text, there might not
be any need for you to cast into the specific suggestion implementation.
Hi everyone - I am using a combination of term/phrase/completion as part
of my search query. However I am having some issues trying to iterate over
the list of suggestions returned.
I generate the "suggestion id" when I create the request object. Now when
I am try to parse the list of suggestions retrieved, I have no way to
iterate over the list of suggestions returned or get all of them as Map or
any other mechanism. I use SearchResponse#getSuggest()#iterator() but it
uses generics and it assume that I already know all the suggestions that I
have entered in the request.
My application server is stateless and I do not intend to store the
suggestion ids on the server while my request is getting processed. so
overall I am stuck and looking for a generic way to iterate over the
suggestions from the query response.
public void doMapping(SearchResponse response) {
Suggest suggest = response.getSuggest();
//Option 1:
suggest.getSuggestion(*NAME*); //where do I get the name from, given
that I am not storing the state on my server when creating the request
//Option 2
Iterator<*what should I specify here*> iter = suggest.iterator();
//Preferred way
Iterator<Suggestion> iter = suggest.iterator();
*//Then iterate over and typecast each object as necessary
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.