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

标签 java elasticsearch elasticsearch-java-api elasticsearch-bulk-api

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/

相关文章:

java - Spring Data Elasticsearch 按JSON 结构查询

java - 是否可以定义一个 Java 类加载器,它返回与所请求的完全不同的类?

java - xslt处理

elasticsearch - ElasticSearch/Logstash 5-将.raw重命名为.keyword

elasticsearch - Kibana未在图 block map 上显示结果

javascript - 通过 javascript 循环将文档添加到 ElasticSearch 索引不起作用

spring - Elasticsearch和Spring兼容性(2019年3月)

elasticsearch - ElasticSearch RANGE查询无法按预期工作

java - 如何识别正确的java执行器?

java - App Engine 数据存储中的空列表 : Java vs Python