Relational DB | Elasticsearch |
---|---|
数据库(database) | 索引 index |
表(tables) | 索引 index(原为 types) |
行(rows) | 文档 documents |
字段(columns) | fields |
约束(schema) | 映射mapping |
rpm -Uvh elasticsearch-7.12.0-x86_64.rpm
systemctl enable elasticsearch
systemctl start elasticsearch
#查看es状态
systemctl status elasticsearch
如果是elasticsearch8.+
vim /etc/elasticsearch/elasticsearch.yml
xpack.security.enabled默认为true,此时改成false
xpack.security.enabled: false
curl "http://localhost:9200"
使用图形工具head连接时需要添加增加跨域访问参数
vim /etc/elasticsearch/elasticsearch.yml
添加及修改以下配置
http.host: 0.0.0.0
network.host: 0.0.0.0
discovery.seed_hosts: ["0.0.0.0", "[::1]"]
#启用跨域支持
http.cors.enabled: true
http.cors.allow-origin: "*"
systemctl restart elasticsearch
wget https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.xz
tar -xvf node-v14.16.1-linux-x64.tar.xz
mv ./node-v14.16.1-linux-x64 /usr/local/nodejs
ln -s /usr/local/nodejs/bin/npm /usr/local/bin/
ln -s /usr/local/nodejs/bin/node /usr/local/bin/
node -v
npm -v
克隆项目到本地
git clone https://github.com/mobz/elasticsearch-head.git
进入根目录
cd elasticsearch-head/
vim package.json
"license": "Apache-2.0"
npm install
npm run start
nohup npm run start &
默认端口为9100
http://ip地址:9100
下载对应的版本
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.0/elasticsearch-analysis-ik-7.12.0.zip
mkdir /usr/share/elasticsearch/plugins/ik
unzip -o elasticsearch-analysis-ik-7.12.0.zip -d /usr/share/elasticsearch/plugins/ik
ll /usr/share/elasticsearch/plugins/ik
systemctl restart elasticsearch
index是索引名,可自定义
curl -XPUT http://localhost:9200/index
index为指定的索引名
curl -XPOST http://localhost:9200/index/_mapping -H 'Content-Type:application/json' -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
}
}
}'
curl -XPOST http://localhost:9200/index/_create/1 -H 'Content-Type:application/json' -d'{"content":"美国留给伊拉克的是个烂摊子吗"}'
curl -XPOST http://localhost:9200/index/_create/2 -H 'Content-Type:application/json' -d'{"content":"公安部:各地校车将享最高路权"}'
curl -XPOST http://localhost:9200/index/_create/3 -H 'Content-Type:application/json' -d'{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}'
curl -XPOST http://localhost:9200/index/_create/4 -H 'Content-Type:application/json' -d'{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}'
以“中国领事馆”为关键字
curl -XPOST http://localhost:9200/index/_search -H 'Content-Type:application/json' -d'
{
"query" : { "match" : { "content" : "中国领事馆" }},
"highlight" : {
"pre_tags" : ["", ""],
"post_tags" : [" ", ""],
"fields" : {
"content" : {}
}
}
}'
{
"query": {
"match": {
"content": "中国领事馆"
}
},
"highlight": {
"pre_tags": [
"" ,
""
],
"post_tags": [
"",
""
],
"fields": {
"content": {}
}
}
}