弹性搜索中的查询通过邮递员工作,但不通过java代码



我正试图在弹性搜索中索引的文本中搜索一个印度语查询。当我通过邮递员发送POST请求时,我会得到那个记录,但当我通过swagger测试它时,它不起作用

邮递员快照

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代码工作的。

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

正在工作。添加:StringEntity实体=新StringEntity(jsonString,"UTF-8"(;

最新更新