Completion suggester using java api 6.1.1


(Manfrid) #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!


(David Pilato) #2

Which Java API? Transport Client or REST Client?


(Manfrid) #3

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)
  }

(David Pilato) #4

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).


(Manfrid) #5

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)
  }

(system) #6

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