Completion suggestion migration from 1.7 to 2.1 NPE


(antoine philippe chaker) #1

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 !


(system) #2