在好例子网,分享、交流、成长!
您当前所在位置:首页Others 开发实例一般编程问题 → SpringBoot集成Elasticsearch7.4 实战.pdf

SpringBoot集成Elasticsearch7.4 实战.pdf

一般编程问题

下载此实例
  • 开发语言:Others
  • 实例大小:0.98M
  • 下载次数:13
  • 浏览次数:310
  • 发布时间:2021-01-29
  • 实例类别:一般编程问题
  • 发 布 人:好学IT男
  • 文件格式:.pdf
  • 所需积分:2
 

实例介绍

【实例简介】
1、CentOS7下安装Elasticsearch7.4 2、SpringBoot版本2.1.8.RELEASE,集成Elasticsearch7.4实现创建索引、删除索引;添加输入
README. md 11/72019 路径 config/ elasticsearch.ym 允许外部IP访问 network. host: 0.0.0.0 把这个注释先放开 cluster. initial master nodes:["node-1","node-2"] 1.1.5.启动&验证结果 ·启动 elastic@localhost elastic]s ./bin/elasticsearch ·验让结果 Elastic公在默认9200端口运行,打开地址http://192.168.147.132:9200/ C合(①不宝197.168.|47137 应用M云 Naven Center Appe次尽中电个项日空理中国信P材6oe译Nexs百度一下,你知道(0gMM找机原理分, IsoN name: localhost localdomain cluster name: elasticsearch i cluster_uuid: 5KWEv4UhSaWOBsmvNHukYA version number: 7.41.0 build hash: 22e1767283e61a196cb4db791ea66e3f1-ab9910 build date:2019092708:36:48.5694192 build_snaps lucene version: 8.2.0 minimum_wire_compatibility_version: 6.8.0 minimum_index_ compatibility_version: 6.0.0-betal tagline: You Know, for Seard 1.2.中文分词插件|K 1.21.安装 ik插件地址:https://github.com/medcl/elasticsearch-analysis-ik为了演示需要,这里选择wget方式。 载 [root@localhostdownloadswgethttps://github.com/medcl/elasticsearch-analysis ik/releases/download/v7.4.0/elasticsearch-analysis-ik-740. zip 安裝插件 3 README. md 11/72019 Elastic@localhost elastic]s cd plugins Elastic@localhost plugins]$ cd mkdir ik & cd ik Elastic(@localhost ik]$ cp ./././download/elasticsearch-analysis-ik-740. zip elastic@localhost ik]s unzip elasticsearch-analysis-ik-7.4.0.zip 完成后重启eS 验证分词器 使用cru命令,输入下面的URL地址,验证分词器是否成功。 elastic@localhost elastic]s curl -X GET -H "Content-Type: application/json http://localhost:9200/analyze?pretty=true"-d'ttext":中华五千年华夏"}'; elasticclocathostik」curl-xGei-H"conTent-lype:application/]son"http://localhoSt:9200/analyze?pretty=true"-d'text":中华土干年华复"}'; art outset end offset typ <IDLOGRAPllIC> osition. 0 token":‘华", start offset 1 pasition start offset: 2 nd offset token position": 3 start offset. 4 type": CIDEOGRAPHIC>" position": 4 55/ root1y2.68141.1322 1.2.2. ik max word FAik smart · ik max word:将文本按最细粒度的组合来拆分,比如会将“中华五千年华夏"拆分为五千年、五千、五 千年华、华夏、千年华夏",总之是可能的组合; · ik smart最粗粒度的拆分,比如会将"五千年华夏"拆分为五千年、华夏 不添加分词类别, Elastic对于汉字默认使用 standard只是将汉字拆分成一个个的汉字,而我们i则更加 的智能,下面通过几个案例来说明。 4/29 README. md 11/72019 1221. ik smart分词 在丿SON格式中添加 analyzer节点内容为 lik smart Elastic@localhost elastic]s curl -X GET -H "Content-Type: application/json http://localhost:9200/analyze?pretty=true"-dttext":中华五千年华 夏"," analyzer":"ik_5mart"}’ Iclasticalocathostik]scurlXGetContentTypc:application/ison"http://localhost:92e0/analyzoprotty-truc"d[toxt":中华五千午华夏analyzer:ksnart token".中华" tart offs 5⊥Liu":9 start offset 1222. ik max word分词 在JSON格式中添加 analyzer节点内容为 lik max word Elastic@localhost elastic]s curl-X GET -H"Content-Type: application/json http://localhost:9200/analyze?pretty=true"-d'ftext":中华五千年华 a","analyzer":"ik max word") 1.3.索引 1.3.1.创建索引 README. md 11/72019 由」在 ElasticSearch7x之后就默认不在文持指定索引类型,所以在在 elasticsearch7κ上执行: settings": index": t number of shards: 3 number of replicas: 2 mappings": twitter": 执行结果则会出错: Root mapping definition has unsupported parameters(刚开始接触就踩了这个坑,折煞 劳资好久)。如果在6κ上执行,则会正常执行。出现这个的原因是, elasticsearch7默认不在支持指定索引类 型,默认索引类型是doc,如果想改变,则配置 include_ type_name:true即可(这个没有测试,官方文档说的, 无论是否可行,建议不要这么做,因为 elasticsearch8后就不在提供该字段) https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html 13.11.官方例子说明 curl -X PUT "localhost: 9200/twitter -H Content-Type: application/json'-d settings":i index number of shards:3 number of replicas:2 d指定了你的参数,这里将这些参数放到∫jon文件中 settings设置内容含义 name 价格 number of shards分片数 number__of_replicas副本数 mappings 结构化数据设置下面的一级属性是自定义的类型 properties 类型的属性设置节点,下面都是属性 6/29 README. md 11/72019 name 价格 poch_millis 表示时闩戳 13.12.自定义索引 使用json文件创建索引使用-d@ your json File指定你的json文件。下边我创建了一个索引名称为 product(可自己定义)的索引。 Elastic@localhost elastic]$ curl -"Content-Type: application/json"X PUT http://localhost:9200/twitter?pretty=true"-d'aprod.json [elasticglocathost elastics curl-hcontent-Type: application/]son-x puThttP: //Locathost: 9200/twitter?pretty=true -d prod. json shards acknowledged": true twitter [elasticqLocalhost elastic]s 参数形式创建索引 elastic@localhost elastic]s curl -"Content-Type: application/json"-X PUT http://localhost:9200/twitter?pretty=true"-d settings": t index": t number of shards: 3 number of replicas": 2 mappings": t dynamic: false, properties":[ productid: i e n."long name": I type: text index: true analyzer: ik max word short name": i type":text index: true analyzer:"ik max word desc": i type":text j index: true analyzer: ik max word 7 README. md 11/72019 elasticdlocathostelasticscurl-hcontent-type:application/son"-xputhttp://locathosT:9200/twitter?pretty-true"-d index number of shards :3, number of replicas mappings: L dyna mic false, proper Lies productid": I type Mtext. index": true analyzer: ik max word short name type:text andlyzer:" ik mdx war'd eSc text anal yer: ik max word acknowledged tru shld Ids acknluWLeuyed:true index:twitter 1.32.查看索引 1321.全部索引 Elastic@localhost elastic] curl -H"Content-Type: application/json"-X GET http://localhost:9200/cat/indices?v health status index uuid pri rep docs. count docs. deleted store. size pri store size yellow open twitter scSSD1SfRCio4F77Hh8agQ 3 2 690b 699b el asticalocalhast elastics curi -h"conteNt-type: appl ication/json-x Gft Http: //ocathost: 9200/ cat/indices?v health status index uuid pri rep docs. count docs. deleted stare. si7e pri store. si7e yellow open twitter scssnisfRCi04F77Hh8an0 3 69h 690b elas ticalocathast elas 1322.条件查询 elastic@localhost elastic]s curl -H"Content-Type: application/json"-X GET http://localhost:9200/twitter?pretty=true README. md 11/72019 twitter":t aliases": mappings":i dynamic":false properties desc text analyzer:ik max word name type":text analyzer:ik max word productid: t typ ong short name":i type text analyzer":"ik max word settings index creation date 1571153735619 number of shards":3", number of replicas uuid:SCSSD1SfRCio4F77Hh8agQ" version created 7040999" provided name":twitter 1.33.查看索引分词器 [elastic@localhost elastic]s curl -"Content-Type: application/json"-X GET http://localhost:9200/twitter/analyze?pretty=true field:text text":"秦皇汉武. elastic 9/29 README. md 11/72019 1.34.修改索引 1.3.5删除索引 Elastic@localhost elastic]s curl -H"Content-Type: application/ison"-X DELETE http://localhost:9200/twitter?pretty=true 14.如何数据管理 14.1.添加数据 ·这里演示PUT方式为 twitter索引添加数据,并且指定id,应当注意此处的默认类型为do,还有·种就是 釆用P○ST方式添加数据,并且自动生成主键,本文就不再演示,请自行查相关材料。 [elasticalocalhost elastic]s curl -H " Content-Type: application/json"-X PUT http://localhost:9200/twitter/doc/1?pretty=true-d productid: 1, name 测试添加索引产品名称", " short_name":"测试添加索引产品短标题", desc":"测试添加索引产品描述 执行返回结果如图,则添加数据成功。 [clasticalocalhost clastics curl Hcontent Typc: application/ison"x PuthtTp: //localhost: 9200/twitter/ doc/1?prctty=truc" d productid":1 "name":"测试添加京引产品名称 hort name 武添加索引产品短标题 desc":"测试涿加紫引产品描述 ndx": twitter created total "「 died": 0, 「 elasticalocalhost elastic1s■ 指定id为1,还可以加上参数 op_type= create,这样在创建重复id吋会报错导致创建失败,否则会更新该 id的属性值。 [elastic@localhost elastic]s curl -H"Content-Type: application/json"-X PUT http://localhost:9200/twitter/doc/1?optype=create&pretty=true-d productid 1 "name":"测试添加索引产品名称", " short name":"测试添加索引产品短标题", 10/29 【实例截图】
【核心代码】

标签:

实例下载地址

SpringBoot集成Elasticsearch7.4 实战.pdf

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警