2017-02-11 87 views
0

我試圖從elasticsearch 5.1中檢索建議者結果,但是目前我得到一個空的結果。我目前使用的是客戶端。我的代碼如下。Jest客戶端從ElasticSearch Suggestor 5.1,Play Framework沒有收到數據

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)); 
    } 
+1

https://github.com/searchbox-io/Jest/releases笑話不支持彈性5.x的尚未 – alkis

+1

使用Elasticsearch 5 REST客戶端來代替。 – ryanlutgen

回答

0
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" + 
        "}"; 
相關問題