term and wildcard queries already create either a MatchAllDocsQuery or a MatchNoDocsQuery at the shard level depending on the index name and its aliases. See IndexFieldType#termQuery and IndexFieldType#wildcardQuery for details.
It would be nice to go further and handle these in TermQueryBuilder#rewrite and WildcardQueryBuilder#rewrite. The benefit is that if someone queries index foo with a filter on { "term": { "_index": "bar" } }, then the top-level query will rewrite to a MatchNoDocsQuery, which is exactly the information that the can_match phase leverages in order to skip shards.
It would be a convenient and efficient way for Kibana to filter on a subset of data streams that are configured in the index patterns.
termandwildcardqueries already create either aMatchAllDocsQueryor aMatchNoDocsQueryat the shard level depending on the index name and its aliases. SeeIndexFieldType#termQueryandIndexFieldType#wildcardQueryfor details.It would be nice to go further and handle these in
TermQueryBuilder#rewriteandWildcardQueryBuilder#rewrite. The benefit is that if someone queries indexfoowith a filter on{ "term": { "_index": "bar" } }, then the top-level query will rewrite to aMatchNoDocsQuery, which is exactly the information that thecan_matchphase leverages in order to skip shards.It would be a convenient and efficient way for Kibana to filter on a subset of data streams that are configured in the index patterns.