Issue iterating over the suggestions included in query response


(Amit Soni) #1

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

}

-Amit.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Alexander Reelsen) #2

Hey,

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.

--Alex

On Wed, Oct 16, 2013 at 1:37 AM, Amit Soni amitsoni29@gmail.com wrote:

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

}

-Amit.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #3