【问题标题】:query in elasticsearch working thru postman but not thru java code通过邮递员而不是通过java代码在elasticsearch中查询
【发布时间】:2020-08-06 01:52:57
【问题描述】:

我正在尝试在弹性搜索中索引的文本中搜索印度语言的查询。当我通过邮递员发出 POST 请求时,我得到了该记录,但是当我通过 swagger 对其进行测试时,它不起作用

Snapshot of postman

String url =  "http://localhost:9200/mono/_doc/_search?pretty";
        CloseableHttpClient httpClient = (HttpClients.createDefault());
        HttpPost httpPost = new HttpPost(url);
    httpPost.setHeader("content-type", "application/json");
System.out.println("Request : " + httpPost);

        httpPost.setEntity(entity);
        // Execute and get the response after ingesting PO (purchase order) into
        // Globality.
        HttpResponse response = httpClient.execute(httpPost);
        String response2 = EntityUtils.toString(response.getEntity());

        if (response2 != null) {
            System.out.println(response2);
        }

调试代码输出:

json2 是

 {"query":{"match":{"body":{"fuzziness":"2","query":"जन्मभूमि"}}}}

请求:

POST http://localhost:9200/mono/_doc/_search?pretty HTTP/1.1

回复:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

所以正如我们在上面看到的,没有返回任何结果。是不是因为 HTTP 版本 1.0.它需要是2.0吗?如果是,如何指定?这与印度语言特定问题有关吗?但无法通过邮递员而不是通过 java 代码理解它的工作原理。

还有一件事,在邮递员中它同时适用于 GET 和 POST。在代码中,我想先使用 GET,但不知道如何使用 GET 请求发送正文,所以最终使用了 POST。

【问题讨论】:

  • 现在工作。补充:StringEntity entity = new StringEntity(jsonString,"UTF-8");
  • 随意添加答案并接受它:)

标签: http elasticsearch utf-8 postman


【解决方案1】:

现在工作。补充:StringEntity entity = new StringEntity(jsonString,"UTF-8");

【讨论】:

    猜你喜欢
    • 2017-07-20
    • 2017-08-18
    • 1970-01-01
    • 2017-01-27
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 1970-01-01
    相关资源
    最近更新 更多