[BUG] _field_caps with index_filter silently omits indices whose shards could not be checked
Describe the bug
_field_caps with an index_filter leaves an index out of indices when it couldn't evaluate the filter on that index's unavailable shards, and reports nothing about it: failed_indices and failures are both null. A caller can't tell "this index has no documents matching the filter" apart from "some of this index's shards couldn't be checked".
_search with the same query does report the gap, in _shards (successful < total).
This breaks index pruning in the SQL plugin (opensearch-project/sql#5808). It uses _field_caps + index_filter to skip indices that can't match a query's time range, so an index with in-range data on an unavailable shard is pruned, and the query returns an incomplete result with no error and no _shards gap to report.
Related component
Search
To Reproduce
Two data nodes. One index with two shards, one per node; the in-range documents sit only on the shard of the node that will be stopped:
PUT dcm-mixed
{ "settings": { "number_of_shards": 2, "number_of_replicas": 0,
"index.routing.allocation.total_shards_per_node": 1 },
"mappings": { "properties": { "@timestamp": { "type": "date" } } } }
# pick routing values that land on each shard (GET dcm-mixed/_search_shards?routing=<k>)
# shard on node-1: only old documents; shard on node-2: only recent documents
POST dcm-mixed/_bulk?routing=<k-node1>&refresh=true # 50 docs, @timestamp 40-60 days ago
POST dcm-mixed/_bulk?routing=<k-node2>&refresh=true # 80 docs, @timestamp within the last day
PUT dcm-healthy # 1 shard pinned to node-1, 100 docs within the last dayStop node-2, so dcm-mixed shard 0 is UNASSIGNED and shard 1 is STARTED.
POST dcm-*/_field_caps?fields=@timestamp
{ "index_filter": { "range": { "@timestamp": { "gte": "now-1d", "lte": "now" } } } }Expected behavior
The response should say dcm-mixed couldn't be fully evaluated, for example with a per-index failures entry or a _shards-style summary like _search returns, instead of leaving it out as if it were proven not to match.
Actual behavior
Measured on 3.10.0-SNAPSHOT:
| Request | Result |
|---|---|
_field_caps with index_filter |
indices: ["dcm-healthy"], failed_indices: null, failures: null |
_field_caps without a filter |
indices: ["dcm-healthy", "dcm-mixed"], failed_indices: null, failures: null |
_search with the same range, size: 0 |
hits: 100, _shards: { total: 3, successful: 2, failed: 0 } |
dcm-mixed is dropped from the filtered response, but it holds 80 in-range documents on the unavailable shard. The unfiltered response lists it because its other shard answers, so comparing the two calls can't detect the gap either.
The same happens, more simply, when every shard of an index is unavailable: the index is missing from both responses, again with no failure reported.
Additional Details
- The SQL plugin works around the whole-index case in opensearch-project/sql#5819 by treating any index absent from an unfiltered probe as unreadable and keeping it. It can't work around the shard-level case above.
- Reading the routing table or cluster health would reveal unavailable shards, but needs
cluster:monitor/stateorcluster:monitor/health, which index-scoped roles usually don't have. So a caller holding only index-level read permissions can't get this information any other way.
Source: opensearch-project/OpenSearch