Open
Description
Elasticsearch Version
main
Installed Plugins
No response
Java Version
bundled
OS Version
n/a
Problem Description
match
queries get translated into defacto match-all queries when they are used as field caps index filters. This happens because of a confluence of two implementation details:
- Field caps considers an index filter a match on a shard if it does not rewrite to
match_none
(see here). - The
match
query does not check if it can be applied to a field until after the rewrite cycle is complete. The check occurs indoToQuery
, which is not executed by the field caps index filter code path.
Steps to Reproduce
PUT test-index
{
"mappings": {
"properties": {
"text": {
"type": "text"
}
}
}
}
PUT test-index-2
{
"mappings": {
"properties": {
"text": {
"type": "text"
}
}
}
}
PUT test-index/_doc/1
{
"text": "foo"
}
PUT test-index-2/_doc/2
{
"text": "bar"
}
// Index filter should only match test-index
// Returns both test-index and test-index-2
GET /_field_caps?types=&ignore_unavailable=true&allow_no_indices=true&index=*&fields=*&expand_wildcards=open
{
"index_filter": {
"match": {
"text": {
"query": "foo"
}
}
}
}
// Index filter shouldn't match either index
// Returns both test-index and test-index-2
GET /_field_caps?types=&ignore_unavailable=true&allow_no_indices=true&index=*&fields=*&expand_wildcards=open
{
"index_filter": {
"match": {
"baz": {
"query": "space"
}
}
}
}
Logs (if relevant)
No response