springboot集成elasticsearch7,使用rest,不使用transport
1 RestClientConfig
package com.xzp.config;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
/**
* @author xzp
* @date 2020-08-12 13:07:06
*/
@Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {
@Autowired
@Qualifier("elasticsearchRestHighLevelClient")
private RestHighLevelClient elasticsearchRestHighLevelClient;
@Override
public RestHighLevelClient elasticsearchClient() {
return elasticsearchRestHighLevelClient;
}
// no special bean creation needed
}
2 配置
elasticsearch:
rest:
uris:
- http://localhost:9200
参考:1.https://docs.spring.io/spring-data/elasticsearch/docs/4.0.2.RELEASE/reference/html/#elasticsearch.operations
2.https://docs.spring.io/spring-data/elasticsearch/docs/4.0.2.RELEASE/reference/html/#elasticsearch.clients.rest
网友评论