在RestClient低级Rest API客户端中翻译匹配的特定字段Elasticsearch查询

时间:2019-07-11 09:28:39

标签: json elasticsearch

我想将此Elasticsearch查询转换成RestClient低级客户端。

GET try1\_search   
{
  "query": {
    "match": {
      "process.pa_name":   "luca"
    }
  }
}

我的JSON数据如下,

{
        "_index": "try1",
        "_type": "_doc",
        "_id": "2",
        "_score": 1,
        "_source": {
          "target": {
            "br_id": 0,
            "an_id": 0,
            "ai_id": 0,
            "explanation": [
              "element 1",
              "element 2"
            ]
          },
          "process": {
            "an_id": 1311,
            "pa_name": "micha"
          },
          "text": "hello world"
        }
      },
      {
        "_index": "try1",
        "_type": "_doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "target": {
            "br_id": 0,
            "an_id": 1,
            "ai_id": 1,
            "explanation": [
              "element 3",
              "element 4"
            ]
          },
          "process": {
            "an_id": 1311,
            "pa_name": "luca"
          },
          "text": "the all People are good"
        }
      }
    ]
  }
}

我在Low Level Client中使用RestClient编写了这样的平滑处理,以从JSON数据中获取所有实体,

       try {
            RestClient restClient = RestClient.builder(
                    new HttpHost("localhost", 9200, "http")).build();

            Response response1 = restClient.performRequest("GET", "/try1/_doc/_search?size=" + 10, Collections.singletonMap("pretty", "true"));
            String responseBody = EntityUtils.toString(response1.getEntity());
            System.out.println("result is : " + responseBody);

        } catch (UnknownHostException ex) {
            System.out.println("failure : " + ex.getMessage());
        }

任何人都可以帮助我扩展代码以获得上述Elastic Search查询吗? 我会很感激的。

0 个答案:

没有答案