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

Spring Boot Elasticsearch7.6.2實現(xiàn)創(chuàng)建索引、刪除索引、判斷索引是否存在、獲取/添加/刪除/更新索引別名、單條/批量插入、單條/批量更新、刪除數(shù)據(jù)、遞歸統(tǒng)計ES聚合的數(shù)據(jù)

這篇具有很好參考價值的文章主要介紹了Spring Boot Elasticsearch7.6.2實現(xiàn)創(chuàng)建索引、刪除索引、判斷索引是否存在、獲取/添加/刪除/更新索引別名、單條/批量插入、單條/批量更新、刪除數(shù)據(jù)、遞歸統(tǒng)計ES聚合的數(shù)據(jù)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Spring Boot Elasticsearch7.6.2實現(xiàn)創(chuàng)建索引、根據(jù)索引名刪除索引、根據(jù)索引名判斷索引是否存在、獲取索引對應(yīng)的別名、為索引添加別名、為索引刪除別名、為索引更換別名 舊的換為新的 不會判斷舊的是否存在、單條數(shù)據(jù)插入、批量插入、單條數(shù)據(jù)更新、根據(jù)maps批量更新、根據(jù)id刪除數(shù)據(jù)、根據(jù)id批量刪除數(shù)據(jù)、遞歸統(tǒng)計ES聚合的數(shù)據(jù)

注意:我的版本是elasticsearch7.6.2、spring-boot-starter-data-elasticsearch-2.5.6

引入依賴

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
	</dependency>
package com.mar.elasticsearchUtils;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Preconditions;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.document.Document;
import org.springframework.data.elasticsearch.core.index.AliasAction;
import org.springframework.data.elasticsearch.core.index.AliasActionParameters;
import org.springframework.data.elasticsearch.core.index.AliasActions;
import org.springframework.data.elasticsearch.core.index.AliasData;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;
import org.springframework.data.elasticsearch.core.query.StringQuery;
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.util.*;

@Component
@Slf4j
public class EsUtil {

    private static ElasticsearchRestTemplate elasticsearchRestTemplate;

    @Autowired
    public EsUtil(ElasticsearchRestTemplate elasticsearchRestTemplate) {
        EsUtil.elasticsearchRestTemplate = elasticsearchRestTemplate;
    }

    public static <T> boolean createIndex(Class<T> destinationClass, String indexName, String... withAliases) {
        if (ObjectUtil.isNull(destinationClass)) throw new RuntimeException("參數(shù)類不能為空");
        if (StrUtil.isEmpty(indexName)) throw new RuntimeException("參數(shù)名不能為空");
        if (withAliases == null || withAliases.length <= 0) throw new RuntimeException("索引別名至少有一個");
        for (String withAlias : withAliases) {
            if (!withAlias.endsWith("_search")) {
                throw new RuntimeException("索引別名只能以‘_search’結(jié)尾");
            }
        }
        return createIndex(destinationClass, indexName, 3, 2, Integer.MAX_VALUE, withAliases);
    }

    /**
     * 創(chuàng)建索引
     *
     * @param destinationClass 映射對象
     * @param withAliases      別名 必須如:"***_search"用來搜索
     * @author mar
     * @date 2021/10/28 14:54
     */
    public static <T> boolean createIndex(Class<T> destinationClass, String indexName, Integer shards, Integer replicas, Integer maxResult, String... withAliases) {
        if (ObjectUtil.isNull(destinationClass)) throw new RuntimeException("參數(shù)類不能為空");
        if (StrUtil.isEmpty(indexName)) throw new RuntimeException("參數(shù)名不能為空");
        if (withAliases == null || withAliases.length <= 0) throw new RuntimeException("索引別名至少有一個");
        for (String withAlias : withAliases) {
            if (!withAlias.endsWith("_search")) {
                throw new RuntimeException("索引別名只能以‘_search’結(jié)尾");
            }
        }

        IndexCoordinates of = IndexCoordinates.of(indexName);
        IndexOperations indexOperations = elasticsearchRestTemplate.indexOps(of);
        boolean exists = indexOperations.exists();
        if (exists) {
            indexOperations.delete();
        }
        Map<String, Object> settings = new HashMap<>();
        settings.put("index.number_of_shards", shards > 0 ? shards : 3);
        settings.put("index.number_of_replicas", replicas > 0 ? replicas : 2);
        settings.put("index.max_result_window", maxResult > 0 ? maxResult : Integer.MAX_VALUE);
        Document mapping = indexOperations.createMapping(destinationClass);
        indexOperations.create(settings, mapping);
        AliasAction.Add add = new AliasAction.Add(AliasActionParameters.builder()
                .withIndices(indexName).withAliases(withAliases).build());
        return indexOperations.alias(new AliasActions(add));
    }

    /**
     * 根據(jù)索引名刪除索引
     *
     * @param indexName 索引名稱
     * @author mar
     * @date 2021/10/28 16:29
     */
    public static boolean deleteIndexByName(String indexName) {
        return elasticsearchRestTemplate.indexOps(IndexCoordinates.of(indexName)).delete();
    }

    /**
     * 根據(jù)索引名判斷索引是否存在
     *
     * @param indexName
     * @return boolean
     * @author mar
     * @date 2021/11/29 16:39
     */
    public static boolean isExists(String indexName) {
        IndexCoordinates of = IndexCoordinates.of(indexName);
        return elasticsearchRestTemplate.indexOps(of).exists();
    }

    /**
     * 獲取索引對應(yīng)的別名
     */
    public static Set<String> getAlias(String index) {
        if (StrUtil.isEmpty(index)) throw new RuntimeException("索引名不能為空");
        Map<String, Set<AliasData>> aliasesForIndex = elasticsearchRestTemplate.indexOps(IndexCoordinates.of(index)).getAliasesForIndex();
        Set<String> set = new HashSet<>();
        aliasesForIndex.forEach((key, value) -> {
            value.forEach(data -> set.add(data.getAlias()));
        });
        return set;
    }

    /**
     * 為索引添加別名
     *
     * @param index 真實索引
     * @param alias 別名
     */
    public static boolean addAlias(String index, String... alias) {
        Preconditions.checkNotNull(index);
        Preconditions.checkNotNull(alias);
        final IndexOperations indexOps = elasticsearchRestTemplate.indexOps(IndexCoordinates.of(index));
        AliasActions aliasActions = new AliasActions(new AliasAction.Add(
                AliasActionParameters.builder().withIndices(index).withAliases(alias).build()
        ));
        return indexOps.alias(aliasActions);
    }

    /**
     * 為索引刪除別名
     *
     * @param index 真實索引
     * @param alias 別名
     */
    public static boolean delAlias(String index, String... alias) {
        Preconditions.checkNotNull(index);
        Preconditions.checkNotNull(alias);
        final IndexOperations indexOps = elasticsearchRestTemplate.indexOps(IndexCoordinates.of(index));
        AliasActions aliasActions = new AliasActions(new AliasAction.Remove(
                AliasActionParameters.builder().withIndices(index).withAliases(alias).build()
        ));
        return indexOps.alias(aliasActions);
    }

    /**
     * 為索引更換別名 舊的換為新的 不會判斷舊的是否存在
     *
     * @param index    真實索引
     * @param oldAlias 要刪除的別名
     * @param newAlias 要新增的別名
     */
    public static boolean replaceAlias(String index, String oldAlias, String newAlias) {
        Preconditions.checkNotNull(index);
        Preconditions.checkNotNull(oldAlias);
        Preconditions.checkNotNull(newAlias);
        final IndexOperations indexOps = elasticsearchRestTemplate.indexOps(IndexCoordinates.of(index));
        final AliasAction.Add add = new AliasAction.Add(AliasActionParameters.builder().withIndices(index).withAliases(newAlias).build());
        final AliasAction.Remove remove = new AliasAction.Remove(AliasActionParameters.builder().withIndices(index).withAliases(oldAlias).build());
        AliasActions aliasActions = new AliasActions(add, remove);
        return indexOps.alias(aliasActions);
    }

    /**
     * 單條數(shù)據(jù)插入
     *
     * @param t         待插入的數(shù)據(jù)實體
     * @param indexName 索引名
     * @return java.lang.String 返回文檔id
     */
    public static <T> void saveByEntity(T t, String indexName) {
        //這里的操作就是指定文檔id
        String id = getFieldId(t);
        IndexQuery build = new IndexQueryBuilder()
                .withId(id)
                .withObject(t).build();
        elasticsearchRestTemplate.index(build, IndexCoordinates.of(indexName));
    }

    public static <T> void saveBatchByEntities(Map<String, List<T>> map) {
        if (map != null && map.size() > 0)
            map.forEach((key, value) -> saveBatchByEntities(value, key));
    }

    /**
     * 批量插入
     *
     * @param sourceList 待插入的數(shù)據(jù)實體集合
     * @param indexName  索引名
     * @return java.util.List<java.lang.String> 返回idList
     */
    public static <T> void saveBatchByEntities(List<T> sourceList, String indexName) {
        List<IndexQuery> queryList = new ArrayList<>();
        for (T source : sourceList) {
            String id = getFieldId(source);
            IndexQuery build = new IndexQueryBuilder().withId(id).withObject(source).build();
            queryList.add(build);
        }
        elasticsearchRestTemplate.bulkIndex(queryList, IndexCoordinates.of(indexName));
    }

    /**
     * 單條數(shù)據(jù)更新
     *
     * @param entity    待更新的數(shù)據(jù)實體
     * @param indexName 索引名
     * @return void
     */
    public static <T> void updateByEntity(T entity, String indexName) {
        String id = getFieldId(entity);
        Map<String, String> map = null;
        try {
            map = BeanUtils.describe(entity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Document document = Document.from(map);
        document.setId(id);
        // 這里的UpdateQuery需要構(gòu)造一個Document對象,但是Document對象不能用實體類轉(zhuǎn)化而來
        //(可見Document的源碼,位于:org.springframework.data.elasticsearch.core.document
        // 包下),因此上面才會BeanUtils.describe(entity),將實體類轉(zhuǎn)化成一個map,由map轉(zhuǎn)化
        // 為Document對象。
        //不加默認(rèn)false。true表示更新時不存在就插入
        UpdateQuery build = UpdateQuery.builder(id)
                .withDocAsUpsert(false)
                .withDocument(document)
                .build();
        elasticsearchRestTemplate.update(build, IndexCoordinates.of(indexName));
    }

    /**
     * 根據(jù)maps批量更新
     *
     * @param list      待更新的數(shù)據(jù)實體集合
     * @param indexName 索引名
     * @return void
     * @author Innocence
     */
    public static <T> void updateByMaps(List<T> list, String indexName) {
        List<Map<String, Object>> maps = listToMap(list);
        List<UpdateQuery> updateQueries = new ArrayList<>();
        maps.forEach(item -> {
            Document document = Document.from(item);
            document.setId(String.valueOf(item.get("id")));
            UpdateQuery build = UpdateQuery.builder(document.getId())
                    .withDocument(document)
                    .build();
            updateQueries.add(build);
        });
        elasticsearchRestTemplate.bulkUpdate(updateQueries, IndexCoordinates.of(indexName));
    }

    /**
     * 根據(jù)id刪除數(shù)據(jù)
     *
     * @param id
     * @param indexName 索引名
     * @return java.lang.String 被刪除的id
     */
    public static String deleteById(String id, String indexName) {
        return elasticsearchRestTemplate.delete(id, IndexCoordinates.of(indexName));
    }

    /**
     * 根據(jù)id批量刪除數(shù)據(jù)
     *
     * @param docIdName 文檔id字段名,如我們上面設(shè)置的文檔id的字段名為“id”
     * @param ids       需要刪除的id集合
     * @param indexName 索引名稱
     * @return void
     */
    public static void deleteByIds(String docIdName, List<String> ids, String indexName) {
        StringQuery query = new StringQuery(QueryBuilders.termsQuery(docIdName, ids).toString());
        elasticsearchRestTemplate.delete(query, null, IndexCoordinates.of(indexName));
    }

    /**
     * 遞歸統(tǒng)計ES聚合的數(shù)據(jù)
     */
    @SneakyThrows
    public static <T> Map<T, Long> count(Aggregations aggregations, Class<T> destinationClass) throws NoSuchFieldException, IllegalAccessException {
        //返回值封裝
        Map<T, Long> map = new HashMap<>();
        //將t轉(zhuǎn)為JSONObject防止數(shù)據(jù)值被覆蓋
        Map<JSONObject, Long> jsonMap = new HashMap<>();
        for (Aggregation aggregation : aggregations) {
            Terms terms = (Terms) aggregation;
            List<? extends Terms.Bucket> buckets = terms.getBuckets();
            if (buckets.size() > 0) {
                // 如果內(nèi)部還有aggregation,就繼續(xù)往下走,不能統(tǒng)計
                for (Terms.Bucket bucket : buckets) {
                    T t = destinationClass.newInstance();
                    Field declaredField = t.getClass().getDeclaredField(aggregation.getName());
                    declaredField.setAccessible(true);
                    declaredField.set(t, bucket.getKeyAsString());
                    Aggregations aggregationsInners = bucket.getAggregations();
                    if (aggregationsInners == null || aggregationsInners.asList().size() == 0) {
                        jsonMap.put((JSONObject) JSONObject.toJSON(t), bucket.getDocCount());
                    } else {
                        countIterator(aggregationsInners, jsonMap, t);
                    }
                }
            }
        }
        for (Map.Entry<JSONObject, Long> entry : jsonMap.entrySet()) {
            //將json對象轉(zhuǎn)換為java對象
            T vo = JSONObject.toJavaObject(entry.getKey(), destinationClass);
            map.put(vo, entry.getValue());
        }
        return map;
    }

    /**
     * 內(nèi)部遞歸方法
     */
    private static <T> void countIterator(Aggregations aggregations, Map<JSONObject, Long> jsonMap, T destinationClass) throws NoSuchFieldException, IllegalAccessException {
        for (Aggregation aggregation : aggregations) {
            Terms terms = (Terms) aggregation;
            List<? extends Terms.Bucket> buckets = terms.getBuckets();
            if (buckets.size() > 0) {
                // 如果內(nèi)部還有aggregation,就繼續(xù)往下走,不能統(tǒng)計
                for (Terms.Bucket bucket : buckets) {
                    Field declaredField = destinationClass.getClass().getDeclaredField(aggregation.getName());
                    declaredField.setAccessible(true);
                    declaredField.set(destinationClass, bucket.getKeyAsString());
                    Aggregations aggregationsInners = bucket.getAggregations();
                    if (aggregationsInners == null || aggregationsInners.asList().size() == 0) {
                        jsonMap.put((JSONObject) JSONObject.toJSON(destinationClass), bucket.getDocCount());
                    } else {
                        countIterator(aggregationsInners, jsonMap, destinationClass);
                    }
                }
            }
        }
    }

    /**
     * 解析出id值
     *
     * @param t 泛型
     * @return java.lang.String
     * @author mar
     * @date 2021/11/1 16:25
     */
    public static <T> String getFieldId(T t) {
        String primaryKey = null;
        Field[] fields = t.getClass().getDeclaredFields();
        Field field;
        for (int i = 0; i < fields.length; i++) {
            fields[i].setAccessible(true);
        }
        for (int i = 1; i < fields.length; i++) {
            try {
                field = t.getClass().getDeclaredField(fields[i].getName());
                Id id = field.getAnnotation(Id.class);
                if (id != null) {
                    //打開私有訪問
                    field.setAccessible(true);
                    primaryKey = (String) field.get(t);
                }
            } catch (NoSuchFieldException | IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return primaryKey;
    }

    /**
     * 把一個字符串的第一個字母大寫、效率是最高的
     *
     * @param fieldName
     * @return java.lang.String
     * @author mar
     * @date 2021/11/2 15:49
     */
    public static String getMethodName(String fieldName) {
        byte[] items = fieldName.getBytes();
        items[0] = (byte) ((char) items[0] - 'a' + 'A');
        return new String(items);
    }

    /**
     * 用于把List<Object>轉(zhuǎn)換成Map<String,Object>形式,便于更新操作
     *
     * @param list 集合
     * @return 返回對象
     * @author mar
     */
    public static <T> List<Map<String, Object>> listToMap(List<T> list) {
        List<Map<String, Object>> maps = new ArrayList<>();
        try {
            for (T t : list) {
                Map<String, Object> map = BeanUtil.beanToMap(t);
                maps.add(map);
            }
            return maps;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}

有時候你可能需要查詢大批量的數(shù)據(jù),建議加上下面配置文件文章來源地址http://www.zghlxwxcb.cn/news/detail-643814.html

import org.elasticsearch.client.HeapBufferedAsyncResponseConsumer;
import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
import org.elasticsearch.client.RequestOptions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

@Configuration
public class EsConfig {

    @Value("${es.data.size:}")
    private Integer dataSize;

    @Bean
    public void setRequestOptions() throws NoSuchFieldException, IllegalAccessException {
        //設(shè)置es查詢buffer大小
        RequestOptions requestOptions = RequestOptions.DEFAULT;
        Class<? extends RequestOptions> reqClass = requestOptions.getClass();
        Field reqField = reqClass.getDeclaredField("httpAsyncResponseConsumerFactory");
        reqField.setAccessible(true);
        //去除final
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(reqField, reqField.getModifiers() & ~Modifier.FINAL);

        //設(shè)置默認(rèn)的工廠
        reqField.set(requestOptions, (HttpAsyncResponseConsumerFactory) () -> {
            Integer size = new Integer( 5 * 100);
            if(dataSize!=null){
                size = dataSize;
            }
            //500MB
            return new HeapBufferedAsyncResponseConsumer( size * 1024 * 1024);
        });
    }
}

到了這里,關(guān)于Spring Boot Elasticsearch7.6.2實現(xiàn)創(chuàng)建索引、刪除索引、判斷索引是否存在、獲取/添加/刪除/更新索引別名、單條/批量插入、單條/批量更新、刪除數(shù)據(jù)、遞歸統(tǒng)計ES聚合的數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(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īng)查實,立即刪除!

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

相關(guān)文章

  • Elasticsearch7.x——spring-boot-starter-data-elasticsearch詳解

    Elasticsearch7.x——spring-boot-starter-data-elasticsearch詳解

    Spring Data Elasticsearch是Spring Data項目下的一個子模塊。 查看 Spring Data的官網(wǎng):http://projects.spring.io/spring-data/ Spring Data 的使命是給各種數(shù)據(jù)訪問提供統(tǒng)一的編程接口,不管是關(guān)系型數(shù)據(jù)庫(如MySQL),還是非關(guān)系數(shù)據(jù)庫(如Redis),或者類似Elasticsearch這樣的索引數(shù)據(jù)庫。從而簡化

    2024年02月03日
    瀏覽(19)
  • spring elasticsearch:啟動項目時自動創(chuàng)建索引

    在springboot整合spring data elasticsearch項目中,當(dāng)索引數(shù)量較多,mapping結(jié)構(gòu)較為復(fù)雜時,我們常常希望啟動項目時能夠自動創(chuàng)建索引及mapping,這樣就不用再到各個環(huán)境中創(chuàng)建索引了 所以今天咱們就來看看如何自動創(chuàng)建索引 如股票使用的是spring data elasticsearch包,其 @Document 注解中

    2024年02月11日
    瀏覽(22)
  • spring data elasticsearch:啟動項目時自動創(chuàng)建索引

    spring data elasticsearch:啟動項目時自動創(chuàng)建索引

    在springboot整合spring data elasticsearch項目中,當(dāng)索引數(shù)量較多,mapping結(jié)構(gòu)較為復(fù)雜時,我們常常希望啟動項目時能夠自動創(chuàng)建索引及mapping,這樣就不用再到各個環(huán)境中創(chuàng)建索引了 所以今天咱們就來看看如何自動創(chuàng)建索引 我們已經(jīng)在實體類中聲明了索引數(shù)據(jù)結(jié)構(gòu)了,只需要識別

    2024年02月05日
    瀏覽(18)
  • SpringBoot+Elasticsearch按日期實現(xiàn)動態(tài)創(chuàng)建索引(分表)

    SpringBoot+Elasticsearch按日期實現(xiàn)動態(tài)創(chuàng)建索引(分表)

    ?? @ 作者: 一恍過去 ?? @ 主頁: https://blog.csdn.net/zhuocailing3390 ?? @ 社區(qū): Java技術(shù)棧交流 ?? @ 主題: SpringBoot+Elasticsearch按日期實現(xiàn)動態(tài)創(chuàng)建索引(分表) ?? @ 創(chuàng)作時間: 2023年02月19日 SpringBoot+Elasticsearch,通過 @Document 注解,利用EL表達式指定到配置文件,實現(xiàn)動態(tài)生成

    2023年04月08日
    瀏覽(19)
  • Spring Boot:實現(xiàn)MyBatis動態(tài)創(chuàng)建表

    在有些應(yīng)用場景中,我們會有需要動態(tài)創(chuàng)建和操作表的需求。 比如因為單表數(shù)據(jù)存儲量太大而采取分表存儲的情況,又或者是按日期生成日志表存儲系統(tǒng)日志等等。這個時候就需要我們動態(tài)的生成和操作數(shù)據(jù)庫表了。 而我們都知道,以往我們使用MyBatis是需要提前生成包括

    2024年02月04日
    瀏覽(21)
  • 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)
  • [Spring Boot]12 ElasticSearch實現(xiàn)分詞搜索功能

    [Spring Boot]12 ElasticSearch實現(xiàn)分詞搜索功能

    我們在使用搜索功能的時候,有時,為了使搜索的結(jié)果更多更廣,比如搜索字符串“領(lǐng)導(dǎo)力”,希望有這些組合的結(jié)果(領(lǐng)導(dǎo)力、領(lǐng)導(dǎo)、領(lǐng)、導(dǎo)、力)都要能夠全部展示出來。 這里我們引入ElasticSearch結(jié)合分詞插件,來實現(xiàn)這樣的搜索功能。 比如:一款app需要對“課程”進行

    2024年02月03日
    瀏覽(21)
  • [Java Framework] [ELK] Spring 整合ES (ElasticSearch7.15.x +)

    [Java Framework] [ELK] Spring 整合ES (ElasticSearch7.15.x +)

    ElasticSearch7.15.x 版本后,廢棄了高級Rest客戶端的功能 2.1 配置文件 2.2 配置類 3.1 索引的相關(guān)操作 3.2 實體映射相關(guān)操作 3.2.1 創(chuàng)建實體類 3.2.2 Doc實體操作API 3.3 聚合相關(guān)操作 3.3.1 創(chuàng)建實體類 3.3.2 創(chuàng)建操作類 [1] Elasticsearch Clients [2] Elasticsearch Clients - Aggregations

    2023年04月08日
    瀏覽(25)
  • Spring Boot進階(19):探索ElasticSearch:如何利用Spring Boot輕松實現(xiàn)高效數(shù)據(jù)搜索與分析

    Spring Boot進階(19):探索ElasticSearch:如何利用Spring Boot輕松實現(xiàn)高效數(shù)據(jù)搜索與分析

    ????????ElasticSearch是一款基于Lucene的開源搜索引擎,具有高效、可擴展、分布式的特點,可用于全文搜索、日志分析、數(shù)據(jù)挖掘等場景。Spring Boot作為目前最流行的微服務(wù)框架之一,也提供了對ElasticSearch的支持。本篇文章將介紹如何在Spring Boot項目中整合ElasticSearch,并展

    2024年02月11日
    瀏覽(23)
  • Spring Boot 中使用 Elasticsearch 實現(xiàn)商品搜索功能

    作者:禪與計算機程序設(shè)計藝術(shù) Elasticsearch 是開源分布式搜索引擎,它提供了一個分布式、RESTful 搜索接口?;?Elasticsearch 的搜索方案能夠輕松應(yīng)對復(fù)雜的檢索場景并提供高擴展性。在 Web 應(yīng)用中,Elasticsearch 可以作為后臺服務(wù)支持用戶的檢索需求。本文將會教你如何使用

    2024年02月06日
    瀏覽(18)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包