文章目录
docker安装es
docker安装es-head插件
es中CRUD
docker安装es
使用docker安装elasticsearch,只需要一句话,没有镜像会自动下载。
docker --name es -d -p 9200:9200 elasticsearch
docker ps
也可以先去search,pull拉取镜像。docker search elasticsearch
docker pull elasticsearch
使用浏览器访问下或发一个curl验证下。curl http://127.0.0.1:9200/
docker安装es-head插件
下面安装一个elasticsearch-head客户端插件,需要独立安装下。
docker search docker search elasticsearch-head
docker pull mobz/elasticsearch-head:5
docker run --name es-head -d -p 9100:9100 mobz/elasticsearch-head:5
浏览器访问:http://127.0.0.1:9100/,连接es时会出现跨域问题,修改es的配置文件elasticsearch.yml,可以直接挂载配置文件,也可以在es交互bash中修改或者在宿主机和容器之间cp文件。docker exec -it es bash
docker restart es
cd config
cat >> elasticsearch.yml <<-EOF
追加如下信息,修改完记得重启es服务。http.cors.enabled: true
http.cors.allow-origin: "*"
在es中操作crud
下面在es中操作一波crud,类似数据库,但es提供的是restful接口,简单对比下二者之间的操作。
elasticsearch | |
insert | PUT |
select | GET |
update | POST |
delete | DELETE |
curl -X PUT -d '{"name":"码农小麦","age":25,"habit":["run","music","coding","sing"]}' http://127.0.0.1:9200/person/student/1
curl -X GET http://127.0.0.1:9200/person/student/1
curl -X POST -d '{"name":"码农小麦","age":28}' http://127.0.0.1:9200/person/student/1
curl -X DELETE http://127.0.0.1:9200/person/student/1