当前位置:   article > 正文

springboot集成ElasticSearch使用RestHighLevelClient连接客户端_springboot elasticsearch-rest-high-level-client

springboot elasticsearch-rest-high-level-client

ES查询结构图

在这里插入图片描述
1.pom依赖引用

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>7.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>${
   elasticsearch.version}</version>
        </dependency>

        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>x-pack-transport</artifactId>
            <version>${
   elasticsearch.version}</version>
        </dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

2.yml 参数配置

elasticsearch:
  ansy:
    page-size: 7000
    cluster-name: my-application
    index-prefix: xz
    #用户名及密码
    xpack-security-user: elastic:elastic
    #es集群
    ips:
      - ip: 127.0.0.1
        port: 9200
      #- ip: 127.0.0.1
      #  port: 9300
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

3.config配置获取参数

package com.example.demo.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@ConfigurationProperties(prefix = "elasticsearch.ansy")
public class ElasticsearchConfig {
   
    private Map<String, String> sqls;

    // 数据库读取线程数
    private int pThreadNum;

    // ES同步线程数
    private int cThreadNum;

    //数据库读取条数
    private int pageSize;

    //集群IP
    private List<Map<String,String>> ips;

    private String clusterName;

    private String timepath;
    //ESXpack用户名密码
    private String xpackSecurityUser;
    //ESXpack instance.key
    private String xpackSslKey;
    //ESXpack instance.crt
    private String xpackSslCertificate;
    //ESXpack ca.crt
    private String xpackSslCertificateauthorities;
    //ESXpack xpack.security.transport.ssl.verification_mode certificate
    private String xpackSslVerificationmode;
    //ESXpack xpack.security.transport.ssl.enabled
    private String xpackSslEnabled;

    public Map<String, String> getSqls() {
   
        return sqls;
    }

    public void setSqls(Map<String, String> sqls) {
   
        this.sqls = sqls;
    }

    public int getpThreadNum() {
   
        return pThreadNum;
    }

    public void setpThreadNum(int pThreadNum) {
   
        this.pThreadNum = pThreadNum;
    }

    public int getcThreadNum() {
   
        return cThreadNum;
    }

    public void setcThreadNum(int cThreadNum) {
   
        this.cThreadNum = cThreadNum;
    }

    public int getPageSize() {
   
        return pageSize;
    }

    public void setPageSize(int pageSize) {
   
        this.pageSize = pageSize;
    }

    public List<Map<String, String>> getIps() {
   
        return ips;
    }

    public void setIps(List<Map<String, String>> ips) {
   
        this.ips = ips;
    }

    public String getClusterName() {
   
        return clusterName;
    }

    public void setClusterName(String clusterName) {
   
        this.clusterName = clusterName;
    }

    public String getTimepath() {
   
        return timepath;
    }

    public void setTimepath(String timepath) {
   
        this.timepath = timepath;
    }

    public String getXpackSecurityUser() {
   
        return xpackSecurityUser;
    }

    public void setXpackSecurityUser(String xpackSecurityUser) {
   
        this.xpackSecurityUser = xpackSecurityUser;
    }

    public String getXpackSslKey() {
   
        return xpackSslKey;
    }

    public void setXpackSslKey(String xpackSslKey) {
   
        this.xpackSslKey = xpackSslKey;
    }

    public String getXpackSslCertificate() {
   
        return xpackSslCertificate;
    }

    public void setXpackSslCertificate(String xpackSslCertificate) {
   
        this.xpackSslCertificate = xpackSslCertificate;
    }

    public String getXpackSslCertificateauthorities() {
   
        return xpackSslCertificateauthorities;
    }

    public void setXpackSslCertificateauthorities(String xpackSslCertificateauthorities) {
   
        this.xpackSslCertificateauthorities = xpackSslCertificateauthorities;
    }

    public String getXpackSslVerificationmode() {
   
        return xpackSslVerificationmode;
    }

    public void setXpackSslVerificationmode(String xpackSslVerificationmode
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/68646
推荐阅读
相关标签
  

闽ICP备14008679号