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

【SpringBoot】整合Elasticsearch 操作索引及文檔

這篇具有很好參考價值的文章主要介紹了【SpringBoot】整合Elasticsearch 操作索引及文檔。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

官網(wǎng)操作文檔:Elasticsearch Clients | Elastic ?????

???????? 踩坑太多了。。。這里表明一下Spring Boot2.4以上版本可能會出現(xiàn)問題,所以我降到了2.2.1.RELEASE。對于現(xiàn)在2023年6月而言,Es版本已經(jīng)到了8.8,而SpringBoot版本已經(jīng)到了3.x版本。如果是高版本的Boot在配置類的時候會發(fā)現(xiàn)RestHighLevelClient已過時。從官網(wǎng)也可以看的出來RestHighLevelClient已過時。所以這篇博文中不會用到關(guān)于RestHighLevelClient的Api。

??????? 此篇博文的對應(yīng)版本關(guān)系:Elasticsearch 8.2.0 + Spring Boot 2.7.5。在進(jìn)入到下面的案例,我需要在這之前先介紹RestClient、RestHighLevelClient、RestClientTransport、ElasticsearchClient。

RestClient

??????? 這個類主要是用作于與服務(wù)端IP以及端口的配置,在其的builder()方法可以設(shè)置登陸權(quán)限的賬號密碼、連接時長等等??偠灾褪?strong>服務(wù)端配置。

【SpringBoot】整合Elasticsearch 操作索引及文檔

【SpringBoot】整合Elasticsearch 操作索引及文檔

RestClientTransport

??????? 這是Jackson映射器創(chuàng)建傳輸。建立客戶端與服務(wù)端之間的連接傳輸數(shù)據(jù)。這是在創(chuàng)建ElasticsearchClient需要的參數(shù),而創(chuàng)建RestClientTransport就需要上面創(chuàng)建的RestClient。

ElasticsearchClient

??????? 這個就是Elasticsearch的客戶端。調(diào)用Elasticsearch語法所用到的類,其就需要傳入上面介紹的RestClientTransport。

【SpringBoot】整合Elasticsearch 操作索引及文檔

引入依賴

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<!-- 高版本還需引入此依賴 -->
<dependency>
    <groupId>jakarta.json</groupId>
    <artifactId>jakarta.json-api</artifactId>
    <version>2.0.0</version>
</dependency>

修改yml

??????? 需要注意的是賬號和密碼可以不需要,看自己的Elasticsearch是否有配置賬號密碼。具體對Elasticsearch的登陸操作可以看:中偏下的位置就是對賬號密碼的設(shè)置。【Linux】Docker部署鏡像環(huán)境 (持續(xù)更新ing)_小白的救贖的博客-CSDN博客

server:
  port: 8080

elasticsearch:
  hostAndPort: 192.168.217.128:9200 # 低版本使用的
  ip: 192.168.217.128
  port: 9200
  username: elastic
  password: 123456
  connectionTimeout: 1000
  socketTimeout: 30000

配置類 ???

????????這里演示兩種情況的配置:第一個代碼塊是SpringBoot2.4以下 + 7.x版本Elasticsearch的配置。第二個代碼塊是Spring2.4以上 + 8.x版本Elasticsearch的配置。

@Configuration
public class ElasticConfig extends AbstractElasticsearchConfiguration {

    @Value("${elasticsearch.hostAndPort}")
    private String hostAndPort;

    @Value("${elasticsearch.username}")
    private String username;

    @Value("${elasticsearch.password}")
    private String password;

    @Value("${elasticsearch.connectionTimeout}")
    private String connectTimeout;

    @Value("${elasticsearch.socketTimeout}")
    private String socketTimeout;

    /**
     * create Elasticsearch client
     * @return RestHighLevelClient
     */
    @Bean
    public RestHighLevelClient elasticsearchClient() {
        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(username, password));
        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(hostAndPort)
                .withConnectTimeout(Long.parseLong(connectTimeout))
                .withSocketTimeout(Long.parseLong(socketTimeout))
                .withBasicAuth(username, password)
                .build();
        return RestClients.create(clientConfiguration).rest();
    }

    /**
     * 將連接傳入 Elasticsearch在 Spring Boot的模板類中
     * @return 返回 Es的模板類
     */
    @Bean
    public ElasticsearchRestTemplate elasticsearchRestTemplate() {
        return new ElasticsearchRestTemplate(elasticsearchClient());
    }
}
@Configuration
public class ElasticConfig {

    @Value("${elasticsearch.ip}")
    private String ip;

    @Value("${elasticsearch.port}")
    private String port;

    @Value("${elasticsearch.username}")
    private String username;

    @Value("${elasticsearch.password}")
    private String password;

    @Value("${elasticsearch.connectionTimeout}")
    private String connectTimeout;

    @Value("${elasticsearch.socketTimeout}")
    private String socketTimeout;

    /**
     * create Elasticsearch client
     * @return RestHighLevelClient
     */
    @Bean
    public ElasticsearchClient elasticsearchClient() {
        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(username, password));

        RestClient restClient = RestClient.builder(
                new HttpHost(ip, Integer.parseInt(port)))
                .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
                .setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
                    @Override
                    public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) {
                        return builder.setConnectTimeout(Integer.parseInt(connectTimeout)).setSocketTimeout(Integer.parseInt(socketTimeout));
                    }
                }).build();

        ElasticsearchTransport transport 
                        = new RestClientTransport(restClient, new JacksonJsonpMapper());

        return new ElasticsearchClient(transport);
    }
}

控制層

??????? 這里為了方便快速入門,就把所有業(yè)務(wù)代碼都放在控制層中了。這篇博文主要是對索引進(jìn)行操作,所以說獲取到ElasticsearchClient后會調(diào)用indices()方法,這個方法就是操作索引的方法。次代碼塊是展示變量以及類注解。后面逐一暫時各個測試代碼塊Api以及返回結(jié)果。

@RestController
@RequestMapping("/es")
@Slf4j
public class EsController{

    @Autowired
    private ElasticConfig elasticConfig;
}

創(chuàng)建索引

/**
 * create index
 * @return is success?
 */
@PutMapping("/createIndex")
public boolean createIndex() throws IOException {
    CreateIndexRequest indexRequest 
                        = new CreateIndexRequest.Builder().index("user").build();
    CreateIndexResponse indexResponse 
                        = elasticConfig.esClient().indices().create(indexRequest);

    boolean isSuccess = indexResponse.acknowledged();
    if(isSuccess) {
        log.info("創(chuàng)建索引成功");
    } else {
        log.info("創(chuàng)建索引失敗");
    }
    return isSuccess;
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

查詢單個索引數(shù)據(jù)

/**
 * get one index data by id
 */
@GetMapping("/getIndex")
public void getIndex() throws IOException {
   GetResponse<User> response = elasticConfig.esClient().get(g -> g
           .index("user")
           .id("1000")
           ,User.class
   );
   if(response.found()) {
       log.info("此用戶的姓名為,{}",response.source().getUsername());
   } else {
       log.info("未查詢到此用戶");
   }
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

刪除索引

??????? 這里我測試刪除索引成功后又把索引添加了回去。為了后面的其它操作做準(zhǔn)備。

/**
 * delete one index
 */
@DeleteMapping("/deleteIndex")
public boolean deleteIndex() throws IOException {
    DeleteIndexRequest indexRequest 
                        = new DeleteIndexRequest.Builder().index("user").build();
    DeleteIndexResponse deleteResponse 
                        = elasticConfig.esClient().indices().delete(indexRequest);
    boolean isSuccess = deleteResponse.acknowledged();
    if(isSuccess) {
        log.info("刪除索引成功");
    } else {
        log.info("刪除索引失敗");
    }
    return isSuccess;
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

增加索引內(nèi)容

??????? 這里我新增了個實體類,方便添加到索引內(nèi)容中。這里大概有四種方式可以創(chuàng)建,這里我演示了三種方式,第四種是使用到了ElasticsearchAsyncClient ,這是Elastic異步客戶端。

@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
    private String username;
    private String sex;
    private Integer age;
}
/**
 * 向索引內(nèi)容插入數(shù)據(jù)
 */
@PostMapping("/insertIndexData")
public void insertIndexData() throws IOException {
    User user = new User("zhangSan","男",18);
    /*
    第一種方式:使用DSL語法創(chuàng)建對象
    IndexRequest<User> indexRequest = IndexRequest.of(i -> i
            .index("user")
            .id("1000")
            .document(user)
    IndexResponse indexResponse = elasticConfig.esClient().index(indexRequest.build());
    );
     */
    /*
    第二種方式:使用Elasticsearch客戶端上配置的對象映射器映射到JSON。
    IndexResponse indexResponse = elasticConfig.esClient().index(i -> i
            .index("user")
            .id("1000")
            .document(user)
    );
     */
    // 第三種方式:使用構(gòu)造器模式
    IndexRequest.Builder<User> indexRequest = new IndexRequest.Builder<>();
    indexRequest.index("user");
    indexRequest.id("1000");
    indexRequest.document(user);
    IndexResponse indexResponse = elasticConfig.esClient().index(indexRequest.build());
    log.info("index,{}",indexResponse.index());
    log.info("id,{}",indexResponse.id());
    log.info("version,{}",indexResponse.version());
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

批量添加索引數(shù)據(jù)

????????BulkRequest包含一組操作,每個操作都是具有多個變體的類型。為了創(chuàng)建這個請求,可以方便地將構(gòu)建器對象用于主請求,并將流利的DSL用于每個操作。下面的示例顯示了如何為列表或應(yīng)用程序?qū)ο缶幹扑饕?/p>

??????? operations是BulkOperation的生成器,BulkOperation是一種變體類型。此類型具有索引、創(chuàng)建、更新刪除變體。

/**
 * 批量插入索引數(shù)據(jù)
 */
@PostMapping("/batchInsertIndex")
public void batchInsertIndex() throws IOException {
    // 將需要批量添加的數(shù)據(jù)放到List中
    List<User> list = new ArrayList<>();
    list.add(new User("liSi","女",20));
    list.add(new User("wangWu","男",22));
    // 使用BulkRequest的構(gòu)造器
    BulkRequest.Builder request = new BulkRequest.Builder();
    for(User user : list) {
        request.operations(l -> l
                .index(i -> i
                        .index("user")
                        .document(user)
                )
        );
    }
    BulkResponse response = elasticConfig.esClient().bulk(request.build());
    if(response.errors()) {
        log.info("批量插入報錯");
    } else {
        log.info("批量插入成功");
    }
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

批量刪除索引數(shù)據(jù)

/**
 * 批量刪除索引數(shù)據(jù)
 */
@DeleteMapping("/batchDeleteIndex")
public void batchDeleteIndex() throws IOException {
    BulkRequest.Builder request = new BulkRequest.Builder();
    // 根據(jù)id做到刪除索引的數(shù)據(jù)
    request.operations(l -> l
            .delete(i -> i
                    .index("user")
                    .id("vGK5sogBM87kk5Mw8V0P")
            )
    );
    request.operations(l -> l
            .delete(i -> i
                    .index("user")
                    .id("u2K5sogBM87kk5Mw8V0P")
            )
    );
    BulkResponse response = elasticConfig.esClient().bulk(request.build());
    if(response.errors()) {
        log.info("批量刪除報錯");
    } else {
        log.info("批量刪除成功");
    }
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

????????? 這里批量刪除接口測試完后,我又批量添加了幾行數(shù)據(jù),方便下面方法的測試。

// 以下就是我添加的數(shù)據(jù)
list.add(new User("liSi","女",20));
list.add(new User("wangWu","男",22));
list.add(new User("zhaoLiu","男",20));
list.add(new User("xiaoQi","女",21));

【SpringBoot】整合Elasticsearch 操作索引及文檔

簡單查詢/單條件

????????可以組合多種類型的搜索查詢。我們將從簡單的文本匹配查詢開始。單條件準(zhǔn)確查詢主要用到的關(guān)鍵字是term。而模糊查詢就需要用到match。而match這里就不演示了。

/**
 * 單條件查詢
 */
@GetMapping("/search")
public void search() throws IOException {
    SearchResponse<User> response = elasticConfig.esClient().search(s -> s
            .index("user")
            .query(q -> q
                    .term(e -> e
                            .field("age")
                            .value("20")
                    )
            ), User.class
    );
    // 獲取查詢后的命中條數(shù):其中包括 TotalHitsRelation 以及 total
    TotalHits total = response.hits().total();
    boolean isExactResult = total.relation() == TotalHitsRelation.Eq;
    if (isExactResult) {
        log.info("There are " + total.value() + " results");
    } else {
        log.info("There are more than " + total.value() + " results");
    }
    // 解析查詢到的所有信息
    List<Hit<User>> hits = response.hits().hits();
    for(Hit<User> hit : hits) {
        log.info("id,{}", hit.id());
    }
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

多條件查詢 / 范圍查詢

????????Elasticsearch允許將單個查詢組合起來,以構(gòu)建更復(fù)雜的搜索請求。當(dāng)前數(shù)據(jù)有五條,為了更好的多條件查詢,我又增加了5條數(shù)據(jù)。多條件查詢用到的關(guān)鍵字主要就是bool。

// 起初的5條數(shù)據(jù)
list.add(new User("zhangSan","男",18));
list.add(new User("liSi","女",20));
list.add(new User("wangWu","男",22));
list.add(new User("zhaoLiu","男",20));
list.add(new User("xiaoQi","女",21));
// 以下就是我添加的數(shù)據(jù)
list.add(new User("zhangSan","男",20));
list.add(new User("zhangSan","男",21));
list.add(new User("zhangSan","男",22));
list.add(new User("zhangSan","男",23));
list.add(new User("zhangSan","男",24));
/**
 * 多條件查詢
 */
@GetMapping("/batchSearch")
public void batchSearch() throws IOException {
    // 查詢性別
    Query sex = MatchQuery.of(m -> m
            .field("sex")
            .query("男")
    )._toQuery();
    // 查詢年齡區(qū)間
    Query age = RangeQuery.of(r -> r
            .field("age")
            .lte(JsonData.of(20))
            .gte(JsonData.of(18))
    )._toQuery();
    // 結(jié)合性別和年齡區(qū)間查詢來搜索用戶索引
    SearchResponse<User> response = elasticConfig.esClient().search(s -> s
            .index("user")
            .query(q -> q
                .bool(b -> b
                    .must(sex)
                    .must(age)
                )
            ),User.class
    );
    // 獲取查詢后的命中條數(shù):其中包括 TotalHitsRelation 以及 total
    TotalHits total = response.hits().total();
    boolean isExactResult = total.relation() == TotalHitsRelation.Eq;
    if (isExactResult) {
        log.info("There are " + total.value() + " results");
    } else {
        log.info("There are more than " + total.value() + " results");
    }
    // 解析查詢到的所有信息
    List<Hit<User>> hits = response.hits().hits();
    for(Hit<User> hit : hits) {
        log.info("id,{}", hit.id());
    }
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

分頁查詢

??????? 主要就是Elasticsearch語法中的from與size表示:當(dāng)前頁的開始索引處以及每頁條數(shù)。

/**
 * 分頁查詢
 */
@GetMapping("/searchByPage")
public void searchByPage() throws IOException {
    // 假設(shè)每頁3條數(shù)據(jù) 那么查詢第二頁的參數(shù)就是:開始索引處為(2 - 1) * 3 = 3 以及 每頁條數(shù)3
    SearchResponse<User> response = elasticConfig.esClient().search(b -> b
            .index("user")
            .from(3)
            .size(3)
            ,User.class
    );
    log.info("查詢到的總條數(shù)為,{}",response.hits().total().value());
    List<Hit<User>> hits = response.hits().hits();
    for(Hit<User> hit : hits) {
        log.info("查詢到的id,{}", hit.id());
    }
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

【SpringBoot】整合Elasticsearch 操作索引及文檔文章來源地址http://www.zghlxwxcb.cn/news/detail-493899.html

查詢所有索引數(shù)據(jù)

/**
 * get all index data
 */
@GetMapping("/getAllIndex")
public void getAllIndex() throws IOException {
    SearchResponse<User> response = elasticConfig.esClient().search(s -> s
            .index("user")
            ,User.class);
    // 解析查詢到的所有信息
    List<Hit<User>> hits = response.hits().hits();
    for(Hit<User> hit : hits) {
        log.info(String.valueOf(hit.source()));
    }
}

【SpringBoot】整合Elasticsearch 操作索引及文檔

到了這里,關(guān)于【SpringBoot】整合Elasticsearch 操作索引及文檔的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • ElasticSearch學(xué)習(xí)2--索引和文檔的基礎(chǔ)操作

    ElasticSearch學(xué)習(xí)2--索引和文檔的基礎(chǔ)操作

    1、創(chuàng)建索引 ??????? 對ES的操作其實就是發(fā)送一個restful請求,kibana中在DevTools中進(jìn)行ES操作 ??????? 創(chuàng)建索引時需要注意ES的版本,不同版本的ES創(chuàng)建索引的語句略有差別,會導(dǎo)致失敗 如下創(chuàng)建一個名為people的索引,settings,一些設(shè)置,mappings字段映射 我的版本是7.0之前

    2024年02月10日
    瀏覽(18)
  • Elasticsearch索引庫和文檔的相關(guān)操作

    Elasticsearch索引庫和文檔的相關(guān)操作

    前言:最近一直在復(fù)習(xí)Elasticsearch相關(guān)的知識,公司搜索相關(guān)的技術(shù)用到了這個,用公司電腦配了環(huán)境,借鑒網(wǎng)上的課程進(jìn)行了總結(jié)。希望能夠加深自己的印象以及幫助到其他的小伙伴兒們????。 如果文章有什么需要改進(jìn)的地方還請大佬不吝賜教????。 小威在此先感謝各位

    2024年02月02日
    瀏覽(37)
  • elasticsearch(ES)分布式搜索引擎01——(初識ES,索引庫操作和文檔操作,RestClient操作索引庫和文檔)

    elasticsearch(ES)分布式搜索引擎01——(初識ES,索引庫操作和文檔操作,RestClient操作索引庫和文檔)

    1.1.1.elasticsearch的作用 elasticsearch是一款非常強(qiáng)大的開源搜索引擎,具備非常多強(qiáng)大功能,可以幫助我們從海量數(shù)據(jù)中快速找到需要的內(nèi)容 1.1.2.ELK技術(shù)棧 elasticsearch結(jié)合kibana、Logstash、Beats,也就是elastic stack(ELK)。被廣泛應(yīng)用在日志數(shù)據(jù)分析、實時監(jiān)控等領(lǐng)域: 而elasticsearc

    2024年02月07日
    瀏覽(48)
  • ElasticSearch基礎(chǔ)1——索引和文檔。Kibana,RestClient操作索引和文檔+黑馬旅游ES庫導(dǎo)入

    ElasticSearch基礎(chǔ)1——索引和文檔。Kibana,RestClient操作索引和文檔+黑馬旅游ES庫導(dǎo)入

    導(dǎo)航: 【黑馬Java筆記+踩坑匯總】JavaSE+JavaWeb+SSM+SpringBoot+瑞吉外賣+SpringCloud/SpringCloudAlibaba+黑馬旅游+谷粒商城 黑馬旅游源碼:? https://wwmg.lanzouk.com/ikjTE135ybje 目錄 1.初識彈性搜索elasticsearch 1.1.了解ES 1.1.1.elasticsearch的作用 1.1.2.ELK彈性棧 1.1.3.elasticsearch和lucene 1.1.4.搜索引擎技術(shù)

    2024年02月01日
    瀏覽(50)
  • ElasticSearch之RestClient操作索引庫和文檔

    ElasticSearch之RestClient操作索引庫和文檔

    前言:上文介紹了使用DSL語言操作索引庫和文檔,本篇文章將介紹使用Java中的RestClient來對索引庫和文檔進(jìn)行操作。 希望能夠加深自己的印象以及幫助到其他的小伙伴兒們????。 如果文章有什么需要改進(jìn)的地方還請大佬不吝賜教????。 小威在此先感謝各位大佬啦~~????

    2024年02月06日
    瀏覽(21)
  • 【ElasticSearch】ElasticSearch Java API的使用——常用索引、文檔、查詢操作(二)

    Elaticsearch ,簡稱為es,es是一個開源的 高擴(kuò)展 的 分布式全文檢索引擎 ,它可以近乎 實時的存儲 、 檢索數(shù)據(jù); 本身擴(kuò)展性很好,可以擴(kuò)展到上百臺服務(wù)器,處理PB級別(大數(shù)據(jù)時代)的數(shù)據(jù)。es也使用java開發(fā)并使用Lucene作為其核心來實現(xiàn)所有索引和搜索的功能,但是它的 目的

    2024年01月16日
    瀏覽(124)
  • elasticsearch[一]-索引庫操作(輕松創(chuàng)建)、文檔增刪改查、批量寫入(效率倍增)

    elasticsearch[一]-索引庫操作(輕松創(chuàng)建)、文檔增刪改查、批量寫入(效率倍增)

    在 elasticsearch 提供的 API 中,與 elasticsearch 一切交互都封裝在一個名為 RestHighLevelClient 的類中,必須先完成這個對象的初始化,建立與 elasticsearch 的連接。 分為三步: 1)引入 es 的 RestHighLevelClient 依賴: 2)因為 SpringBoot 默認(rèn)的 ES 版本是 7.6.2,所以我們需要覆蓋默認(rèn)的 ES 版本

    2024年01月16日
    瀏覽(22)
  • springboot3整合elasticsearch8.7.0實現(xiàn)為bean對象創(chuàng)建索引添加映射

    springboot3整合elasticsearch8.7.0實現(xiàn)為bean對象創(chuàng)建索引添加映射

    目錄 準(zhǔn)備工作 添加相關(guān)依賴 在yml中配置elasticsearch 主要內(nèi)容 實體類 ElasticSearch配置類 測試 確認(rèn)當(dāng)前沒有counter索引 啟動spring 再次查詢counter索引? 在測試類中輸出counter索引的映射 官方文檔 要注意版本對應(yīng)關(guān)系 spring官方文檔中有版本對照表 目前我使用的都是最新的版本,

    2024年02月03日
    瀏覽(20)
  • 【ElasticSearch】基于 Java 客戶端 RestClient 實現(xiàn)對 ElasticSearch 索引庫、文檔的增刪改查操作,以及文檔的批量導(dǎo)入

    【ElasticSearch】基于 Java 客戶端 RestClient 實現(xiàn)對 ElasticSearch 索引庫、文檔的增刪改查操作,以及文檔的批量導(dǎo)入

    ElasticSearch 官方提供了各種不同語言的客戶端,用來操作 ES。這些客戶端的本質(zhì)就是組裝 DSL 語句,通過 HTTP 請求發(fā)送給 ES 服務(wù)器。 官方文檔地址:https://www.elastic.co/guide/en/elasticsearch/client/index.html。 在本文中,我們將著重介紹 ElasticSearch Java 客戶端中的 RestClient,并演示如何

    2024年02月08日
    瀏覽(29)
  • [elastic 8.x]java客戶端連接elasticsearch與操作索引與文檔

    為了方便演示,我關(guān)閉了elasticsearch的安全驗證,帶安全驗證的初始化方式將在最后專門介紹 其中,HotelDoc是一個實體類 帶安全驗證的連接有點復(fù)雜,將下列代碼中CA證書的位置改為實際所在的位置就行了。 password為elastic的密碼,可以在我的另一篇文章中查看密碼的重置方式

    2024年04月11日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包