3

Java 1.8、Elasticsearch 低级和高级 Rest 客户端 7.0.0

我正在尝试此处找到的文档中的简单示例:批量 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?

是的,这可能是我的一些简单的疏忽,但我已经为此苦苦挣扎了一段时间,希望能得到一些帮助。

4

1 回答 1

2

由于您的请求中缺少“_doc”而出现“缺少类型”。将 new IndexRequest("posts") 更改为 new IndexRequest("posts","_doc") 可能会起作用。这将给出一个“弃用”警告,因为 _types 在 Elastic 7.xx 中被删除

于 2020-05-16T06:39:42.747 回答