如果按照下面的方式更改了依赖仍然有问题,可以直接指定一下 type:

-------------------------------

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

于是去https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch/7.1.0找到这两个jar包,加上,就保存成功了。

新的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>

 

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐