SpringBoot整合Elasticsearch

来自多彩世界 2020-06-22

SpringBoot整合Elasticsearch。

首先导入依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>

添加配置类RestClientConfig.java

@Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {
    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {

        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo("localhost:9200")
                .build();

        return RestClients.create(clientConfiguration).rest();
    }
}

接口继承CrudRepository

public interface UserRepository extends CrudRepository<User, Long> {

}

未完待续

参考链接