2014-04-21 21:34:01 -04:00
|
|
|
[[search-shards]]
|
|
|
|
== Search Shards API
|
|
|
|
|
|
|
|
The search shards api returns the indices and shards that a search request would
|
|
|
|
be executed against. This can give useful feedback for working out issues or
|
2016-11-22 17:00:25 -05:00
|
|
|
planning optimizations with routing and shard preferences. When filtered aliases
|
2017-05-05 03:34:12 -04:00
|
|
|
are used, the filter is returned as part of the `indices` section [5.1.0] Added in 5.1.0.
|
2014-04-21 21:34:01 -04:00
|
|
|
|
2016-11-22 11:22:33 -05:00
|
|
|
The `index` may be a single value, or comma-separated.
|
2014-04-21 21:34:01 -04:00
|
|
|
|
|
|
|
[float]
|
|
|
|
=== Usage
|
|
|
|
|
|
|
|
Full example:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
GET /twitter/_search_shards
|
2014-04-21 21:34:01 -04:00
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
// CONSOLE
|
2018-05-14 12:22:35 -04:00
|
|
|
// TEST[s/^/PUT twitter\n{"settings":{"index.number_of_shards":5}}\n/]
|
2014-04-21 21:34:01 -04:00
|
|
|
|
|
|
|
This will yield the following result:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2016-09-14 11:23:25 -04:00
|
|
|
"nodes": ...,
|
2016-11-22 17:00:25 -05:00
|
|
|
"indices" : {
|
|
|
|
"twitter": { }
|
|
|
|
},
|
2014-04-21 21:34:01 -04:00
|
|
|
"shards": [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"index": "twitter",
|
|
|
|
"node": "JklnKbD7Tyqi9TP3_Q_tBg",
|
|
|
|
"primary": true,
|
2016-09-14 11:23:25 -04:00
|
|
|
"shard": 0,
|
|
|
|
"state": "STARTED",
|
|
|
|
"allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
|
|
|
|
"relocating_node": null
|
2014-04-21 21:34:01 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"index": "twitter",
|
|
|
|
"node": "JklnKbD7Tyqi9TP3_Q_tBg",
|
|
|
|
"primary": true,
|
2016-09-14 11:23:25 -04:00
|
|
|
"shard": 1,
|
|
|
|
"state": "STARTED",
|
|
|
|
"allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
|
|
|
|
"relocating_node": null
|
2014-04-21 21:34:01 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"index": "twitter",
|
|
|
|
"node": "JklnKbD7Tyqi9TP3_Q_tBg",
|
|
|
|
"primary": true,
|
2016-09-14 11:23:25 -04:00
|
|
|
"shard": 2,
|
|
|
|
"state": "STARTED",
|
|
|
|
"allocation_id": {"id":"Nwl0wbMBTHCWjEEbGYGapg"},
|
|
|
|
"relocating_node": null
|
2014-04-21 21:34:01 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"index": "twitter",
|
|
|
|
"node": "JklnKbD7Tyqi9TP3_Q_tBg",
|
|
|
|
"primary": true,
|
2016-09-14 11:23:25 -04:00
|
|
|
"shard": 3,
|
|
|
|
"state": "STARTED",
|
|
|
|
"allocation_id": {"id":"bU_KLGJISbW0RejwnwDPKw"},
|
|
|
|
"relocating_node": null
|
2014-04-21 21:34:01 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"index": "twitter",
|
|
|
|
"node": "JklnKbD7Tyqi9TP3_Q_tBg",
|
|
|
|
"primary": true,
|
2016-09-14 11:23:25 -04:00
|
|
|
"shard": 4,
|
|
|
|
"state": "STARTED",
|
|
|
|
"allocation_id": {"id":"DMs7_giNSwmdqVukF7UydA"},
|
|
|
|
"relocating_node": null
|
2014-04-21 21:34:01 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
// TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/]
|
|
|
|
// TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.0.0.node/]
|
|
|
|
// TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.0.0.allocation_id.id/]
|
|
|
|
// TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.1.0.allocation_id.id/]
|
|
|
|
// TESTRESPONSE[s/Nwl0wbMBTHCWjEEbGYGapg/$body.shards.2.0.allocation_id.id/]
|
|
|
|
// TESTRESPONSE[s/bU_KLGJISbW0RejwnwDPKw/$body.shards.3.0.allocation_id.id/]
|
|
|
|
// TESTRESPONSE[s/DMs7_giNSwmdqVukF7UydA/$body.shards.4.0.allocation_id.id/]
|
2014-04-21 21:34:01 -04:00
|
|
|
|
|
|
|
And specifying the same request, this time with a routing value:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2017-11-23 03:48:54 -05:00
|
|
|
GET /twitter/_search_shards?routing=foo,bar
|
2014-04-21 21:34:01 -04:00
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
// CONSOLE
|
2018-05-14 12:22:35 -04:00
|
|
|
// TEST[s/^/PUT twitter\n{"settings":{"index.number_of_shards":5}}\n/]
|
2014-04-21 21:34:01 -04:00
|
|
|
|
|
|
|
This will yield the following result:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2016-09-14 11:23:25 -04:00
|
|
|
"nodes": ...,
|
2016-11-22 17:00:25 -05:00
|
|
|
"indices" : {
|
|
|
|
"twitter": { }
|
|
|
|
},
|
2014-04-21 21:34:01 -04:00
|
|
|
"shards": [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"index": "twitter",
|
|
|
|
"node": "JklnKbD7Tyqi9TP3_Q_tBg",
|
|
|
|
"primary": true,
|
2017-11-23 03:48:54 -05:00
|
|
|
"shard": 2,
|
2016-09-14 11:23:25 -04:00
|
|
|
"state": "STARTED",
|
2017-11-23 03:48:54 -05:00
|
|
|
"allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
|
2016-09-14 11:23:25 -04:00
|
|
|
"relocating_node": null
|
2014-04-21 21:34:01 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"index": "twitter",
|
|
|
|
"node": "JklnKbD7Tyqi9TP3_Q_tBg",
|
|
|
|
"primary": true,
|
2017-11-23 03:48:54 -05:00
|
|
|
"shard": 3,
|
2016-09-14 11:23:25 -04:00
|
|
|
"state": "STARTED",
|
2017-11-23 03:48:54 -05:00
|
|
|
"allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
|
2016-09-14 11:23:25 -04:00
|
|
|
"relocating_node": null
|
2014-04-21 21:34:01 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
// TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/]
|
2017-11-23 03:48:54 -05:00
|
|
|
// TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.1.0.node/]
|
|
|
|
// TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.1.0.allocation_id.id/]
|
|
|
|
// TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.0.0.allocation_id.id/]
|
2014-04-21 21:34:01 -04:00
|
|
|
|
|
|
|
This time the search will only be executed against two of the shards, because
|
|
|
|
routing values have been specified.
|
|
|
|
|
|
|
|
[float]
|
|
|
|
=== All parameters:
|
|
|
|
|
|
|
|
[horizontal]
|
|
|
|
`routing`::
|
|
|
|
A comma-separated list of routing values to take into account when
|
|
|
|
determining which shards a request would be executed against.
|
|
|
|
|
|
|
|
`preference`::
|
|
|
|
Controls a `preference` of which shard replicas to execute the search
|
|
|
|
request on. By default, the operation is randomized between the shard
|
2019-07-19 09:16:35 -04:00
|
|
|
replicas. See the link:search-request-body.html#request-body-search-preference[preference]
|
2014-04-21 21:34:01 -04:00
|
|
|
documentation for a list of all acceptable values.
|
|
|
|
|
|
|
|
`local`::
|
|
|
|
A boolean value whether to read the cluster state locally in order to
|
|
|
|
determine where shards are allocated instead of using the Master node's
|
2017-05-05 03:34:12 -04:00
|
|
|
cluster state.
|