国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot3整合Elasticsearch8.x之全面保姆級(jí)教程

這篇具有很好參考價(jià)值的文章主要介紹了SpringBoot3整合Elasticsearch8.x之全面保姆級(jí)教程。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

整合ES

環(huán)境準(zhǔn)備

  1. 安裝配置EShttps://blog.csdn.net/qq_50864152/article/details/136724528
  2. 安裝配置Kibanahttps://blog.csdn.net/qq_50864152/article/details/136727707
  3. 新建項(xiàng)目:新建名為webSpringBoot3項(xiàng)目

elasticsearch-java

公共配置

  1. 介紹:一個(gè)開(kāi)源的高擴(kuò)展的分布式全文檢索引擎,可以近乎實(shí)時(shí)的存儲(chǔ) 和檢索數(shù)據(jù)
  2. 依賴(lài):web模塊引入elasticsearch-java依賴(lài)---但其版本必須與你下載的ES的版本一致
<!-- 若不存在Spring Data ES的某個(gè)版本支持你下的ES版本,則使用  -->
<!-- ES 官方提供的在JAVA環(huán)境使用的依賴(lài) -->
<dependency>
  <groupId>co.elastic.clients</groupId>
  <artifactId>elasticsearch-java</artifactId>
  <version>8.11.1</version>
</dependency>

<!-- 和第一個(gè)依賴(lài)是一起的,為了解決springboot項(xiàng)目的兼容性問(wèn)題  -->
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
</dependency>
  1. 配置:web模塊dev目錄application-dal添加

使用open+@Value("${elasticsearch.open}")的方式不能放到Nacos配置中心

# elasticsearch配置
elasticsearch:
  # 自定義屬性---設(shè)置是否開(kāi)啟ES,false表不開(kāi)竅ES
  open: true
  # es集群名稱(chēng),如果下載es設(shè)置了集群名稱(chēng),則使用配置的集群名稱(chēng)
  clusterName: es
  hosts: 127.0.0.1:9200
  # es 請(qǐng)求方式
  scheme: http
  # es 連接超時(shí)時(shí)間
  connectTimeOut: 1000
  # es socket 連接超時(shí)時(shí)間
  socketTimeOut: 30000
  # es 請(qǐng)求超時(shí)時(shí)間
  connectionRequestTimeOut: 500
  # es 最大連接數(shù)
  maxConnectNum: 100
  # es 每個(gè)路由的最大連接數(shù)
  maxConnectNumPerRoute: 100
  1. 配置:web模塊config包下新建ElasticSearchConfig類(lèi)
package cn.bytewisehub.pai.web.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Data
@Configuration
@ConfigurationProperties(prefix = "elasticsearch")
public class ElasticSearchConfig {

    // 是否開(kāi)啟ES
    private Boolean open;

    // es 集群host ip 地址
    private String hosts;

    // es用戶(hù)名
    private String userName;

    // es密碼
    private String password;

    // es 請(qǐng)求方式
    private String scheme;

    // es集群名稱(chēng)
    private String clusterName;

    // es 連接超時(shí)時(shí)間
    private int connectTimeOut;

    // es socket 連接超時(shí)時(shí)間
    private int socketTimeOut;

    // es 請(qǐng)求超時(shí)時(shí)間
    private int connectionRequestTimeOut;

    // es 最大連接數(shù)
    private int maxConnectNum;

    // es 每個(gè)路由的最大連接數(shù)
    private int maxConnectNumPerRoute;

    // es api key
    private String apiKey;


    public RestClientBuilder creatBaseConfBuilder(String scheme){


        // 1. 單節(jié)點(diǎn)ES Host獲取
        String host = hosts.split(":")[0];
        String port = hosts.split(":")[1];
        // The value of the schemes attribute used by noSafeRestClient() is http
        // but The value of the schemes attribute used by safeRestClient() is https
        HttpHost httpHost = new HttpHost(host, Integer.parseInt(port),scheme);

        // 2. 創(chuàng)建構(gòu)建器對(duì)象
        //RestClientBuilder: ES客戶(hù)端庫(kù)的構(gòu)建器接口,用于構(gòu)建RestClient實(shí)例;允許你配置與Elasticsearch集群的連接,設(shè)置請(qǐng)求超時(shí),設(shè)置身份驗(yàn)證,配置代理等
        RestClientBuilder builder = RestClient.builder(httpHost);

        // 連接延時(shí)配置
        builder.setRequestConfigCallback(requestConfigBuilder -> {
            requestConfigBuilder.setConnectTimeout(connectTimeOut);
            requestConfigBuilder.setSocketTimeout(socketTimeOut);
            requestConfigBuilder.setConnectionRequestTimeout(connectionRequestTimeOut);
            return requestConfigBuilder;
        });

        // 3. HttpClient 連接數(shù)配置
        builder.setHttpClientConfigCallback(httpClientBuilder -> {
            httpClientBuilder.setMaxConnTotal(maxConnectNum);
            httpClientBuilder.setMaxConnPerRoute(maxConnectNumPerRoute);
            return httpClientBuilder;
        });

        return builder;
    }
}
  1. 測(cè)試:web模塊test目錄下新建ElasticSearchTest類(lèi)
@Slf4j
@SpringBootTest
public class ElasticSearchTest {

    @Value("${elasticsearch.open}")
    // 是否開(kāi)啟ES,默認(rèn)開(kāi)啟
    String open = "true";
}

直接連接ES

  1. 設(shè)置:ES Elasticsearch.ymlxpack.security.enabled屬性設(shè)置為false

xpack.security.enabled
● 默認(rèn)true:必須使用賬號(hào)連接ES
● 若為false:必須使用http://localhost:9200/訪問(wèn)ES服務(wù)+啟動(dòng)Kibana服務(wù)會(huì)失敗+不需要使用賬號(hào)連接,但必須使用HTTP連接

  1. 添加:ElasticSearchConfig類(lèi)添加下列方法
/**
* @function: 創(chuàng)建使用http連接來(lái)直接連接ES服務(wù)器的客戶(hù)端
* 如果@Bean沒(méi)有指定bean的名稱(chēng),那么這個(gè)bean的名稱(chēng)就是方法名
*/
@Bean(name = "directConnectionESClient")
public ElasticsearchClient directConnectionESClient(){

    RestClientBuilder builder = creatBaseConfBuilder((scheme == "http")?"http":"http");
    
    //Create the transport with a Jackson mapper
    ElasticsearchTransport transport = new RestClientTransport(builder.build(), new JacksonJsonpMapper());

    //And create the API client
    ElasticsearchClient esClient = new ElasticsearchClient(transport);

    return esClient;
};
  1. 添加:ElasticSearchTest類(lèi)中添加下列代碼---索引名必須小寫(xiě)
  2. 運(yùn)行:設(shè)置跳過(guò)測(cè)試--->手動(dòng)運(yùn)行/不跳過(guò)--->直接install,但不運(yùn)行測(cè)試
@Resource(name = "directConnectionESClient")
ElasticsearchClient directConnectionESClient;


@Test
public void directConnectionTest() throws IOException {

if (open.equals("true")) {
    //創(chuàng)建索引
    CreateIndexResponse response = directConnectionESClient.indices().create(c -> c.index("direct_connection_index"));
    log.info(response.toString());
}
else{
    log.info("es is closed");
}
}

賬號(hào)密碼連接ES

  1. 設(shè)置:ES Elasticsearch.ymlxpack.security.enabled屬性使用默認(rèn)值+ xpack.security.http.ssl.enabled設(shè)置為false

注意:若xpack.security.enabled屬性為false,則xpack.security.http.ssl.enabled屬性不生效,即相當(dāng)于設(shè)置為false;所有以xpack開(kāi)頭的屬性都不會(huì)生效

ES Elasticsearch.ymlxpack.security.http.ssl.enabled
● 默認(rèn)true:必須使用https://localhost:9200/訪問(wèn)ES服務(wù)+啟動(dòng)Kibana服務(wù)會(huì)成功+需要使用賬號(hào)連接+必須使用HTTPS連接
● 若為false:必須使用http://localhost:9200/訪問(wèn)ES服務(wù)+啟動(dòng)Kibana服務(wù)會(huì)失敗+需要使用賬號(hào)連接,但必須使用HTTP連接

  1. 配置:dev目錄application-dal中添加下列配置
# elasticsearch配置
elasticsearch:
  userName:  #自己的賬號(hào)名
  password:  #自己的密碼
  1. 添加:ElasticSearchTest類(lèi)中添加下列代碼---索引名必須小寫(xiě)+不能有空格
  2. 運(yùn)行:設(shè)置跳過(guò)測(cè)試--->手動(dòng)運(yùn)行/不跳過(guò)--->直接install,但不運(yùn)行測(cè)試
@Resource(name = "accountConnectionESClient")
ElasticsearchClient accountConnectionESClient;


@Test
public void accountConnectionTest() throws IOException {

if (open.equals("true")) {
    //創(chuàng)建索引
    CreateIndexResponse response = accountConnectionESClient.indices().create(c -> c.index("account_connection_index"));
    log.info(response.toString());
}
else{
    log.info("es is closed");
}
}

證書(shū)賬號(hào)連接ES

  1. 設(shè)置:ES Elasticsearch.ymlxpack.security.enabledxpack.security.http.ssl.enabled配置項(xiàng)使用默認(rèn)值

設(shè)置為true后,ES就走https,若schemehttp,則報(bào)Unrecognized SSL message錯(cuò)誤

  1. 配置:將dev目錄application-dalelasticsearch.scheme配置項(xiàng)改成https
  2. 證書(shū)添加:終端輸入keytool -importcert -alias es_https_ca -keystore "D:\computelTool\Java\JDK\JDK21\lib\security\cacerts" -file "D:\computelTool\database\elasticsearch8111\config\certs\http_ca.crt"

keytool -delete -alias es_https_ca -keystore "D:\computelTool\Java\JDK\JDK21\lib\security\cacerts" ---與上面的命令相反

  1. 拷貝:將ESconfig目錄下certs目錄下的http_ca.crt文件拷貝到web模塊resource目錄
  2. 添加:ElasticSearchConfig類(lèi)添加下列方法
/**
* @function: 創(chuàng)建用于安全連接(證書(shū) + 賬號(hào))ES服務(wù)器的客戶(hù)端
* 如果@Bean沒(méi)有指定bean的名稱(chēng),那么這個(gè)bean的名稱(chēng)就是方法名
*/
@Bean(name = "accountAndCertificateConnectionESClient")
public ElasticsearchClient accountAndCertificateConnectionESClient() {


    RestClientBuilder builder = creatBaseConfBuilder( (scheme == "https")?"https":"https");

    // 1.賬號(hào)密碼的配置
    //CredentialsProvider: 用于提供 HTTP 身份驗(yàn)證憑據(jù)的接口; 允許你配置用戶(hù)名和密碼,以便在與服務(wù)器建立連接時(shí)進(jìn)行身份驗(yàn)證
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));

    // 2.設(shè)置自簽證書(shū),并且還包含了賬號(hào)密碼
    builder.setHttpClientConfigCallback(httpAsyncClientBuilder -> httpAsyncClientBuilder
                                        .setSSLContext(buildSSLContext())
                                        .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
                                        .setDefaultCredentialsProvider(credentialsProvider));

    RestClientTransport transport = new RestClientTransport(builder.build(), new JacksonJsonpMapper());

    //And create the API client
    ElasticsearchClient esClient = new ElasticsearchClient(transport);

    return esClient;
}

private static SSLContext buildSSLContext() {

    // 讀取http_ca.crt證書(shū)
    ClassPathResource resource = new ClassPathResource("http_ca.crt");
    SSLContext sslContext = null;
    try {
        // 證書(shū)工廠
        CertificateFactory factory = CertificateFactory.getInstance("X.509");
        Certificate trustedCa;
        try (InputStream is = resource.getInputStream()) {
            trustedCa = factory.generateCertificate(is);
        }
        // 密鑰庫(kù)
        KeyStore trustStore = KeyStore.getInstance("pkcs12");
        trustStore.load(null, "liuxiansheng".toCharArray());
        trustStore.setCertificateEntry("ca", trustedCa);
        SSLContextBuilder sslContextBuilder = SSLContexts.custom()
                 .loadTrustMaterial(trustStore, null);
        sslContext = sslContextBuilder.build();
    } catch (CertificateException | IOException | KeyStoreException | NoSuchAlgorithmException |
                 KeyManagementException e) {
        log.error("ES連接認(rèn)證失敗", e);
    }
    return sslContext;
}

  1. 測(cè)試:ElasticSearchTest類(lèi)添加
@Resource(name = "accountAndCertificateConnectionESClient")
ElasticsearchClient accountAndCertificateConnectionESClient;

@Test
public void  accountAndCertificateConnectionTest() throws IOException {

if (open.equals("true")) {
    //創(chuàng)建索引
    CreateIndexResponse response =  accountAndCertificateConnectionESClient.indices().create(c -> c.index("account_and_certificate_connection_index"));
    log.info(response.toString());
    System.out.println(response.toString());
}
else{
    log.info("es is closed");
}
}

Spring Data ES

公共配置

  1. 依賴(lài):web模塊引入該依賴(lài)---但其版本必須與你下載的ES的版本一致

版本:點(diǎn)擊https://spring.io/projects/spring-data-elasticsearch#learn,點(diǎn)擊GA版本的Reference Doc,點(diǎn)擊version查看Spring Data ESES版本的支持關(guān)系

參考:https://www.yuque.com/itwanger/vn4p17/wslq2t/https://blog.csdn.net/qq_40885085/article/details/105023026

<!-- 若存在Spring Data ES的某個(gè)版本支持你下的ES版本,則使用  -->
<!-- Spring官方在ES官方提供的JAVA環(huán)境使用的依賴(lài)的基礎(chǔ)上做了封裝 -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>

<!-- ESTestEntity用到 -->
<dependency>
	<groupId>jakarta.servlet</groupId>
	<artifactId>jakarta.servlet-api</artifactId>
	<version>6.0.0</version>
	<scope>provided</scope>
</dependency>

<!-- ESTestEntity用到 -->
<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <scope>provided</scope>
  <!--provided:指定該依賴(lài)項(xiàng)在編譯時(shí)是必需的,才會(huì)生效, 但在運(yùn)行時(shí)不需要,也不會(huì)生效-->
  <!--這樣 Lombok 會(huì)在編譯期靜悄悄地將帶 Lombok 注解的源碼文件正確編譯為完整的 class 文件 -->
</dependency>
  1. 新建:web模塊TestEntity目錄新建ESTestEntity
@Data
@EqualsAndHashCode(callSuper = false)
@Document(indexName = "test")
public class ESTestEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private Long id;

    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String content;

    private String title;

    private String excerpt;
}
  1. 新建:web模塊TestRepository包下新建ESTestRepository 接口
import cn.bytewisehub.pai.web.TestEntity.ESTestEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface ESTestRepository extends ElasticsearchRepository<ESTestEntity, Long> {
}

直接連接ES

  1. 配置:ES Elasticsearch.ymlxpack.security.enabled屬性設(shè)置為false

xpack.security.enabled
● 默認(rèn)true:必須使用賬號(hào)連接ES
● 若為false:必須使用http://localhost:9200/訪問(wèn)ES服務(wù)+啟動(dòng)Kibana服務(wù)會(huì)失敗+不需要使用賬號(hào)連接,但必須使用HTTP連接

  1. 配置:web模塊dev目錄application-dal添加
spring:
  elasticsearch:
    uris:
      - http://127.0.0.1:9200
  1. 新建:web模塊test目錄新建ElasticsearchTemplateTest
import cn.bytewisehub.pai.web.TestEntity.ESTestEntity;
import cn.bytewisehub.pai.web.TestRepository.ESTestRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;

@SpringBootTest
public class ElasticsearchTemplateTest {

    @Autowired
    ESTestRepository esTestRepository;

    @Autowired
    ElasticsearchTemplate elasticsearchTemplate;

    @Test
    void save() {
        ESTestEntity esTestEntity = new ESTestEntity();
        esTestEntity.setId(1L);
        esTestEntity.setContent("不安全連接");
        esTestEntity.setTitle("world");
        esTestEntity.setExcerpt("test");
        System.out.println(elasticsearchTemplate.save(esTestEntity));
    }

    @Test
    void insert() {
        ESTestEntity esTestEntity = new ESTestEntity();
        esTestEntity.setId(2L);
        esTestEntity.setContent("不安全連接");
        esTestEntity.setTitle("world");
        esTestEntity.setExcerpt("test");
        System.out.println(esTestRepository.save(esTestEntity));
    }
}
  1. 訪問(wèn):點(diǎn)擊http://localhost:9200/test/_search ---查詢(xún)索引庫(kù)test
    springboot3.x es8.x,java,spring,spring boot,elasticsearch,windows

HTTP連接ES

  1. 配置:ES Elasticsearch.ymlxpack.security.enabled屬性使用默認(rèn)值+ xpack.security.http.ssl.enabled設(shè)置為false

ES Elasticsearch.ymlxpack.security.http.ssl.enabled
● 默認(rèn)true:必須使用https://localhost:9200/訪問(wèn)ES服務(wù)+啟動(dòng)Kibana服務(wù)會(huì)成功+需要使用賬號(hào)連接+必須使用HTTPS連接
● 若為false:必須使用http://localhost:9200/訪問(wèn)ES服務(wù)+啟動(dòng)Kibana服務(wù)會(huì)失敗+需要使用賬號(hào)連接,但必須使用HTTP連接文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-850077.html

  1. 配置:web模塊dev目錄application-dal添加
spring:
  elasticsearch:
    uris:
      - http://127.0.0.1:9200
    username:  # 賬號(hào)用戶(hù)名
    password:  #賬號(hào)密碼
  1. 修改:web模塊test目錄下ElasticsearchTemplateTest修改成這樣,其他參見(jiàn)直接連接
import cn.bytewisehub.pai.web.TestEntity.ESTestEntity;
import cn.bytewisehub.pai.web.TestRepository.ESTestRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;

@SpringBootTest
public class ElasticsearchTemplateTest {

    @Autowired
    ESTestRepository esTestRepository;

    @Autowired
    ElasticsearchTemplate elasticsearchTemplate;

    @Test
    void save() {
        ESTestEntity esTestEntity = new ESTestEntity();
        esTestEntity.setId(1L);
        esTestEntity.setContent("不安全連接");
        esTestEntity.setTitle("world");
        esTestEntity.setExcerpt("test");
        System.out.println(elasticsearchTemplate.save(esTestEntity));
    }

    @Test
    void insert() {
        ESTestEntity esTestEntity = new ESTestEntity();
        esTestEntity.setId(2L);
        esTestEntity.setContent("不安全連接");
        esTestEntity.setTitle("world");
        esTestEntity.setExcerpt("test");
        System.out.println(esTestRepository.save(esTestEntity));
    }
}
  1. 訪問(wèn):點(diǎn)擊http://localhost:9200/test/_search ---查詢(xún)索引庫(kù)test

HTTPS連接ES

  1. 配置:ES Elasticsearch.ymlxpack.security.enabledxpack.security.http.ssl.enabled屬性使用默認(rèn)值
  2. 配置:web模塊dev目錄application-dal添加
spring:
  elasticsearch:
    uris:
      - https://127.0.0.1:9200
    username:  # 賬號(hào)用戶(hù)名
    password:  #賬號(hào)密碼
  1. 修改:web模塊test目錄下ElasticsearchTemplateTest修改成這樣,其他參見(jiàn)直接連接
import cn.bytewisehub.pai.web.TestEntity.ESTestEntity;
import cn.bytewisehub.pai.web.TestRepository.ESTestRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;

@SpringBootTest
public class ElasticsearchTemplateTest {

    @Autowired
    ESTestRepository esTestRepository;

    @Autowired
    ElasticsearchTemplate elasticsearchTemplate;

    @Test
    void save() {
        ESTestEntity esTestEntity = new ESTestEntity();
        esTestEntity.setId(1L);
        esTestEntity.setContent("不安全連接");
        esTestEntity.setTitle("world");
        esTestEntity.setExcerpt("test");
        System.out.println(elasticsearchTemplate.save(esTestEntity));
    }

    @Test
    void insert() {
        ESTestEntity esTestEntity = new ESTestEntity();
        esTestEntity.setId(2L);
        esTestEntity.setContent("不安全連接");
        esTestEntity.setTitle("world");
        esTestEntity.setExcerpt("test");
        System.out.println(esTestRepository.save(esTestEntity));
    }
}
  1. 訪問(wèn):點(diǎn)擊http://localhost:9200/test/_search ---查詢(xún)索引庫(kù)test

到了這里,關(guān)于SpringBoot3整合Elasticsearch8.x之全面保姆級(jí)教程的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • springboot整合elasticsearch8

    1.引入maven依賴(lài) 2.application.yml添加配置 3.編寫(xiě)config文件 啟動(dòng)demo項(xiàng)目,通過(guò)控制臺(tái)日志查看是否能夠正常連接es。 4.在DemoApplicationTests編寫(xiě)簡(jiǎn)單測(cè)試操作es。

    2024年02月12日
    瀏覽(22)
  • springBoot整合ElasticSearch8.x版本

    導(dǎo)入依賴(lài) ? dependency ? ? ? ? groupIdcom.fasterxml.jackson.core/groupId ? ? ? ? artifactIdjackson-databind/artifactId ? ? ? ? version2.13.2/version ? /dependency ? ? dependency ? ? ? ? groupIdorg.glassfish/groupId ? ? ? ? artifactIdjakarta.json/artifactId ? ? ? ? version2.0.1/version ? /dependency ? ? ? ? ? dependency ?

    2023年04月21日
    瀏覽(27)
  • springboot整合elasticsearch8組合條件查詢(xún)

    整合過(guò)程見(jiàn)上一篇文章 springboot整合elasticsearch8 1.es8多條件組合查詢(xún) 2.使用scroll進(jìn)行大數(shù)據(jù)量查詢(xún)

    2024年02月16日
    瀏覽(19)
  • SpringBoot3 整合 ElasticSearch7 示例

    SpringBoot3 整合 ElasticSearch7 示例

    做仿??晚?xiàng)目需要使用 es 做搜索,但是老師示例的是 SpringBoot2 + es6 去做的,然而我用的是 Spring3 + es7.17.10,于是踩了很多的坑。 在 es7 中,配置文件和查詢(xún)所需的實(shí)現(xiàn)類(lèi)都做了很大的改動(dòng),我以能成功運(yùn)行的代碼為例,大概說(shuō)一下怎么配置和使用。 首先 yml 配置文件發(fā)生了變

    2024年02月07日
    瀏覽(29)
  • java-springboot整合ElasticSearch8.2復(fù)雜查詢(xún)

    近期有大數(shù)據(jù)項(xiàng)目需要用到es,而又是比較新的es版本,網(wǎng)上也很少有8.x的java整合教程,所有寫(xiě)下來(lái)供各位參考。 首先 1.導(dǎo)包: 2.客戶(hù)端連接代碼EsUtilConfigClint: 一開(kāi)始按照其他博主的方法,長(zhǎng)時(shí)間連接不操作查詢(xún)?cè)俅握{(diào)用查詢(xún)時(shí)會(huì)報(bào)錯(cuò)timeout,所以要設(shè)置RequestConfigCallback 3

    2024年02月11日
    瀏覽(16)
  • elasticsearch8和kibana部署以及與springboot整合遇到的坑

    elasticsearch8和kibana部署以及與springboot整合遇到的坑

    我本來(lái)使用的是最新版本的es 8.6.2。但是由于ik分詞器只更新到8.6.1,所以就更改為部署8.6.1。在過(guò)程中遇到一些問(wèn)題,這里做一個(gè)總結(jié) 環(huán)境:windows10 elasticsearch版本:8.6.1 一、修改es 用戶(hù)密碼的方式 二、kibana 使用用戶(hù)名和密碼登錄 修改kibana.yml 文件 啟動(dòng)kibana一直閃退 解決方

    2024年02月02日
    瀏覽(22)
  • 關(guān)于springboot整合elasticsearch8.4.3的找不到相關(guān)類(lèi)JsonProvider、JsonProvider的解決方案

    關(guān)于springboot整合elasticsearch8.4.3的找不到相關(guān)類(lèi)JsonProvider、JsonProvider的解決方案

    環(huán)境是springboot是2.3.7,elasticsearch是8.4.3 關(guān)于8.4.3的官方文檔:https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/8.4/installation.html 創(chuàng)建ElasticsearchClient 對(duì)象: 一開(kāi)始報(bào)錯(cuò)ClassNotFoundException: jakarta.json.spi.JsonProvider,然后看了下官方文檔修改了下jakarta.json-api的版本.解決完成之后

    2024年02月02日
    瀏覽(26)
  • springboot整合elasticsearch8.2報(bào)錯(cuò)unable to parse response body for Response{requestLine

    springboot整合elasticsearch8.2報(bào)錯(cuò)unable to parse response body for Response{requestLine

    用postman發(fā)出請(qǐng)求,執(zhí)行saveAll命令的時(shí)候發(fā)現(xiàn)錯(cuò)誤,返回500。 但是很奇怪elsticsearch卻能夠存進(jìn)去。版本的話springboot是2.6.4,2.7貌似也不行 查看:官方資料 我們使用savaall會(huì)去繼承ElasticsearchRepository類(lèi),并調(diào)用其中的函數(shù)。 然而,據(jù)圖可知,在2022.8月依舊只支持7.17.4,而我的版本

    2024年02月16日
    瀏覽(23)
  • springboo整合elasticSearch8 java client api

    官方文檔: https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/connecting.html gradle maven 若無(wú)密碼,可以使用下面方式: 使用es自動(dòng)設(shè)置的mapping 設(shè)置mappings Doc是自定義實(shí)體類(lèi) 比如 select * from doc where user_id in(1,2,3); 方式一: 方式二: 方式三:

    2024年02月13日
    瀏覽(46)
  • SpringBoot3整合MyBatisPlus

    隨著 SpringBoot3 的發(fā)布, mybatisplus 也在不斷更新以適配 spirngboot3 。目前仍然處于維護(hù)升級(jí)階段,最初 2023.08 時(shí),官方宣布對(duì) SpringBoot3 的原生支持,詳情看這里。 但是對(duì)于較新版本的 SpringBoot3 ,仍然有很多 bug ,甚至無(wú)法啟動(dòng),摸爬滾打又游歷社區(qū)后,實(shí)踐后得到一套成功的

    2024年01月24日
    瀏覽(22)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包