文章目录
1、搜索引擎
根据用户的需求结合一定的算法,运用特定的策略检索出指定信息反馈给用户的一名检索技术。
2、为什么使用新型搜索?
- 性能更好
- 可以对搜索条件进行分词,部分匹配也可以检索出来
- 可以对符合结果的关键字进行高亮显示
- 即使输错一个字母依然可以搜索
- 进行关键字的补全
3、底层原理:倒排索引
又称反向索引,分为两部分:文档列表和倒排索引区
- 新增数据时:新增到文档列表的同时,会对搜索字段进行分词,把词条结果和位置信息保存到排序索引区
- 查询数据时:会对搜索条件进行分词,根据分词结果到倒排索引区进行匹配,进而找到词条的位置信息,根据位置找到文档列表中的数据。
4、底层API
lucene,类似于 servlet 属于 apache
solr、ElasticSearch
5、你使用了什么分词器?
ik分词器
6、ElasticSearch安装
6.1、准备目录并授予权限
[root@localhost ~]# rm -rf /opt/elasticsearch
[root@localhost ~]# mkdir -p /opt/elasticsearch/{config,plugins}
[root@localhost ~]# chmod -R 777 /opt/elasticsearch
6.2、制作配置文件
[root@localhost ~]# cat <<EOF> /opt/elasticsearch/config/elasticsearch.yml
> xpack.security.enabled: false
> xpack.license.self_generated.type: basic
> xpack.security.transport.ssl.enabled: false # 不配报错
> xpack.security.enrollment.enabled: true
> http.host: 0.0.0.0
> EOF
6.3、初始化es容器
[root@localhost ~]# docker network create elastic
Error response from daemon: network with name elastic already exists
本人已经创建
[root@localhost ~]# docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
> --net elastic \
> --restart=always \
> -e "discovery.type=single-node" \
> -e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
> -v /opt/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
> -v /opt/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
> -d elasticsearch:8.8.2
89bb2276fc3dbaffbec92dcfcafb953df70b8b278dc15ffdec17445235a0dc85
6.4、重置es用户密码
[root@localhost ~]# chmod -R 777 /opt/elasticsearch
[root@localhost ~]# docker exec -it elasticsearch bin/elasticsearch-reset-password -u elastic -i
WARNING: Owner of file [/usr/share/elasticsearch/config/users] used to be [root], but now is [elasticsearch]
WARNING: Owner of file [/usr/share/elasticsearch/config/users_roles] used to be [root], but now is [elasticsearch]
This tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Re-enter password for [elastic]:
ERROR: Failed to reset password for the [elastic] user
6.5、安装中文分词器
6.5.1、 把资料中的elasticsearch-analysis-ik-8.8.2.zip上传到/opt/elasticsearch/plugins目录
6.5.2、解压
[root@localhost ~]# cd /opt/elasticsearch/plugins/
[root@localhost plugins]# ls
elasticsearch-analysis-ik-8.8.2.zip
[root@localhost plugins]# unzip elasticsearch-analysis-ik-8.8.2.zip -d ik-analyzer
Archive: elasticsearch-analysis-ik-8.8.2.zip
creating: ik-analyzer/config/
inflating: ik-analyzer/config/extra_single_word_full.dic
inflating: ik-analyzer/config/quantifier.dic
inflating: ik-analyzer/config/IKAnalyzer.cfg.xml
inflating: ik-analyzer/config/main.dic
inflating: ik-analyzer/config/extra_single_word_low_freq.dic
inflating: ik-analyzer/config/extra_stopword.dic
inflating: ik-analyzer/config/preposition.dic
inflating: ik-analyzer/config/extra_main.dic
inflating: ik-analyzer/config/extra_single_word.dic
inflating: ik-analyzer/config/suffix.dic
inflating: ik-analyzer/config/surname.dic
inflating: ik-analyzer/config/stopword.dic
inflating: ik-analyzer/plugin-descriptor.properties
inflating: ik-analyzer/plugin-security.policy
inflating: ik-analyzer/elasticsearch-analysis-ik-8.8.2.jar
inflating: ik-analyzer/httpclient-4.5.2.jar
inflating: ik-analyzer/httpcore-4.4.4.jar
inflating: ik-analyzer/commons-logging-1.2.jar
inflating: ik-analyzer/commons-codec-1.9.jar
6.5.3、删除压缩包
[root@localhost plugins]# rm -rf elasticsearch-analysis-ik-8.8.2.zip
[root@localhost plugins]# ls
ik-analyzer
6.6、重启es容器
[root@localhost plugins]# docker restart elasticsearch
elasticsearch
7、安装kibana
7.1、启动kibana
[root@localhost plugins]# docker run --name kibana \
> --net elastic \
> -v /opt/kibana/config:/usr/share/kibana/config \
> -p 5601:5601 -d kibana:8.8.2
45b3210eaa93a33f76f8facfeaaba71b0667d726c0f562421b404a3f7885c16e
7.2、创建配置文件
[root@localhost plugins]# cat <<EOF> /opt/kibana/config/kibana.yml
> server.host: "0.0.0.0" # 不配报错
> server.shutdownTimeout: "5s"
> elasticsearch.hosts: [ "http://192.168.74.148:9200" ]
> elasticsearch.username: "kibana_system" # 不能用 elastic
> elasticsearch.password: "123456"
> i18n.locale: "zh-CN"
> EOF
7.3、重启kibana容器
[root@localhost plugins]# docker restart kibana
kibana
8、测试安装分词词库是否可以使用!
GET /_analyze
{
"analyzer": "ik_smart",
"text": "我是中国人"
}