[关闭]
@nalan90 2016-12-09T23:14:17.000000Z 字数 3977 阅读 518

Getting Started

ElasticSearch


Cluster Health

  1. #Request
  2. GET /_cat/health?v
  3. #Response
  4. epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
  5. 1481276500 09:41:40 elasticsearch yellow 1 1 11 11 0 0 11 0 - 50.0%
  1. #Request
  2. GET /_cat/nodes?v
  3. #Response
  4. ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
  5. 172.17.0.2 7 89 0 0.08 0.04 0.01 mdi * kx4nTUI
  1. #Request
  2. GET /_cat/indices?v
  3. #Response
  4. health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
  5. yellow open .kibana OKHkcJ1HSUylJM5MSCX3lA 1 1 1 0 3.1kb 3.1kb
  6. yellow open bank TPSuBFZVRlKW61o5JMuk8A 5 1 1000 0 640.8kb 640.8kb

Create an Index

  1. #Request
  2. PUT /customer?pretty
  3. #Response
  4. {
  5. "acknowledged": true,
  6. "shards_acknowledged": true
  7. }

Index and Query a Document

  1. # Request
  2. PUT /customer/external/1?pretty
  3. {
  4. "name": "John Doe"
  5. }
  6. #Response
  7. {
  8. "_index": "customer",
  9. "_type": "external",
  10. "_id": "1",
  11. "_version": 1,
  12. "result": "created",
  13. "_shards": {
  14. "total": 2,
  15. "successful": 1,
  16. "failed": 0
  17. },
  18. "created": true
  19. }
  1. #Request
  2. GET /customer/external/1?pretty
  3. #Response
  4. {
  5. "_index": "customer",
  6. "_type": "external",
  7. "_id": "1",
  8. "_version": 1,
  9. "found": true,
  10. "_source": {
  11. "name": "John Doe"
  12. }
  13. }
  14. #Request
  15. GET /customer/external/2?pretty
  16. #Response 未查询到任何数据
  17. {
  18. "_index": "customer",
  19. "_type": "external",
  20. "_id": "2",
  21. "found": false
  22. }

Delete an Index

  1. #Request
  2. DELETE /customer?pretty
  3. #Response
  4. {
  5. "acknowledged": true
  6. }
  1. PUT /customer
  2. PUT /customer/external/1
  3. {
  4. "name": "John Doe"
  5. }
  6. GET /customer/external/1
  7. DELETE /customer
  1. <REST Verb> /<Index>/<Type>/<ID

Modifying Your Data

  1. GET /customer/external/1?pretty
  2. {
  3. "_index": "customer",
  4. "_type": "external",
  5. "_id": "1",
  6. "_version": 1,
  7. "found": true,
  8. "_source": {
  9. "name": "John Doe"
  10. }
  11. }
  1. #Request
  2. PUT /customer/external/1?pretty
  3. {
  4. "name": "John Doe"
  5. }
  6. #Response
  7. {
  8. "_index": "customer",
  9. "_type": "external",
  10. "_id": "1",
  11. "_version": 2,
  12. "result": "updated",
  13. "_shards": {
  14. "total": 2,
  15. "successful": 1,
  16. "failed": 0
  17. },
  18. "created": false
  19. }
  20. 版本号变更
  1. #Request
  2. POST /customer/external?pretty
  3. {
  4. "name": "Jane Doe"
  5. }
  6. #Response
  7. {
  8. "_index": "customer",
  9. "_type": "external",
  10. "_id": "AVjkGopJkGmB7tHuUrBy",
  11. "_version": 1,
  12. "result": "created",
  13. "_shards": {
  14. "total": 2,
  15. "successful": 1,
  16. "failed": 0
  17. },
  18. "created": true
  19. }

Updating Documents

  1. POST /customer/external/1/_update?pretty
  2. {
  3. "doc": { "name": "Jane Doe" }
  4. }
  5. {
  6. "_index": "customer",
  7. "_type": "external",
  8. "_id": "1",
  9. "_version": 6,
  10. "result": "updated",
  11. "_shards": {
  12. "total": 2,
  13. "successful": 1,
  14. "failed": 0
  15. }
  16. }
  17. POST /customer/external/1/_update?pretty
  18. {
  19. "doc": { "name": "Jane Doe", "age": 20 }
  20. }
  21. GET /customer/external/1?pretty
  22. {
  23. "_index": "customer",
  24. "_type": "external",
  25. "_id": "1",
  26. "_version": 7,
  27. "found": true,
  28. "_source": {
  29. "name": "Jane Doe",
  30. "age": 20
  31. }
  32. }
  33. #年龄+5
  34. POST /customer/external/1/_update?pretty
  35. {
  36. "script" : "ctx._source.age += 5"
  37. }
  38. GET /customer/external/1?pretty
  39. {
  40. "_index": "customer",
  41. "_type": "external",
  42. "_id": "1",
  43. "_version": 8,
  44. "found": true,
  45. "_source": {
  46. "name": "Jane Doe",
  47. "age": 25
  48. }
  49. }

Deleting Documents

  1. #Request
  2. DELETE /customer/external/1?pretty
  3. #Response
  4. {
  5. "found": true,
  6. "_index": "customer",
  7. "_type": "external",
  8. "_id": "1",
  9. "_version": 9,
  10. "result": "deleted",
  11. "_shards": {
  12. "total": 2,
  13. "successful": 1,
  14. "failed": 0
  15. }
  16. }

Batch Processing

  1. #Request
  2. POST /customer/external/_bulk?pretty
  3. {"index":{"_id":"1"}}
  4. {"name": "John Doe" }
  5. {"index":{"_id":"2"}}
  6. {"name": "Jane Doe" }
  7. #Response
  8. {
  9. "took": 40,
  10. "errors": false,
  11. "items": [
  12. {
  13. "index": {
  14. "_index": "customer",
  15. "_type": "external",
  16. "_id": "1",
  17. "_version": 1,
  18. "result": "created",
  19. "_shards": {
  20. "total": 2,
  21. "successful": 1,
  22. "failed": 0
  23. },
  24. "created": true,
  25. "status": 201
  26. }
  27. },
  28. {
  29. "index": {
  30. "_index": "customer",
  31. "_type": "external",
  32. "_id": "2",
  33. "_version": 1,
  34. "result": "created",
  35. "_shards": {
  36. "total": 2,
  37. "successful": 1,
  38. "failed": 0
  39. },
  40. "created": true,
  41. "status": 201
  42. }
  43. }
  44. ]
  45. }
  1. #Request
  2. POST /customer/external/_bulk?pretty
  3. {"update":{"_id":"1"}}
  4. {"doc": { "name": "John Doe becomes Jane Doe" } }
  5. {"delete":{"_id":"2"}}
  6. #Response
  7. {
  8. "took": 33,
  9. "errors": false,
  10. "items": [
  11. {
  12. "update": {
  13. "_index": "customer",
  14. "_type": "external",
  15. "_id": "1",
  16. "_version": 2,
  17. "result": "updated",
  18. "_shards": {
  19. "total": 2,
  20. "successful": 1,
  21. "failed": 0
  22. },
  23. "status": 200
  24. }
  25. },
  26. {
  27. "delete": {
  28. "found": true,
  29. "_index": "customer",
  30. "_type": "external",
  31. "_id": "2",
  32. "_version": 2,
  33. "result": "deleted",
  34. "_shards": {
  35. "total": 2,
  36. "successful": 1,
  37. "failed": 0
  38. },
  39. "status": 200
  40. }
  41. }
  42. ]
  43. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注