Why JAVA TransportClient.suggest returns empty result, but SuggestRequestBuilder.prepareSuggest works


(Timgluz) #1

Hello, everyone!

I'm currently writing suggestion wrappers for Clojure ES-client called Elastisch - it uses Java native client v.1.7.2 underhood.

When i tried to write simple completion suggest with TransportClient.suggest function then i'm getting empty response, but it works with SuggestRequestBuilder. Here's my pseudo-Java translations of my Clojure code

// completion query
CompletionSuggestionBuilder compBuilder = new CompletionSuggestionBuilder("my_suggest");
compBuilder.text("Foo");
compBuilder.field("my_suggest");

//1.example
SuggestRequest req = new SuggestRequest(indices);
req.suggest(compBuilder);
client.suggest(req).actionGet() ;; got empty object here

I got expected results using this Java code

//2nd example
SuggestRequestBuilder suggestRequestBuilder = client
.prepareSuggest("example").addSuggestion(compBuilder);
SuggestResponse suggestResponse = suggestRequestBuilder.execute().actionGet(); ;;matches cURL example

Why my first example returns empty result? Do i miss something when building request?

"Elastisch" uses TransportClient functions for search and i would like to keep similar pattern and i'm wondering how i could get my first example to match with cURL and my second example.

Full changelog: https://github.com/clojurewerkz/elastisch/compare/master...timgluz:completion_suggester


(system) #2