I am trying to use the Completion suggester for an Auto complete App. I am developing the client in Java and using "org.elasticsearch.client:elasticsearch-rest-high-level-client:7.1.0." library.
is there any way to extract the source data from the Suggest response ? I was only able to get the score and text from the Suggest response.
Code I have written to search -
SearchRequest searchRequest = new SearchRequest("my_entitiy");
CompletionSuggestionBuilder suggestionBuilder = new CompletionSuggestionBuilder("nameSuggest");
suggestionBuilder.size(10).prefix(input).skipDuplicates(true);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.suggest(
new SuggestBuilder().addSuggestion(SUGGESTION_NAME, suggestionBuilder));
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = elasticClient.search(searchRequest, RequestOptions.DEFAULT);
Suggest suggest = searchResponse.getSuggest();
Suggest.Suggestion<Suggest.Suggestion.Entry<Suggest.Suggestion.Entry.Option>> suggesition =
suggest.getSuggestion(SUGGESTION_NAME);
List<String> suggestionList = new ArrayList<>();
for (Suggest.Suggestion.Entry<Suggest.Suggestion.Entry.Option> entry : suggesition.getEntries()) {
for(Suggest.Suggestion.Entry.Option option:entry.getOptions()){
suggestionList.add(option.getText().toString());
}
}
When I checked the raw response elastic search is returning the complete document, But using java client library I dint find a way to get the source data ?