美文网首页
springboot集成elasticsearch7,使用res

springboot集成elasticsearch7,使用res

作者: 爱的旋转体 | 来源:发表于2020-08-12 14:57 被阅读0次

    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

    相关文章

      网友评论

          本文标题:springboot集成elasticsearch7,使用res

          本文链接:https://www.haomeiwen.com/subject/yezpdktx.html