Skip to content

Wildcard queries should not normalize/remove wildcards in queries #46300

@talevy

Description

@talevy

Wildcard queries should not normalize wildcards from queries

Example scenario where wildcard queries do not exhibit expected behavior:

PUT my-index
{
  "mappings": {
    "_doc": {
      "properties": {
        "foo": {
          "type": "keyword",
          "normalizer": "no_wildcard"
        }
      }
    }
  },
  "settings": {
    "index": {
      "analysis": {
        "char_filter": {
          "no_wildcard": {
            "pattern": "[\\*]",
            "type": "pattern_replace",
            "replacement": ""
          }
        },
        "normalizer": {
          "no_wildcard": {
            "type": "custom",
            "char_filter": "no_wildcard"
          }
        }
      }
    }
  }
}

PUT /my-index/_doc/1
{
    "foo": "bar"
}

GET my-index/_search
{
  "profile": true,
  "query": {
    "wildcard": {
      "foo": {
        "value": "ba*"
      }
    }
  }
}

The resulting input that is provided to the wildcard query removes the *.

// output from the query profiler for above query
...
             {
                "type" : "MultiTermQueryConstantScoreWrapper",
                "description" : "foo:ba",
...

Because of this, the search does not find any matching documents.

I believe this relates to #28894.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions