# Day21 Elasticsearch 从入门到精通

# 相关链接

# 搜索引擎
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docker.html

# 展示操作界面
https://www.elastic.co/guide/en/kibana/7.17/docker.html

# 导入数据
https://www.elastic.co/guide/en/logstash/7.17/installing-logstash.html

# 中文分词
https://github.com/medcl/elasticsearch-analysis-ik

# 入门介绍
https://mp.weixin.qq.com/s?__biz=MzIxMTE0ODU5NQ==&mid=2650238166&idx=1&sn=f93737fbf547b4cbf5249ad6109d3496&chksm=8f5a068ab82d8f9ce9062aa43568c14cf2e167b04827cbfdfe3633862c0fc039a59d78911202&scene=0&xtrack=1#rd


# python client
https://pypi.org/project/elasticsearch/7.17.7/
https://elasticsearch-dsl.readthedocs.io/en/latest/

# python orm?
https://elasticsearch-dsl.readthedocs.io/en/latest/


# 相关视频
https://www.bilibili.com/video/BV16t4y1e7nx?p=1&vd_source=c2cd88c22f9f293467ba248b4efe396f

# 浏览代码 cms2

# 概述

  • Elasticsearch 搜索引擎
  • Logstash 导入数据
  • Kibana 可视化软件
- 倒排索引 快速搜索
- 分词
  • 倒排索引
# 关系数据库与Elasticsearch比较
database(数据库)     index(索引库)
table()            type(类型 _doc)
row()              document(文档)
column()           field(字段)   

# 原始文档
DocID       文档内容Document
1           谷歌地图之父跳槽Facebook
2           谷歌地图之父加盟Facebook
3           谷歌地图创始人拉斯离开谷歌加盟Facebook
4           谷歌地图之父跳槽Facebook与Wave项目取消有关
5           谷歌地图之父拉斯加盟社交网站Facebook

# 倒排索引一变
单词ID   单词       倒排列表(DocId)
1       谷歌        1,2,3,4,5
2       地图        1,2,3,4,5
3       之父        1,2,4,5
4       跳槽        1,4
5       Facebook   1,2,3,4,5

# 倒排索引二变
单词ID   单词       倒排列表(DocId:TF)
1       谷歌        (1:1),(2:1),(3:2),(4:1),(5:1)

# 倒排索引三变
单词ID   单词       倒排列表(DocId:TF:<POS>)
1       谷歌        (1:1:<1>),(2:1:<1>),(3:2<1:6>),(4:1<1>),(5:1<1>)

# 倒排索引说明
DocId   文档ID 
TF      单词在文档中出现的次数
POS     单词在文档中出现的位置

# 安装 ELK

# 版本选择 Docker 安装
- Elasticsearch 7.17.7
- Logstash 7.17.7
- Kibana 7.17.7

# 安装 Elasticsearch
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docker.html
https://www.elastic.co/guide/en/kibana/7.17/docker.html


docker network create elastic
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.17.7
docker run --name es01-test --net elastic -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 -e "discovery.type=single-node" -d docker.elastic.co/elasticsearch/elasticsearch:7.17.7


docker pull docker.elastic.co/kibana/kibana:7.17.7
docker run --name kib01-test --net elastic -p 127.0.0.1:5601:5601 -e "ELASTICSEARCH_HOSTS=http://es01-test:9200" -d docker.elastic.co/kibana/kibana:7.17.7


http://127.0.0.1:9200/
http://127.0.0.1:5601

Chrome插件可视化管理工具 Multi Elasticsearch Head
ElasticHD


POST http://localhost:9200/test/1/
{
  "name": "linda",
  "age": 18,
  "gender": "female"
}


elasticsearch-plugin https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.4.3/elasticsearch-analysis-ik-8.4.3.zip


docker cp /Users/nining/Downloads/elasticsearch-analysis-ik-8.4.3 es01-test:/usr/share/elasticsearch/plugins/ik

docker cp /Users/nining/Downloads/elasticsearch-analysis-ik-7.17.6.zip es01-test:/usr/share/elasticsearch/plugins/ik



docker exec -it es01-test /bin/bash

chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/plugins/ik

docker restart es01-test
docker logs es01-test
上次更新: 11/14/2022, 8:54:42 PM