@nalan90
2016-12-09T15:14:17.000000Z
字数 3977
阅读 689
ElasticSearch
Cluster Health
#RequestGET /_cat/health?v#Responseepoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent1481276500 09:41:40 elasticsearch yellow 1 1 11 11 0 0 11 0 - 50.0%
#RequestGET /_cat/nodes?v#Responseip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name172.17.0.2 7 89 0 0.08 0.04 0.01 mdi * kx4nTUI
#RequestGET /_cat/indices?v#Responsehealth status index uuid pri rep docs.count docs.deleted store.size pri.store.sizeyellow open .kibana OKHkcJ1HSUylJM5MSCX3lA 1 1 1 0 3.1kb 3.1kbyellow open bank TPSuBFZVRlKW61o5JMuk8A 5 1 1000 0 640.8kb 640.8kb
Create an Index
#RequestPUT /customer?pretty#Response{"acknowledged": true,"shards_acknowledged": true}
Index and Query a Document
# RequestPUT /customer/external/1?pretty{"name": "John Doe"}#Response{"_index": "customer","_type": "external","_id": "1","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"created": true}
#RequestGET /customer/external/1?pretty#Response{"_index": "customer","_type": "external","_id": "1","_version": 1,"found": true,"_source": {"name": "John Doe"}}#RequestGET /customer/external/2?pretty#Response 未查询到任何数据{"_index": "customer","_type": "external","_id": "2","found": false}
Delete an Index
#RequestDELETE /customer?pretty#Response{"acknowledged": true}
PUT /customerPUT /customer/external/1{"name": "John Doe"}GET /customer/external/1DELETE /customer
<REST Verb> /<Index>/<Type>/<ID
Modifying Your Data
GET /customer/external/1?pretty{"_index": "customer","_type": "external","_id": "1","_version": 1,"found": true,"_source": {"name": "John Doe"}}
#RequestPUT /customer/external/1?pretty{"name": "John Doe"}#Response{"_index": "customer","_type": "external","_id": "1","_version": 2,"result": "updated","_shards": {"total": 2,"successful": 1,"failed": 0},"created": false}版本号变更
#RequestPOST /customer/external?pretty{"name": "Jane Doe"}#Response{"_index": "customer","_type": "external","_id": "AVjkGopJkGmB7tHuUrBy","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"created": true}
Updating Documents
POST /customer/external/1/_update?pretty{"doc": { "name": "Jane Doe" }}{"_index": "customer","_type": "external","_id": "1","_version": 6,"result": "updated","_shards": {"total": 2,"successful": 1,"failed": 0}}POST /customer/external/1/_update?pretty{"doc": { "name": "Jane Doe", "age": 20 }}GET /customer/external/1?pretty{"_index": "customer","_type": "external","_id": "1","_version": 7,"found": true,"_source": {"name": "Jane Doe","age": 20}}#年龄+5POST /customer/external/1/_update?pretty{"script" : "ctx._source.age += 5"}GET /customer/external/1?pretty{"_index": "customer","_type": "external","_id": "1","_version": 8,"found": true,"_source": {"name": "Jane Doe","age": 25}}
Deleting Documents
#RequestDELETE /customer/external/1?pretty#Response{"found": true,"_index": "customer","_type": "external","_id": "1","_version": 9,"result": "deleted","_shards": {"total": 2,"successful": 1,"failed": 0}}
Batch Processing
#RequestPOST /customer/external/_bulk?pretty{"index":{"_id":"1"}}{"name": "John Doe" }{"index":{"_id":"2"}}{"name": "Jane Doe" }#Response{"took": 40,"errors": false,"items": [{"index": {"_index": "customer","_type": "external","_id": "1","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"created": true,"status": 201}},{"index": {"_index": "customer","_type": "external","_id": "2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"created": true,"status": 201}}]}
#RequestPOST /customer/external/_bulk?pretty{"update":{"_id":"1"}}{"doc": { "name": "John Doe becomes Jane Doe" } }{"delete":{"_id":"2"}}#Response{"took": 33,"errors": false,"items": [{"update": {"_index": "customer","_type": "external","_id": "1","_version": 2,"result": "updated","_shards": {"total": 2,"successful": 1,"failed": 0},"status": 200}},{"delete": {"found": true,"_index": "customer","_type": "external","_id": "2","_version": 2,"result": "deleted","_shards": {"total": 2,"successful": 1,"failed": 0},"status": 200}}]}