Hi all,
This is my code for autocomple with Java API in ES 1.7 :
SuggestResponse suggestResponse = client.prepareSuggest(INDEX).addSuggestion(
new CompletionSuggestionBuilder("suggestion").field(FIELD).text(term).size(10)
).execute().actionGet();
if(suggestResponse.getSuggest().getSuggestion("suggestion").getEntries().get(0).getOptions() != null &&
suggestResponse.getSuggest().getSuggestion("suggestion").getEntries().get(0).getOptions().size()>0){
List<String> sug = new ArrayList<>();
for(Suggest.Suggestion.Entry.Option option : suggestResponse.getSuggest().getSuggestion("suggestion").getEntries().get(0).getOptions()){
CompletionSuggestion.Entry.Option prefixOption = (CompletionSuggestion.Entry.Option) option;
sug.add(prefixOption.getText().toString());
}
}
It doesn't work with ES 2.1 and throws a NPE.
Could someone give me an example of equivalent code for ES 2.1 with Java API ?
Thanks all !