Elasticsearch Java API 7.0批量插入试图基本示例,抛出错误



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("创建"(添加到request.add((?

内创建的indexRequest中。

是的,这可能是我的一些简单的监督,但我已经在摔跤了一段时间,很喜欢帮助。

"丢失类型"由于您的请求中缺少" _doc"而产生。将新的indexrequest(" post"(更改为新的indexRequest(" post"," _ doc"(可能会起作用。这将发出"弃用"警告,因为_型在Elastic 7.x.x中删除。

相关内容

最新更新