Philipp Philipp - 11 days ago 6
Java Question

Elasticsearch - Implement Completion Suggestion in Java (API Version 5!)

I am trying to implement a completion suggestion for my java application. I've read the documentation but could not find anything on how to implement it using the Java API in Version 5.0.1. (All i found was related to older versions)

this.client.prepareSuggest...


=> does not exist anymore

this.client.prepareSearch... .addSuggestion(csb);


=> does not accept CompletionSuggestionBuilder

This is my maven dependency:

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.0.1</version>
</dependency>


Can anyone provide an example?

Val Val
Answer

The correct way of doing it is like this:

CompletionSuggestionBuilder csb = SuggestBuilders.completionSuggestion("foo")
    .prefix("prefix");
client().prepareSearch()
    .suggest(new SuggestBuilder().addSuggestion("foo", csb))