ES的使用示例

1.安装

ES的安装对springboot的版本配置要求很高,需要根据如下的目录下载对应的版本。
es和springboot的版本匹配
查看自己项目所使用的springboot和spring的版本,对应下载文件。
项目spring版本
下载链接地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-17-3

下载完成解压,根据:https://www.ngui.cc/el/3053538.html?action=onClick
进行安装和配置中文解析词
es安装
访问是否启动成功:http://localhost:9200/
访问成功

2.增加中文解析包

配置中文解析词
下载链接:https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.17.3
在这里插入图片描述
重启ES。
如果增加新词,需进行配置
在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict">custom.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<entry key="remote_ext_dict">words_location</entry>
<!--用户可以在这里配置远程扩展停止词字典-->
<entry key="remote_ext_stopwords">words_location</entry>
</properties>

3.项目使用

1.引入依赖

<!-- 引入ES依赖 --><dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.17.3</version></dependency>

2.d.读数据 BoolQueryBuilder的should/must,对应mysql的or/and

创建索引(也就是sql里对应的表)

{
  "settings":{
    "number_of_shards":3,
    "number_of_replicas":2
  },
  "mappings":{
    "properties":{
      "id":{"type":"long"},
      "projectId":{"type":"text"},
      "title":{"type":"text","analyzer":"ik_smart"},
      "excerpt":{"type":"text","analyzer":"ik_max_word"},
      "creatTime": {
                    "type": "date",
                    "store": true,
                    "format": "yyyy-MM-dd HH:mm:ss"
                },
        "icon": {"type": "keyword","index": false},
        "tags": {"type": "keyword","index": false},
        "module": {"type": "keyword","index": false}
    }
  }
 
}

创建数据结构示例

填充内容

{
	"id": 6430,
	"projectId": "flash_qg005ewi",
	"title": "Twitter (X) 获得添加加密货币支付所需的许可",
	"excerpt": "PANews 8月29日消息,据Cryptotimes报道.",
	"icon": "https://uscloudmedia.s3.us-west-2.amazonaws.com/dhunter/icon/pannews.png",              
	"createTime": "2023-08-30 23:30:00",
	"module": 1,
	"tags": ""
}

postman插入数据示例

全文查询

POST /schools/_search

{
   "query":{
      "match_all":{}
   }
}

模糊查询

{
   "query":{
      "multi_match" : {
         "query": "SEC",
         "fields": [ "title", "excerpt" ]
      }
   }
}

模糊查询
ES一般用于数据量特别大,检索需要迅速的项目中,比如文库,比如新闻,比如歌词库等项目中。

相关推荐

  1. 使用OpenGL 和 opengl ES 渲染YUV图片文件QT示例

    2024-07-16 21:18:03       56 阅读
  2. ES6模板字符串基本使用

    2024-07-16 21:18:03       51 阅读
  3. ES客户端RestHighLevelClient使用

    2024-07-16 21:18:03       62 阅读
  4. ES在工作中使用

    2024-07-16 21:18:03       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-16 21:18:03       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-16 21:18:03       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-16 21:18:03       57 阅读
  4. Python语言-面向对象

    2024-07-16 21:18:03       68 阅读

热门阅读

  1. Redis--过期删除策略和数据淘汰策略

    2024-07-16 21:18:03       25 阅读
  2. actual combat 35 —— es

    2024-07-16 21:18:03       22 阅读
  3. 在 Gradle 项目中,排查依赖冲突可以的详细步骤

    2024-07-16 21:18:03       16 阅读
  4. LeetCode题练习与总结:最大间距--164

    2024-07-16 21:18:03       21 阅读
  5. ThinkPHP6事件系统使用指南

    2024-07-16 21:18:03       22 阅读
  6. postman安装介绍

    2024-07-16 21:18:03       19 阅读
  7. echarts忽略Null值:使用echarts的connectNulls

    2024-07-16 21:18:03       22 阅读
  8. 知识蒸馏和知识图谱相结合的大模型微调方案

    2024-07-16 21:18:03       21 阅读
  9. uni-app开发时自定义导航栏

    2024-07-16 21:18:03       23 阅读
  10. 新质生产力和新质战斗力如何深度耦合

    2024-07-16 21:18:03       20 阅读
  11. 【Python】Arcpy将excel点生成shp文件

    2024-07-16 21:18:03       21 阅读
  12. Linux批量更改文件后缀名

    2024-07-16 21:18:03       19 阅读