docker run啓動elastic服務node
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的方式部署docker
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:
查看集羣是否健康bootstrap
curl 'localhost:9200/_cat/health?v'
獲取集羣的節點列表curl
curl 'localhost:9200/_cat/nodes?v'
列出全部索引elasticsearch
curl 'localhost:9200/_cat/indices?v'
創建名爲customer的索引url
curl -XPUT 'localhost:9200/customer?pretty'
向索引customer,類型爲external,添加數據code
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'
刪除索引 DELETEit
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'