ES(Elasticsearch)
Elasticsearch是一个实时的分布式存储、搜索和分析引擎。它可以用于多种用途,但它擅长的一个方面是索引半结构化数据流,例如日志或解码的网络数据包。
1.下载安装
-
deb for Debian/Ubuntu
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.1.2-amd64.deb sudo dpkg -i elasticsearch-8.1.2-amd64.deb # 配置elasticsearch服务,以使用systemd自动启动 sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service # 启动elasticsearch服务 sudo systemctl start elasticsearch.service
-
rpm for Redhat/Centos/Fedora
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.1.2-x86_64.rpm sudo rpm -i elasticsearch-8.1.2-x86_64.rpm sudo service elasticsearch start
-
mac for OS X
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.1.2-darwin-x86_64.tar.gz tar -xzvf elasticsearch-8.1.2-darwin-x86_64.tar.gz cd elasticsearch-8.1.2 ./bin/elasticsearch
-
linux for Linux
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.1.2-linux-x86_64.tar.gz tar -xzvf elasticsearch-8.1.2-linux-x86_64.tar.gz cd elasticsearch-8.1.2 ./bin/elasticsearch
-
win for Windows
1.下载elasticsearch-8.1.2-windows-x86_64.zip文件
2.将 zip 文件的内容解压缩到计算机上的某个目录,例如
C:\Program Files
.3.以管理员身份打开命令提示符并导航到包含提取文件的目录,例如:
cd C:\Program Files\elasticsearch-8.1.2
4.启动Elasticsearch:
.\bin\elasticsearch.bat
2.配置
打开配置文件elasticsearch.yml
# 关闭身份验证
xpack.security.enabled: false
3.确保 Elasticsearch 已启动并运行
在浏览器输入 localhost:9200
验证是否启动:
{
"name" : "PS2022CCBSJOOJ",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "FxP8PXOiQpSa7gnTadCsOA",
"version" : {
"number" : "8.1.2",
"build_flavor" : "default",
"build_type" : "zip",
"build_hash" : "31df9689e80bad366ac20176aa7f2371ea5eb4c1",
"build_date" : "2022-03-29T21:18:59.991429448Z",
"build_snapshot" : false,
"lucene_version" : "9.0.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
4.使用
-
获取健康状态
curl -X GET http://localhost:9200/_cat/health?v
输出结果:
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1649342888 14:48:08 elasticsearch green 1 1 2 2 0 0 0 0 - 100.0%
-
查询当前ES集群中所有的indices
curl -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 test R6IiaDKSQF26_yy8D-agaA 1 1 0 0 225b 225b yellow open www FgZVSnOQRPWAmuS_79jb_w 1 1 0 0 225b 225b
-
创建索引
curl -X PUT localhost:9200/www
输出结果:
{"acknowledged":true,"shards_acknowledged":true,"index":"www"}
-
删除索引
curl -X DELETE localhost:9200/www
输出结果:
curl -X DELETE localhost:9200/www
5.集成IK Analysis插件
- 方法1:
# 1.下载与构建包
# https://github.com/medcl/elasticsearch-analysis-ik/releases
# 2.在ES根目录创建ik插件目录
D:\DevelopInstall\elasticsearch-8.1.2\plugins\ik
# 3.解压elasticsearch-analysis-ik-8.1.2.zip到插件目录
# 4.重启elasticsearch
- 方法2:
# 用elasticsearch-plugin安装插件
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.0/elasticsearch-analysis-ik-6.3.0.zip