I have integrated the complex suggester feature using the Java REST API and it returns a list of suggestions as shown below
["NO DATE EVENT","NO Date","no","nodateevent"]
How can I fetch the particular document if the user chooses one of the options from the autocomplete entry?
Is there any way to return the id along with the name from the suggester ?
Suggestion code in Java
SearchRequest searchRequest = new SearchRequest( INDEX );
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
CompletionSuggestionBuilder completionSuggestionBuilder = SuggestBuilders
.completionSuggestion( "name_suggest" )
.prefix(searchKey).skipDuplicates(true);
SuggestBuilder suggestBuilder = new SuggestBuilder();
suggestBuilder.addSuggestion( "name_suggest", completionSuggestionBuilder );
searchSourceBuilder.suggest( suggestBuilder );
searchRequest.source( searchSourceBuilder );
SearchResponse searchResponse = null;
try
{
searchResponse = client.search( searchRequest,RequestOptions.DEFAULT );
}
catch ( IOException e )
{
e.printStackTrace();
}
List<String> result = new ArrayList<>();
Suggest suggest = searchResponse.getSuggest();
CompletionSuggestion entries = suggest.getSuggestion( "name_suggest" );
for ( CompletionSuggestion.Entry entry : entries )
{
for ( CompletionSuggestion.Entry.Option option : entry.getOptions() )
{
String suggestText = option.getText().string();
result.add(suggestText);
}
}
return result;