1.TransportClient
<!--es-->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
public interface *****Respository extends ElasticsearchRepository<*****Vo, String> {
}
Repository接口的自动实现,包括对自定义查找器方法的支持。
2.RestClient
<!--es-->
<!-- https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.8.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-elasticsearch -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-high-level-client -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.8.10</version>
</dependency>
@Configuration
public class ElasticsearchConf extends AbstractElasticsearchConfiguration {
@Value("${es.endpoints}")
String esIp;
@Override
public RestHighLevelClient elasticsearchClient() {
return RestClients.create(ClientConfiguration.create(esIp)).rest();
}
@Bean
@Override
public EntityMapper entityMapper() {
ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(
elasticsearchMappingContext(), new DefaultConversionService()
);
entityMapper.setConversions(elasticsearchCustomConversions());
return entityMapper;
}
}
es:
endpoints: 192.168.1.12:9200
因为我用的是docker所以只做了docker相关笔记
- 进入docker 容器
docker exec -it a70fda65d2ba /bin/bash
- 安装es对应分词器版本(找了半天对应的版本)
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.10/elasticsearch-analysis-ik-6.8.10.zip 分词器及相关下载 https://elasticsearch.cn/download/
- 查看安装的分词器
- 退出/重启
exit docker restart elasticsearch
|