# Completion Suggestion Java API for ElasticSearch 5.5.1

**URL:** <https://discuss.elastic.co/t/completion-suggestion-java-api-for-elasticsearch-5-5-1/105216>\
**Category:** Elasticsearch\
**Created:** [October 25, 2017, 10:04am UTC](https://discuss.elastic.co/t/completion-suggestion-java-api-for-elasticsearch-5-5-1/105216 "2017-10-25T10:04:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaobingy](https://avatars.discourse-cdn.com/v4/letter/x/c68b51/32.png) [@xiaobingy](https://discuss.elastic.co/u/xiaobingy)\
**Post date:** [October 25, 2017, 10:04am UTC](https://discuss.elastic.co/t/completion-suggestion-java-api-for-elasticsearch-5-5-1/105216/1 "2017-10-25T10:04:29Z")

</div>

I want to refer the following example to code the suggestions function with java for elasticsearch 5.5.1,  
but I could not find the prepareSearch , addSuggestion methods like the example.  
Could you help me to solve the problem , thanks very much.

CompletionSuggestionBuilder compBuilder = new CompletionSuggestionBuilder("complete");  
compBuilder.text("n..");  
compBuilder.field("suggest");

SearchResponse searchResponse = localClient.prepareSearch(INDEX\_NAME)  
.setTypes("completion")  
.setQuery(QueryBuilders.matchAllQuery())  
.addSuggestion(compBuilder)  
.execute().actionGet();

CompletionSuggestion compSuggestion = searchResponse.getSuggest().getSuggestion("complete");

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 27, 2017, 3:12pm UTC](https://discuss.elastic.co/t/completion-suggestion-java-api-for-elasticsearch-5-5-1/105216/2 "2017-10-27T15:12:14Z")

</div>

it's not `addSuggestion`, but just `suggest()` - have you tried that?

See [https://github.com/elastic/elasticsearch/blob/5.5/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java](https://github.com/elastic/elasticsearch/blob/5.5/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java)

---

<div class="post-metadata">

**Author:** ![xiaobingy](https://avatars.discourse-cdn.com/v4/letter/x/c68b51/32.png) [@xiaobingy](https://discuss.elastic.co/u/xiaobingy)\
**Post date:** [October 28, 2017, 4:12am UTC](https://discuss.elastic.co/t/completion-suggestion-java-api-for-elasticsearch-5-5-1/105216/3 "2017-10-28T04:12:01Z")

</div>

Thank you very much.  
I have noticed the java api changes.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking\_50\_java\_api\_changes.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_50_java_api_changes.html)

---

<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:** [November 25, 2017, 4:12am UTC](https://discuss.elastic.co/t/completion-suggestion-java-api-for-elasticsearch-5-5-1/105216/4 "2017-11-25T04:12:04Z")

</div>

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