赞
踩
1,和之前的一样都要在、/opt文件夹下mkdir docker_es;
2, 在docker_es文件夹下创建yml文件;
version: "3.1" services: elasticsearch: image: daocloud.io/library/elasticsearch:6.5.4 restart: always container_name: elasticsearch environment: - TZ=Asia/Shanghai ports: - 9200:9200 kibana: image: daocloud.io/library/kibana:6.5.4 restart: always container_name: kibana ports: - 5601:5601 environment: - elasticsearch_url=http://192.168.32.137:9200 depends_on: - elasticsearch
3,docker-compose up -d 启动容器
4,容器启动后进入到容器内部docker exec -it id bash
5,进入到容器的bin目录下。就会看到elasticsearch-plugin这个文件夹
6,在bin下执行./elasticsearch-plugin install http://192.168.163.1:8080/elasticsearch-analysis-ik-6.5.4.zip
》》》这一步是因为自己没有分词器所有要在外部下载:这个是吧elasticsearch-analysis-ik-6.5.4.zip放到tomcat的root包下,启动tomcat从里面下载。
》》》下边的问题一定要选y
这样分词器就安装成功了
》》》测试分词器是否可以分词
7,最后访问 192.168.32.137:9200
成功之后才能访问 192.168.32.137:5601
8.重启之后进不去在docker-es文件夹下运行sysctl -w vm.max_map_count=262144然后再重启即可
java实现所要的依赖
<dependencies> <!-- 1. elasticsearch--> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>6.5.4</version> </dependency> <!-- 2. elasticsearch的高级API--> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-high-level-client</artifactId> <version>6.5.4</version> </dependency> <!-- 3. junit--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <!-- 4. lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.22</version> </dependency> </dependencies>
建立连接并测试
public class EsClient { public static RestHighLevelClient getEsClient() { //创建连接 // 创建HttpHost对象 HttpHost httpHost = new HttpHost("192.168.32.137", 9200); // 创建RestClientBuilder RestClientBuilder builder = RestClient.builder(httpHost); // 创建RestHighLevelClient RestHighLevelClient client = new RestHighLevelClient(builder); return client; } } 测试 public class JavaEsTest { @Test public void clientTest(){ RestHighLevelClient esClient=EsClient.getEsClient(); // 打印只要是true就证明连接成功 System.out.println(esClient); } } //显示这个就是连接成功 //org.elasticsearch.client.RestHighLevelClient@49e202ad // Process finished with exit code 0
附录:
》》》因为内部的分词器是没有中文的所有要自己加一个
在GitHub找一个ik
寻找对应的版本
下载
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。