Skip to content

Match queries become defacto match-all queries when used as a field caps index filter #131037

Open
@Mikep86

Description

@Mikep86

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 in doToQuery, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Search Foundations/SearchCatch all for Search Foundations:Search/SearchSearch-related issues that do not fall into other categories>bugTeam:SearchMeta label for search teamTeam:Search FoundationsMeta label for the Search Foundations team in Elasticsearch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions