# Completion suggestion migration from 1.7 to 2.1 NPE

**URL:** <https://discuss.elastic.co/t/completion-suggestion-migration-from-1-7-to-2-1-npe/36401>\
**Category:** Elasticsearch\
**Created:** [December 4, 2015, 4:33pm UTC](https://discuss.elastic.co/t/completion-suggestion-migration-from-1-7-to-2-1-npe/36401 "2015-12-04T16:33:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoine\_philippe\_cha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antoine_philippe_cha/32/2325_2.png) [@antoine\_philippe\_cha](https://discuss.elastic.co/u/antoine_philippe_cha)\
**Post date:** [December 4, 2015, 4:33pm UTC](https://discuss.elastic.co/t/completion-suggestion-migration-from-1-7-to-2-1-npe/36401/1 "2015-12-04T16:33:17Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:33pm UTC](https://discuss.elastic.co/t/completion-suggestion-migration-from-1-7-to-2-1-npe/36401/2 "2017-07-05T23:33:32Z")

</div>


