Completion suggester using java api 6.1.1

I found some code changes in java api 6.1.1.
how can i query with completion suggester using java api 6.1.1 ?
help!

Which Java API? Transport Client or REST Client?

Transport client. thanks.

String[] suggest(String w) {
    def response = client.prepareSearch("my_location")
                         .setTypes("my_type")
                         .setSize(0)
                         .setQuery(QueryBuilders.matchAllQuery())
                         .suggest(SuggestBuilders.completionSuggestion("my_suggestion")
                                                 .prefix(w)
                                                 .field("c_tags")
                                                 .size(100))
                         .execute()
                         .actionGet()
    println(response.suggest)
  }

In the REST client you would write something like:

client.search(new SearchRequest().source(
        new SearchSourceBuilder().suggest(
                new SuggestBuilder().addSuggestion("did_you_mean", SuggestBuilders.completionSuggestion("country_suggest")))
));

I think it's similar in Transport Client. (You should move to REST Client BTW).

thanks, resolved it

String[] suggest(String w) {

    def response = client.prepareSearch("my_location")
                         .setTypes("my_type")
                         .setSize(0)
                         .setQuery(QueryBuilders.matchAllQuery())
                         .suggest(new SuggestBuilder().addSuggestion("my_sugg", SuggestBuilders.completionSuggestion("c_tags")
                                                                                               .prefix(w)))
                         .execute()
                         .actionGet()
    println(response.suggest)
  }

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