springboot整合ElasticSearch(工具类、测试调用)

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: springboot整合ElasticSearch(工具类、测试调用)

1、引入依赖

<properties>
        <java.version>1.8</java.version>
        <log4j2.version>2.17.0</log4j2.version>
        <axis1.version>1.4</axis1.version>
        <elasticsearch.version>7.3.2</elasticsearch.version>
</properties>
<!-- elasticsearch -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>

2、配置文件配置

package com.sinochem.center.elasticsearch.config;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @author : jiagang
 * @date : Created in 2022/3/25 15:21
 */
@Configuration
public class ElasticSearchConfig {
    // 注册 rest高级客户端
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("localhost",9201,"http")
                )
        );
        return client;
    }
}

3、es API工具类实现

package com.sinochem.center.elasticsearch.service.base;
import com.alibaba.fastjson.JSON;
import com.sinochem.center.elasticsearch.entity.EsPage;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;
/**
 * elasticSearch api方法
 * @author : jiagang
 * @date : Created in 2022/3/28 10:21
 */
@Slf4j
@Component
public class BaseElasticsearchService {
    @Autowired
    private RestHighLevelClient restHighLevelClient;
    /**
     * 默认类型
     */
    public static final String DEFAULT_TYPE = "_doc";
    /**
     * set方法前缀
     */
    public static final String SET_METHOD_PREFIX = "set";
    /**
     * 返回状态-CREATED
     */
    public static final String RESPONSE_STATUS_CREATED = "CREATED";
    /**
     * 返回状态-OK
     */
    public static final String RESPONSE_STATUS_OK = "OK";
    /**
     * 返回状态-NOT_FOUND
     */
    public static final String RESPONSE_STATUS_NOT_FOUND = "NOT_FOUND";
    /**
     * 需要过滤的文档数据
     */
    public static final String[] IGNORE_KEY = {"@version","type"};
    /**
     * 超时时间 1s
     */
    public static final TimeValue TIME_VALUE_SECONDS = TimeValue.timeValueSeconds(1);
    /**
     * @PostContruct是spring框架的注解 spring容器初始化的时候执行该方法
     */
//    @PostConstruct
//    public void init() {
//        client = this.transportClient;
//        System.out.println("client*************" + client);
//    }
    /**
     * 创建索引
     * @param index
     * @return
     */
    public  boolean createIndex(String index) throws IOException {
        if (!isIndexExist(index)) {
            log.info("Index is not exits!");
        }
        CreateIndexRequest indexRequest = new CreateIndexRequest(index);
        CreateIndexResponse response = restHighLevelClient.indices().create(indexRequest, RequestOptions.DEFAULT);
        log.info("执行建立成功?" + response.isAcknowledged());
        return response.isAcknowledged();
    }
    /**
     * 删除索引
     *
     * @param index
     * @return
     */
    public boolean deleteIndex(String index) throws IOException {
        if (!isIndexExist(index)) {
            log.info("Index is not exits!");
        }
        DeleteIndexRequest request = new DeleteIndexRequest("mdx_index");
        AcknowledgedResponse response = restHighLevelClient.indices().delete(request, RequestOptions.DEFAULT);
        if (response.isAcknowledged()) {
            log.info("delete index " + index + "  successfully!");
        } else {
            log.info("Fail to delete index " + index);
        }
        return response.isAcknowledged();
    }
    /**
     * 判断索引是否存在
     *
     * @param index
     * @return
     */
    public  boolean isIndexExist(String index) throws IOException {
        GetIndexRequest request = new GetIndexRequest(index);
        boolean exists = restHighLevelClient.indices().exists(request, RequestOptions.DEFAULT);
        if (exists) {
            log.info("Index [" + index + "] is exist!");
        } else {
            log.info("Index [" + index + "] is not exist!");
        }
        return exists;
    }
    /**
     * 指定文档是否存在
     *
     * @param index 索引
     * @param id    文档id
     */
    public boolean isExists(String index, String id) {
        return isExists(index, DEFAULT_TYPE, id);
    }
    /**
     * 指定文档是否存在
     *
     * @param index 索引
     * @param type  类型
     * @param id    文档id
     */
    public boolean isExists(String index, String type, String id) {
        GetRequest request = new GetRequest(index, type, id);
        try {
            GetResponse response = restHighLevelClient.get(request, RequestOptions.DEFAULT);
            return response.isExists();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    /**
     * 根据id查询文档
     * @param index 索引
     * @param id    文档id
     * @param clazz 转换目标Class对象
     * @return 对象
     */
    public <T> T selectDocumentById(String index, String id, Class<T> clazz) {
        return selectDocumentById(index, DEFAULT_TYPE, id, clazz);
    }
    /**
     * 根据id查询文档
     *
     * @param index 索引
     * @param type  类型
     * @param id    文档id
     * @param clazz 转换目标Class对象
     * @return 对象
     */
    public <T> T selectDocumentById(String index, String type, String id, Class<T> clazz) {
        try {
            type = type == null || type.equals("") ? DEFAULT_TYPE : type;
            GetRequest request = new GetRequest(index, type, id);
            GetResponse response = restHighLevelClient.get(request, RequestOptions.DEFAULT);
            if (response.isExists()) {
                Map<String, Object> sourceAsMap = response.getSourceAsMap();
                return dealObject(sourceAsMap, clazz);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     *(筛选条件)获取数据集合
     * 如果使用排序则 sourceBuilder.sort("name",SortOrder.DESC)
     * 如果使用高亮则 :
     * HighlightBuilder highlightBuilder = new HighlightBuilder();
     * highlightBuilder.field("");
     * sourceBuilder.highlighter(highlightBuilder);
     * @param index         索引
     * @param sourceBuilder 请求条件
     * @param clazz         转换目标Class对象
     */
    public <T> List<T> selectDocumentList(String index, SearchSourceBuilder sourceBuilder, Class<T> clazz) {
        try {
            SearchRequest request = new SearchRequest(index);
            if (sourceBuilder != null) {
                // 返回实际命中数
                sourceBuilder.trackTotalHits(true);
                request.source(sourceBuilder);
            }
            SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
            if (response.getHits() != null) {
                List<T> list = new ArrayList<>();
                SearchHit[] hits = response.getHits().getHits();
                for (SearchHit documentFields : hits) {
                    Map<String, Object> sourceAsMap = documentFields.getSourceAsMap();
                    // 高亮结果集特殊处理 -- 高亮信息会显示在highlight标签下  需要将实体类中的字段进行替换
                    Map<String, Object> map = this.highlightBuilderHandle(sourceAsMap, documentFields);
                    list.add(dealObject(map, clazz));
                }
                return list;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 新增/修改文档信息
     * @param index 索引
     * @param data  数据
     */
    public String insertDocument(String index, Object data) {
        try {
            String id = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
            IndexRequest request = new IndexRequest(index);
            request.timeout(TIME_VALUE_SECONDS);
            request.id(id); // 文档id
            request.source(JSON.toJSONString(data), XContentType.JSON);
            IndexResponse response = restHighLevelClient.index(request, RequestOptions.DEFAULT);
            log.info("insertDocument response status:{},id:{}", response.status().getStatus(), response.getId());
            String status = response.status().toString();
            if (RESPONSE_STATUS_CREATED.equals(status) || RESPONSE_STATUS_OK.equals(status)) {
                return response.getId();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    /**
     * 删除文档信息
     *
     * @param index 索引
     * @param id    文档id
     */
    public boolean deleteDocument(String index, String id) {
        try {
            DeleteRequest request = new DeleteRequest(index, id);
            DeleteResponse response = restHighLevelClient.delete(request, RequestOptions.DEFAULT);
            log.info("deleteDocument response status:{},id:{}", response.status().getStatus(), response.getId());
            String status = response.status().toString();
            if (RESPONSE_STATUS_OK.equals(status)) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    /**
     * 更新文档信息
     *
     * @param index 索引
     * @param id    文档id
     * @param data  数据
     */
    public boolean updateDocument(String index, String id, Object data) {
        try {
            UpdateRequest request = new UpdateRequest(index, id);
            request.doc(data, XContentType.JSON);
            UpdateResponse response = restHighLevelClient.update(request, RequestOptions.DEFAULT);
            log.info("updateDocument response status:{},id:{}", response.status().getStatus(), response.getId());
            String status = response.status().toString();
            if (RESPONSE_STATUS_OK.equals(status)) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    /**
     * 批量操作(新增)
     * @param index    索引
     * @param opType   操作类型 PATCH_OP_TYPE_*
     * @param dataList 数据集 新增修改需要传递
     * @param timeout  超时时间 单位为秒
     */
    public boolean patch(String index, String opType, List<Object> dataList, long timeout) {
        try {
            BulkRequest bulkRequest = new BulkRequest();
            bulkRequest.timeout(TimeValue.timeValueSeconds(timeout));
            if (dataList != null && dataList.size() > 0) {
                if ("insert".equals(opType)) {
                    for (Object obj : dataList) {
                        bulkRequest.add(
                                new IndexRequest(index)
                                        .source(JSON.toJSONString(obj), XContentType.JSON)
                        );
                    }
                }
                BulkResponse response = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
                if (!response.hasFailures()) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    /**
     *(筛选条件)获取数据集合分页
     * 如果使用排序则 sourceBuilder.sort("name",SortOrder.DESC)
     * 如果使用高亮则 :
     * HighlightBuilder highlightBuilder = new HighlightBuilder();
     * highlightBuilder.field("");
     * sourceBuilder.highlighter(highlightBuilder);
     * @param index         索引
     * @param sourceBuilder 请求条件
     * @param clazz         转换目标Class对象
     */
    public <T> EsPage selectDocumentPage(String index,SearchSourceBuilder sourceBuilder, int startPage, int pageSize , Class<T> clazz) {
        try {
            SearchRequest request = new SearchRequest(index);
            if (sourceBuilder != null) {
                // 返回实际命中数
                sourceBuilder.from(startPage);
                sourceBuilder.size(pageSize);
                sourceBuilder.explain(true);
                sourceBuilder.trackTotalHits(true);
                request.source(sourceBuilder);
            }
            SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
            if (response.getHits() != null) {
                long totalHits = Arrays.stream(response.getHits().getHits()).count();
                long length = response.getHits().getHits().length;
                List<T> list = new ArrayList<>();
                SearchHit[] hits = response.getHits().getHits();
                for (SearchHit documentFields : hits) {
                    Map<String, Object> sourceAsMap = documentFields.getSourceAsMap();
                    // 高亮结果集特殊处理 -- 高亮信息会显示在highlight标签下  需要将实体类中的字段进行替换
                    Map<String, Object> map = this.highlightBuilderHandle(sourceAsMap, documentFields);
                    list.add(dealObject(map, clazz));
                }
                return new EsPage(startPage, pageSize, (int) totalHits, list);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 高亮结果集 特殊处理
     * @param sourceAsMap
     * @param documentFields
     */
    private Map<String, Object> highlightBuilderHandle(Map<String, Object> sourceAsMap,SearchHit documentFields){
        // 将高亮的字段替换到sourceAsMap中
        Map<String, HighlightField> fieldMap = documentFields.getHighlightFields();
        Set<Map.Entry<String, Object>> entries = sourceAsMap.entrySet();
        entries.forEach(source -> {
            if (fieldMap.containsKey(source.getKey())){
                Text[] fragments = fieldMap.get(source.getKey()).getFragments();
                if (fragments != null){
                    for (Text str : fragments) {
                        source.setValue(str.string());
                    }
                }
            }
        });
        return sourceAsMap;
    }
//    /**
//     * 高亮结果集 特殊处理
//     *
//     * @param searchResponse
//     * @param highlightField
//     */
//    private List<Map<String, Object>> setSearchResponse(SearchResponse searchResponse, String highlightField) {
//        List<Map<String, Object>> sourceList = new ArrayList<>();
//        StringBuffer stringBuffer = new StringBuffer();
//
//        for (SearchHit searchHit : searchResponse.getHits().getHits()) {
//            searchHit.getSourceAsMap().put("id", searchHit.getId());
//
//            if (StringUtils.isNotEmpty(highlightField)) {
//
//                System.out.println("遍历 高亮结果集,覆盖 正常结果集" + searchHit.getSourceAsMap());
//                Text[] text = searchHit.getHighlightFields().get(highlightField).getFragments();
//
//                if (text != null) {
//                    for (Text str : text) {
//                        stringBuffer.append(str.string());
//                    }
//                    //遍历 高亮结果集,覆盖 正常结果集
//                    searchHit.getSourceAsMap().put(highlightField, stringBuffer.toString());
//                }
//            }
//            sourceList.add(searchHit.getSourceAsMap());
//        }
//        return sourceList;
//    }
    /**
     * 将文档数据转化为指定对象
     *
     * @param sourceAsMap 文档数据
     * @param clazz       转换目标Class对象
     * @return
     */
    private static <T> T dealObject(Map<String, Object> sourceAsMap, Class<T> clazz) {
        try {
            ignoreSource(sourceAsMap);
            Iterator<String> keyIterator = sourceAsMap.keySet().iterator();
            T t = clazz.newInstance();
            while (keyIterator.hasNext()) {
                String key = keyIterator.next();
                String replaceKey = key.replaceFirst(key.substring(0, 1), key.substring(0, 1).toUpperCase());
                Method method = null;
                try {
                    method = clazz.getMethod(SET_METHOD_PREFIX + replaceKey, sourceAsMap.get(key).getClass());
                }catch (NoSuchMethodException e) {
                    continue;
                }
                method.invoke(t, sourceAsMap.get(key));
            }
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 剔除指定文档数据,减少不必要的循环
     *
     * @param map 文档数据
     */
    private static void ignoreSource(Map<String, Object> map) {
        for (String key : IGNORE_KEY) {
            map.remove(key);
        }
    }
}

4、单元测试类

package com.sinochem.center;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sinochem.center.elasticsearch.entity.EsPage;
import com.sinochem.center.elasticsearch.service.base.BaseElasticsearchService;
import com.sinochem.center.entity.TaskCenter;
import com.sinochem.center.mapper.db1.TaskCenterMapper;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
 * @author : jiagang
 * @date : Created in 2022/3/28 15:40
 */
@SpringBootTest
@Slf4j
public class ElasticSearchDataTest {
    @Autowired
    private BaseElasticsearchService elasticsearchService;
    @Autowired
    private TaskCenterMapper taskCenterMapper;
    /**
     * 创建索引
     * @throws IOException
     */
    @Test
    public void addIndex() throws IOException {
        boolean b = elasticsearchService.createIndex("hxy_task");
        System.out.println(b);
    }
    /**
     * 新增/修改文档信息
     * @throws IOException
     */
    @Test
    public void insertDocument() throws IOException {
        TaskCenter taskCenter = taskCenterMapper.selectById(100874);
        String id = elasticsearchService.insertDocument("hxy_task", taskCenter);
        System.out.println(id);
    }
    /**
     * 根据id查询文档
     * @throws IOException
     */
    @Test
    public void selectDocumentById() throws IOException {
        TaskCenter taskCenter = elasticsearchService.selectDocumentById("hxy_task", "4B0895F2B2254406B1A83E689E624D41", TaskCenter.class);
        System.out.println(taskCenter);
    }
    /**
     * 批量操作(新增)
     * @throws IOException
     */
    @Test
    public void patch() throws IOException {
        QueryWrapper<TaskCenter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_code","hhj");
        List<TaskCenter> taskCenterList = taskCenterMapper.selectList(queryWrapper);
        List<Object> objects = new ArrayList<>();
        objects.addAll(taskCenterList);
        boolean b = elasticsearchService.patch("hxy_task","insert",objects,5);
        System.out.println(b);
    }
    /**
     * (筛选条件)获取数据集合
     * @throws IOException
     */
    @Test
    public void selectDocumentList() throws IOException {
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.sort("createTime", SortOrder.DESC);
        HighlightBuilder highlightBuilder = new HighlightBuilder();
        highlightBuilder.preTags("<font color=\"red\">");
        highlightBuilder.postTags("</font>");
        highlightBuilder.highlighterType("unified");
        highlightBuilder.field("taskItemTitle");
        highlightBuilder.field("orgName");
        highlightBuilder.requireFieldMatch(false);//多次段高亮需要设置为false
        searchSourceBuilder.highlighter(highlightBuilder);
        QueryBuilder qb = QueryBuilders.matchQuery("taskItemTitle","中化塑料有限公司");
        searchSourceBuilder.query(qb);
        List<TaskCenter> taskCenterList = elasticsearchService.selectDocumentList("hxy_task", searchSourceBuilder, TaskCenter.class);
        System.out.println(taskCenterList);
    }
    /**
     * (筛选条件)获取数据集合分页
     * @throws IOException
     */
    @Test
    public void selectDocumentPage() throws IOException {
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.sort("createTime", SortOrder.DESC);
        HighlightBuilder highlightBuilder = new HighlightBuilder();
        highlightBuilder.preTags("<font color=\"red\">");
        highlightBuilder.postTags("</font>");
        highlightBuilder.highlighterType("unified");
        highlightBuilder.field("taskItemTitle");
        highlightBuilder.field("orgName");
        highlightBuilder.requireFieldMatch(false);//多次段高亮需要设置为false
        searchSourceBuilder.highlighter(highlightBuilder);
        QueryBuilder qb = QueryBuilders.matchQuery("taskItemTitle","中化塑料有限公司");
        searchSourceBuilder.query(qb);
        EsPage page = elasticsearchService.selectDocumentPage("hxy_task", searchSourceBuilder, 1, 5, TaskCenter.class);
        System.out.println(page);
    }
}

注:工具类参考 https://blog.csdn.net/qq_43077369/article/details/116227967 ,在其之上新增了查询高亮结果集特殊处理,分页查询以及单元测试的调用等。

文章持续更新,可以关注下方公众号或者微信搜一搜「 最后一支迷迭香 」第一时间阅读,获取更完整的链路资料。

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
20天前
|
Java 测试技术 开发者
必学!Spring Boot 单元测试、Mock 与 TestContainer 的高效使用技巧
【10月更文挑战第18天】 在现代软件开发中,单元测试是保证代码质量的重要手段。Spring Boot提供了强大的测试支持,使得编写和运行测试变得更加简单和高效。本文将深入探讨Spring Boot的单元测试、Mock技术以及TestContainer的高效使用技巧,帮助开发者提升测试效率和代码质量。
112 2
|
1月前
|
JSON Java 网络架构
elasticsearch学习四:使用springboot整合 rest 进行搭建elasticsearch服务
这篇文章介绍了如何使用Spring Boot整合REST方式来搭建和操作Elasticsearch服务。
114 4
elasticsearch学习四:使用springboot整合 rest 进行搭建elasticsearch服务
|
15天前
|
JSON Java API
springboot集成ElasticSearch使用completion实现补全功能
springboot集成ElasticSearch使用completion实现补全功能
20 1
|
1月前
|
自然语言处理 搜索推荐 关系型数据库
elasticsearch学习六:学习 全文搜索引擎 elasticsearch的语法,使用kibana进行模拟测试(持续更新学习)
这篇文章是关于Elasticsearch全文搜索引擎的学习指南,涵盖了基本概念、命令风格、索引操作、分词器使用,以及数据的增加、修改、删除和查询等操作。
17 0
elasticsearch学习六:学习 全文搜索引擎 elasticsearch的语法,使用kibana进行模拟测试(持续更新学习)
|
1月前
|
Web App开发 JavaScript Java
elasticsearch学习五:springboot整合 rest 操作elasticsearch的 实际案例操作,编写搜索的前后端,爬取京东数据到elasticsearch中。
这篇文章是关于如何使用Spring Boot整合Elasticsearch,并通过REST客户端操作Elasticsearch,实现一个简单的搜索前后端,以及如何爬取京东数据到Elasticsearch的案例教程。
168 0
elasticsearch学习五:springboot整合 rest 操作elasticsearch的 实际案例操作,编写搜索的前后端,爬取京东数据到elasticsearch中。
|
30天前
|
监控 Java Maven
springboot学习二:springboot 初创建 web 项目、修改banner、热部署插件、切换运行环境、springboot参数配置,打包项目并测试成功
这篇文章介绍了如何快速创建Spring Boot项目,包括项目的初始化、结构、打包部署、修改启动Banner、热部署、环境切换和参数配置等基础操作。
111 0
|
6月前
|
Java
【极问系列】springBoot集成elasticsearch出现Unable to parse response body for Response
【极问系列】springBoot集成elasticsearch出现Unable to parse response body for Response
841 2
|
NoSQL Java 测试技术
SpringBoot集成ElasticSearch在启动时报availableProcessors is already set to [8], rejecting [8]
SpringBoot集成ElasticSearch在启动时报availableProcessors is already set to [8], rejecting [8]
137 0
|
SQL 自然语言处理 Java
springboot 2.0集成elasticsearch 7.6.2 (集群)关键字高亮显示(上)
springboot 2.0集成elasticsearch 7.6.2 (集群)关键字高亮显示
200 0
springboot 2.0集成elasticsearch 7.6.2 (集群)关键字高亮显示(上)
|
Java 索引
springboot 2.0集成elasticsearch 7.6.2(集群)(下)
springboot 2.0集成elasticsearch 7.6.2(集群)(下)
346 0
springboot 2.0集成elasticsearch 7.6.2(集群)(下)