我正在尝试在Elasticsearch索引的文本中搜索印度语言查询。当我通过邮递员发出POST请求时,我得到了该记录,但是当我通过摇摇欲坠地对其进行测试时,该记录不起作用
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实体=新的StringEntity(jsonString,“UTF-8”);