Fetch suggested document from the elastic search

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();

    CompletionSuggestionBuilder completionSuggestionBuilder = SuggestBuilders
            .completionSuggestion( "name_suggest" )

    SuggestBuilder suggestBuilder = new SuggestBuilder();
    suggestBuilder.addSuggestion( "name_suggest", completionSuggestionBuilder );
    searchSourceBuilder.suggest( suggestBuilder );

    searchRequest.source( searchSourceBuilder );
    SearchResponse searchResponse = null;

        searchResponse = client.search( searchRequest,RequestOptions.DEFAULT );
    catch ( IOException e )

    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();
    return result;

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.