我正在尝试在 Elasticsearch 中索引的文本中搜索印度语言的查询。当我通过 postman 发出 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吗?如果是,如何指定?这与印度语言特定问题有关吗?但无法通过 postman 而不是通过 java 代码来理解它是如何工作的。还有一件事,在 postman 中它适用于 GET 和 POST。在代码中,我想首先使用 GET,但不知道如何使用 GET 请求发送正文,所以最终使用了 POST。
最佳答案
现在工作。补充: StringEntity entity = new StringEntity(jsonString,"UTF-8");
关于http - 通过 postman 而不是通过java代码在elasticsearch中查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63275770/