ES(ElasticSearch)的安装(依赖)

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
这样分词器就安装成功了
》》》测试分词器是否可以分词
ES(ElasticSearch)的安装(依赖)_第1张图片

ES(ElasticSearch)的安装(依赖)_第2张图片ES(ElasticSearch)的安装(依赖)_第3张图片7,最后访问 192.168.32.137:9200
ES(ElasticSearch)的安装(依赖)_第4张图片

成功之后才能访问 192.168.32.137:5601

8.重启之后进不去在docker-es文件夹下运行sysctl -w vm.max_map_count=262144然后再重启即可

java实现所要的依赖

<dependencies>
    
    <dependency>
        <groupId>org.elasticsearchgroupId>
        <artifactId>elasticsearchartifactId>
        <version>6.5.4version>
    dependency>

    
    <dependency>
        <groupId>org.elasticsearch.clientgroupId>
        <artifactId>elasticsearch-rest-high-level-clientartifactId>
        <version>6.5.4version>
    dependency>

    
    <dependency>
        <groupId>junitgroupId>
        <artifactId>junitartifactId>
        <version>4.12version>
    dependency>

    
    <dependency>
        <groupId>org.projectlombokgroupId>
        <artifactId>lombokartifactId>
        <version>1.16.22version>
    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
ES(ElasticSearch)的安装(依赖)_第5张图片
寻找对应的版本
ES(ElasticSearch)的安装(依赖)_第6张图片下载
ES(ElasticSearch)的安装(依赖)_第7张图片

你可能感兴趣的:(四阶段,笔记,面试)