装置
# 新建 docker-elasticsearch 目录
$ mkdir docker-elasticsearch
# 进入 docker-elasticsearch 目录
$ docker-elasticsearch
# 新建 config 文件夹并批改权限
$ mkdir config && chmod 777 -R config
# 新建 data 文件夹
$ mkdir data && chmod 777 -R data
# 写入配置到 config 目录下的 elasticsearch.yml 中
$ echo "http.host: 0.0.0.0" >> config/elasticsearch.yml
编写 docker-compose.yml 文件
version: '3'
services:
elasticsearch:
image: elasticsearch:7.10.1
container_name: elasticsearch
restart: always
ports:
- 9200:9200
- 9300:9300
environment:
- "ES_JAVA_OPTS=-Xms64m -Xmx128m"
- discovery.type=single-node
volumes:
- ./config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./data:/usr/share/elasticsearch/data
- ./data/plugins:/usr/share/elasticsearch/data/plugins
装置好了当前在浏览器输出 HOST:9200, 显示以下界面, 阐明装置胜利了
装置 kibana
version: '2'
services:
kibana:
container_name: kibana
image: kibana:7.10.1
ports:
- "5601:5601"
restart: always
environment:
- ELASTICSEARCH_HOSTS=http://192.168.4.5:9200
elasticsearch 基本操作
插入数据 (PUT, POST)
PUT /account/_doc/1
{
"name": "Felix",
"age": 18,
"company": [
{
"name": "BFKJ",
"address": "LIUZHOU"
},
{
"name": "aliyun",
"address": "hangzhou"
}
]
}
// 该办法不须要指定 id, 会默认生成一个随机 id
POST user/_doc
{
"name": "Felix",
"company": "bfkj"
}
// 没有数据就插入, 有数据就报错
POST user/_create/1
{
"name": "Felix",
"company": "bfkj"
}