Java 1.8,Elasticsearch 低级和高级 Rest 客户端 7.0.0
我正在尝试此处文档中的简单示例:Bulk API
BulkRequest bulkRequest = new BulkRequest();
request.add(new IndexRequest("posts").id("1")
.source(XContentType.JSON,"field", "valueString"));
// not working
Map<String, Object> doc1 = new HashMap<>();
doc1.put("property", "value");
request.add(new IndexRequest("posts").id("1").source(doc1);
// this is easy to add as a single IndexRequest, but not working here
BulkResponse bulkResponse = this.getClient().bulk(request, RequestOptions.DEFAULT);
// this is the line throwing the error, straight from the docs
错误:
{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed: 1: type is missing;"}],"type":"action_request_validation_exception","reason":"Validation Failed: 1: type is missing;"},"status":400}
at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:260)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:238)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:212)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1433)
... 6 more
那么缺少什么类型?我尝试添加映射,将 opType("create") 添加到在 request.add() 中创建的 IndexRequest?
是的,这可能是我的一些简单疏忽,但我已经为此努力了一段时间,希望能得到一些帮助。
最佳答案
“缺少类型”的出现是因为您的请求中缺少“_doc”。将 new IndexRequest("posts") 更改为 new IndexRequest("posts","_doc") 可能会起作用。这将给出“已弃用”警告,因为 _types 在 Elastic 7.x.x 中已被删除。
关于java - Elasticsearch Java API 7.0 批量插入尝试基本示例,抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55973234/