Jest Client 未从 ElasticSearch Suggestor 5.1、Play Framework 接收数据
Data is not received by Jest Client from ElasticSearch Suggestor 5.1, Play Framework
我正在尝试从 elasticsearch 5.1 中检索建议结果,但目前我得到的结果是空的。我目前正在使用开玩笑的客户端。我的代码如下。
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder("localhost:9200")
.multiThreaded(true)
.build());
JestClient client = factory.getObject();
String query="{\n" +
" \"suggest\": {\n" +
" \"text\": \"porm\",\n" +
" \"simple_phrase\": {\n" +
" \"phrase\": {\n" +
" \"field\": \"content\",\n" +
" \"size\": 1,\n" +
" \"gram_size\": 3,\n" +
" \"direct_generator\": [ {\n" +
" \"field\": \"content\",\n" +
" \"suggest_mode\": \"always\"\n" +
" } ],\n" +
" \"highlight\": {\n" +
" \"pre_tag\": \"<em>\",\n" +
" \"post_tag\": \"</em>\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
Suggest suggest1 = new Suggest.Builder(query).addIndex("index").build();
SuggestResult result1 = client.execute(suggest1);
List<SuggestResult.Suggestion> suggestions = result1.getSuggestions("simple_phrase");
ArrayList<String> suggest2=new ArrayList<String>();
for (SuggestResult.Suggestion sugg:
suggestions) {
suggest2.add(sugg.text);
}
return ok(Json.toJson(suggest2));
}
I have fixed this issue.Actually there was a problem with the json query.
I have modified the query to:
String query="{\n" +
" \"simple_phrase\": {\n" +
" \"text\": \"porm\",\n" +
" \"phrase\": {\n" +
" \"field\": \"content\",\n" +
" \"size\": 1,\n" +
" \"gram_size\": 3,\n" +
" \"direct_generator\": [ {\n" +
" \"field\": \"content\",\n" +
" \"suggest_mode\": \"always\"\n" +
" } ],\n" +
" \"highlight\": {\n" +
" \"pre_tag\": \"<em>\",\n" +
" \"post_tag\": \"</em>\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
我正在尝试从 elasticsearch 5.1 中检索建议结果,但目前我得到的结果是空的。我目前正在使用开玩笑的客户端。我的代码如下。
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder("localhost:9200")
.multiThreaded(true)
.build());
JestClient client = factory.getObject();
String query="{\n" +
" \"suggest\": {\n" +
" \"text\": \"porm\",\n" +
" \"simple_phrase\": {\n" +
" \"phrase\": {\n" +
" \"field\": \"content\",\n" +
" \"size\": 1,\n" +
" \"gram_size\": 3,\n" +
" \"direct_generator\": [ {\n" +
" \"field\": \"content\",\n" +
" \"suggest_mode\": \"always\"\n" +
" } ],\n" +
" \"highlight\": {\n" +
" \"pre_tag\": \"<em>\",\n" +
" \"post_tag\": \"</em>\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
Suggest suggest1 = new Suggest.Builder(query).addIndex("index").build();
SuggestResult result1 = client.execute(suggest1);
List<SuggestResult.Suggestion> suggestions = result1.getSuggestions("simple_phrase");
ArrayList<String> suggest2=new ArrayList<String>();
for (SuggestResult.Suggestion sugg:
suggestions) {
suggest2.add(sugg.text);
}
return ok(Json.toJson(suggest2));
}
I have fixed this issue.Actually there was a problem with the json query.
I have modified the query to:
String query="{\n" +
" \"simple_phrase\": {\n" +
" \"text\": \"porm\",\n" +
" \"phrase\": {\n" +
" \"field\": \"content\",\n" +
" \"size\": 1,\n" +
" \"gram_size\": 3,\n" +
" \"direct_generator\": [ {\n" +
" \"field\": \"content\",\n" +
" \"suggest_mode\": \"always\"\n" +
" } ],\n" +
" \"highlight\": {\n" +
" \"pre_tag\": \"<em>\",\n" +
" \"post_tag\": \"</em>\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}";