elasticsearch7.1保存时报错: Validation Failed: 1: type is missing;
原创 2019-09-08 14:11 阅读(10453)次
elasticsearch7.1保存时报错:
org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: type is missing;
at org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:26)
at org.elasticsearch.action.index.IndexRequest.validate(IndexRequest.java:148)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1399)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1373)
at org.elasticsearch.client.RestHighLevelClient.index(RestHighLevelClient.java:821)
at com.jiachi.util.EsUtil.saveData(EsUtil.java:52)
at com.jiachi.util.EsUtil.main(EsUtil.java:69)
代码如下:
/**
* 单条保存
* @param index
* @param id
* @param m
*/
public static void saveData(String index,String id,Map<String, Object> m){
try {
RestHighLevelClient client = getClient();
IndexRequest indexRequest = new IndexRequest(index)
.id( id)
.source(m);
client.index(indexRequest, RequestOptions.DEFAULT);
} catch (Exception e) {
e.printStackTrace();
}
}
pom.xml: <dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.1.0</version>
</dependency>
怀疑是jar包的问题,看了官方文档,使用高级的client是说还要依赖于其他两个jar:- org.elasticsearch.client:elasticsearch-rest-client
- org.elasticsearch:elasticsearch
新的pom.xml:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.1.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.1.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.1.0</version>
</dependency>
完整代码看:java如何连接es7.x集群