content: package site.alanliang.geekblog.config;
  
  import org.elasticsearch.client.RestHighLevelClient;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.core.convert.support.DefaultConversionService;
  import org.springframework.data.elasticsearch.client.ClientConfiguration;
  import org.springframework.data.elasticsearch.client.RestClients;
  import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
  import org.springframework.data.elasticsearch.core.ElasticsearchEntityMapper;
  import org.springframework.data.elasticsearch.core.EntityMapper;
  
  @Configuration
  public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {
  
      @Value("${elasticsearch.host}")
      private String host;
  
      @Value("${elasticsearch.port}")
      private String port;
  
      @Override
      public RestHighLevelClient elasticsearchClient() {
          ClientConfiguration clientConfiguration = ClientConfiguration.create(host + ":" + port);
          return RestClients.create(clientConfiguration).rest();
  //        return RestClients.create(ClientConfiguration.localhost()).rest();
      }
  
      // no special bean creation needed
  
      // use the ElasticsearchEntityMapper
      @Bean
      @Override
      public EntityMapper entityMapper() {
          ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(elasticsearchMappingContext(),
                  new DefaultConversionService());
          entityMapper.setConversions(elasticsearchCustomConversions());
          return entityMapper;
      }
  }
  