安装地址
https://www.elastic.co/guide/en/elasticsearch/reference/7.2/docker.html
docker pull安装
安装
docker pull elasticsearch
配置jvm内存 /conf/elasticsearch/jvm.options
-Xms512m
-Xmx512m
启动
docker run -v /conf/elasticsearch/jvm.options:/etc/elasticsearch/jvm.options -p 9200:9200 --rm -it elasticsearch
测试
http://192.168.199.149:9200/
{
name: "wXaTvCS",
cluster_name: "elasticsearch",
cluster_uuid: "QBWCsKICTWuw16XDcKSqJg",
version: {
number: "5.6.12",
build_hash: "cfe3d9f",
build_date: "2018-09-10T20:12:43.732Z",
build_snapshot: false,
lucene_version: "6.6.1"
},
tagline: "You Know, for Search"
}
docker-compose安装
docker-compose.yml:
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
container_name: es01
environment:
- node.name=es01
- discovery.seed_hosts=es02
- cluster.initial_master_nodes=es01,es02
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- esnet
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
container_name: es02
environment:
- node.name=es02
- discovery.seed_hosts=es01
- cluster.initial_master_nodes=es01,es02
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata02:/usr/share/elasticsearch/data
networks:
- esnet
volumes:
esdata01:
driver: local
esdata02:
driver: local
networks:
esnet:
启动
docker-compose up
概念
| Elasticsearch | MySQL |
|---|---|
| Index | Database |
| Type | Table |
| Document | Row |
| Field | Column |
api操作
# 没有增加 有则修改 每次修改 _version都+1
curl -i -X PUT "vm:9200/movie/adventure/1" -d '{"name": "Life of Pi", "actors": ["Suraj", "Irrfan"]}'
#查看数据 可以匹配多个索引 正则
http://vm:9200/movie/adventure/_search
# 修改指定id下的指定字段 post、 update 、doc关键词
curl -i -X POST "vm:9200/movie/adventure/1/_update" -d '{"doc":{"name": "Life of2 Pi"}}'
#删除指定行
curl -i -X DELETE "vm:9200/movie/adventure/1/"
dsl操作
GET vm:9200/movie/adventure/_search
{
"query" : {
"match" : {
"name" : "life"
}
}
}