其他分享
首页 > 其他分享> > spring boot 整合elasticSearch

spring boot 整合elasticSearch

作者:互联网

根据文档将maven依赖导入
因为spring boot web导入过jackson了 所以jackson可以不用导入

  <dependencies>
    <dependency>
      <groupId>co.elastic.clients</groupId>
      <artifactId>elasticsearch-java</artifactId>
      <version>7.16.3</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.12.3</version>
    </dependency>
  </dependencies>

配置client

@Configuration
public class ElasticSearchConfig {
    @Bean
    public ElasticsearchClient elasticsearchClient() {
        RestClient restClient = RestClient.builder(
                new HttpHost("localhost", 9200)).build();

        ElasticsearchTransport transport = new RestClientTransport(
                restClient, new JacksonJsonpMapper());

        return new ElasticsearchClient(transport);
    }
}

标签:jackson,restClient,spring,boot,导入,elasticSearch,new
来源: https://www.cnblogs.com/lyraHeartstrings/p/15865305.html