Search Shards API

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html

译文链接 : http://apache.wiki/display/Elasticsearch/Search+Shards+API

贡献者 : @Josh

搜索分片(ShardsAPI 返回将执行搜索请求的索引和分片。 这可以提供有用的反馈用于解决问题或者计划用 routingshard preference 来优化。

indextype 参数可以为单个值,或者用逗号分隔。

用法

比如:

  1. GET /twitter/_search_shards

产生如下结果:

  1. {
  2. "nodes": ...,
  3. "shards": [
  4. [
  5. {
  6. "index": "twitter",
  7. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  8. "primary": true,
  9. "shard": 0,
  10. "state": "STARTED",
  11. "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
  12. "relocating_node": null
  13. }
  14. ],
  15. [
  16. {
  17. "index": "twitter",
  18. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  19. "primary": true,
  20. "shard": 1,
  21. "state": "STARTED",
  22. "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
  23. "relocating_node": null
  24. }
  25. ],
  26. [
  27. {
  28. "index": "twitter",
  29. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  30. "primary": true,
  31. "shard": 2,
  32. "state": "STARTED",
  33. "allocation_id": {"id":"Nwl0wbMBTHCWjEEbGYGapg"},
  34. "relocating_node": null
  35. }
  36. ],
  37. [
  38. {
  39. "index": "twitter",
  40. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  41. "primary": true,
  42. "shard": 3,
  43. "state": "STARTED",
  44. "allocation_id": {"id":"bU_KLGJISbW0RejwnwDPKw"},
  45. "relocating_node": null
  46. }
  47. ],
  48. [
  49. {
  50. "index": "twitter",
  51. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  52. "primary": true,
  53. "shard": 4,
  54. "state": "STARTED",
  55. "allocation_id": {"id":"DMs7_giNSwmdqVukF7UydA"},
  56. "relocating_node": null
  57. }
  58. ]
  59. ]
  60. }

指定相同的请求,这次用一个 routing 值:

  1. GET /twitter/_search_shards?routing=foo,baz

这将获得以下结果:

  1. {
  2. "nodes": ...,
  3. "shards": [
  4. [
  5. {
  6. "index": "twitter",
  7. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  8. "primary": true,
  9. "shard": 0,
  10. "state": "STARTED",
  11. "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
  12. "relocating_node": null
  13. }
  14. ],
  15. [
  16. {
  17. "index": "twitter",
  18. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  19. "primary": true,
  20. "shard": 1,
  21. "state": "STARTED",
  22. "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
  23. "relocating_node": null
  24. }
  25. ]
  26. ]
  27. }

所有参数

| routing | 以逗号分隔的路由值列表考虑到当确定哪些碎片会反对执行的请求。 | | preference | 控制要对其执行搜索请求的分片副本的 perference 。 默认情况下,操作在分片副本之间随机化。 有关所有可接受值的列表,请参阅 preference 文档。 | | local | 一个布尔值,是否在本地读取集群状态以便确定在何处分配碎片,而不是使用Master节点的集群状态。 |