【发布时间】:2020-06-30 18:22:01
【问题描述】:
我正在学习 Java RestHighLevelClient,但我找不到这个问题的答案。
当您向未找到文档的内容提交 REST 请求时,您将看到如下内容:
$ curl localhost:9200/customer/_doc/1?pretty
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index [customer]",
"resource.type" : "index_expression",
"resource.id" : "customer",
"index_uuid" : "_na_",
"index" : "customer"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index [customer]",
"resource.type" : "index_expression",
"resource.id" : "customer",
"index_uuid" : "_na_",
"index" : "customer"
},
"status" : 404
}
但是在 Java 客户端中,您可以编写如下代码:
GetRequest request = new GetRequest(INDEX, ROOT);
GetResponse response = null;
try {
response = client.get(request, RequestOptions.DEFAULT);
} catch (IOException ioe) {
// do something with the IOException
} catch (ElasticsearchException ese) {
// where is the response source?
}
因此,如果未找到文档,您将得到 ElasticsearchException,在这种情况下,局部变量 response 为空。那么你从哪里得到 低级别存在的源文档? (最好作为地图)。
【问题讨论】:
-
源文档出现在底层是什么意思?
-
@AmitKhandelwal 查看
curl命令的输出。它是一个 JS 对象,包含您想要的有关错误的所有信息。我如何在我发布的 Java 代码中得到它?
标签: elasticsearch elasticsearch-java-api