安装
- 官网:
https://www.elastic.co/cn/downloads/elasticsearch
- 下载:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.0-darwin-x86_64.tar.gz
- 解压:
tar -zxvf elasticsearch-7.5.0-darwin-x86_64.tar.gz
- 总写入量:.
cd elasticsearch-7.5.0
sh ./bin/elasticsearch
- 访问
127.0.0.1:9200
依赖java环境
head插件
- 下载:
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
- 解压
unzip master.zip
cd www/es/elasticsearch-head-master
npm install
npm run start
- 访问
127.0.0.1:9100
elasticsearch 配置修改vim config/elasticsearch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17# 跨域配置
http.cors.enabled: true
http.cors.allow-origin: "*"
# 集群配置
cluster.name: uiste
node.name: master
node.master: true
network.host: 127.0.0.1
# 一下内容是从节点配置信息
#cluster.name: uiste
#node.name: slave1
#network.host: 127.0.0.1
#http.port: 8200
#discovery.zen.ping.unicast.hosts: ["127.0.0.1"]
依赖node环境
索引创建
API基本格式:1
http://[ip]:[port]/[索引]/[类型]/[文档ID]
请求示例:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32URL:127.0.0.1:9100/people
METHOD: PUT
PARAMS:
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"name": {
"type": "text"
},
"country": {
"type": "keyword"
},
"age": {
"type": "integer"
},
"date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}
RESPONSE:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "people"
}
异常情况执行结果出错:Root mapping definition has unsupported parameters
出现这个的原因是,elasticsearch7默认不在支持指定索引类型,默认索引类型是_doc,如果想改变,则配置include_type_name: true 即可(这个没有测试,官方文档说的,无论是否可行,建议不要这么做,因为elasticsearch8后就不在提供该字段)。官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html
索引查询
1 | URL: 127.0.0.1:9200/people/_mapping |
添加更新文档
1 | URL: 127.0.0.1:9200/people/_doc/1 |
查询文档
1 | URL:127.0.0.1:9200/people/_search |