对不起 | 对不起,你以前学的 ElasticSearch 都是垃圾!
source link: https://www.iming.info/2020/11/18/对不起-对不起,你以前学的-elasticsearch-都是垃圾!/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Hi! 我是小小,今天是本周的第三篇,今天的主要内容是 ElasticSearch 相关的内容。
撒是ElasticSearch
ElasticSearch 是一个基于 Lucene 的搜索服务器,其提供了一个分布式的多用户能力的全文搜索引擎,基于 RestFul Api Web 接口,基于 Java 语言开发,在 Apache 许可下发布。可以连接多种语言,例如Java,PhP,.net 等。
快速入门
创建索引库
ES 的索引库是一个逻辑概念,包括分词列表和文档列表,相当于MySql的表,MongoDB的集合。
基于Restful API 这样使用
put http://localhost:9200/索引库名称
同时需要设置需要的请求体
{ "settings":{ "index":{ "number_of_shards":1, "number_of_replicas":0 } } }
number_of_shards 分片数量
number_of_replicas 副本数量
同时,还可以使用 head 插件创建新的索引
创建映射
在索引中,每个文档都包含了一个或多个 fieID,创建映射就是在索引库中创建 fieID 的过程。
其对比如下
文档(Document)----------------Row记录 字段(Field)-------------------Columns列
其格式如下
post http://localhost:9200/索引库名称/_mapping
为 xedu_course 索引库创建对应的映射,共包括三个字段:
name:课程名称
description:课程描述
studymondel:课程状态
在 head 中查看
创建文档
相当于创建 MySql 中的记录
其格式如下
put 或 Post http://localhost:9200/索引库名称/_doc/id值 # 如果不指定id值ES会自动生成ID
在 head 中查看
搜索文档
根据课程 id 查询文档
get http://192.168.116.129:9200/xedu_course/_doc/4028e58161bcf7f40161bcf8b77c0000
查询所有记录
get http://192.168.116.129:9200/xedu_course/_doc/_search
查询名称中包括 bootstrap 关键字的的记录
get http://192.168.116.129:9200/xedu_course/_doc/_search?q=name:bootstrap
查询学习模式为 201001 的记录
get http://192.168.116.129:9200/xedu_course/_doc/_search?q=studymodel:201001
分词器
索引中保存的是一个个的词,当去搜索的时候,使用关键字去匹配索引中的值,找到关联的文档。
测试分词器
post http://192.168.116.129:9200/_analyze {"text":"测试分词器,后边是测试内容:spring cloud实战"}
使用 ik 分词器实现中文词组分词
post http://192.168.116.129:9200/_analyze {"text":"测试分词器,后边是测试内容:spring cloud实战","analyzer":"ik_max_word" }
映射
查询
查询所有索引的映射
get http://192.168.116.129:9200/_mapping
创建
post http://localhost:9200/索引库名称/_mapping
更新
可以添加字段,不能更新已有的字段
删除
通过删除索引来删除映射
关于作者
我是小小,双鱼座的程序猿,爱生活,爱幻想,我们下期再见!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK