部署服务

docker run启动elastic服务
docker pull elasticsearch:6.7.2 docker run -d -p 9200:9200 -p 9300:9300 -e
"discovery.type=single-node" elasticsearch:6.7.2
docker-compose.yml的方式部署
version: '2.2' services: elasticsearch: image:
docker.elastic.co/elasticsearch/elasticsearch:6.7.2 container_name:
elasticsearch environment: - cluster.name=docker-cluster -
bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock:
soft: -1 hard: -1 volumes: - esdata1:/usr/share/elasticsearch/data ports: -
9200:9200 networks: - esnet elasticsearch2: image:
docker.elastic.co/elasticsearch/elasticsearch:6.7.2 container_name:
elasticsearch2 environment: - cluster.name=docker-cluster -
bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" -
"discovery.zen.ping.unicast.hosts=elasticsearch" ulimits: memlock: soft: -1
hard: -1 volumes: - esdata2:/usr/share/elasticsearch/data networks: - esnet
volumes: esdata1: driver: local esdata2: driver: local networks: esnet:
elastic常用命令

查看集群是否健康
  curl 'localhost:9200/_cat/health?v'
获取集群的节点列表
  curl 'localhost:9200/_cat/nodes?v'
列出所有索引
curl 'localhost:9200/_cat/indices?v'
建立名为customer的索引
 curl -XPUT 'localhost:9200/customer?pretty'
向索引customer,类型为external,添加数据
  curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '   {    "name":
"John Doe"   }'
获取数据

获取customer索引下类型为external,id为1的数据,pretty参数表示返回结果格式美观。
curl -XGET 'localhost:9200/customer/external/1?pretty'
删除索引 DELETE
curl -XDELETE 'localhost:9200/customer?pretty'
修改数据,如果不存在,就新增
curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '   {    "name":
"John Doe"   }'
更新数据
  curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '   {   
"doc": { "name": "Jane Doe", "age": 20 }   }'
删除一条记录数据
curl -XDELETE 'localhost:9200/customer/external/2?pretty'