Skip to content

[BUG] Escaped wildcard character in wildcard query not handled correctly #15555

@HUSTERGS

Description

@HUSTERGS

Describe the bug

When use wildcard query on wildcard field, raw * (and maybe include raw ?), is not handled correctly, while the same wildcard query can work well on keyword field. Possibly the escape logic is not implemented in opensearch/index/mapper/WildcardFieldMapper.java.

Related component

Search

To Reproduce

  1. Create a simple index containing both wildcard and keyword type
    PUT escape_index
    {
      "mappings": {
        "properties": {
          "wild": {
            "type": "wildcard",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          }
        }
      }
    }
    
  2. Insert data with raw *
    POST escape_index/_doc
    {
      "wild": "* test *"
    }
    
  3. search on both field with the same wildcard query
    Search on KEYWORD type:
    GET escape_index/_search
    {
      "query": {
        "wildcard": {
          "wild.keyword": {
            "value": "\\**"
          }
        }
      }
    }
    
    Result:
    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": {
          "value": 1,
          "relation": "eq"
        },
        "max_score": 1,
        "hits": [
          {
            "_index": "escape_index",
            "_id": "xMi6opEB80UGmJnvgJSB",
            "_score": 1,
            "_source": {
              "wild": "* test *"
            }
          }
        ]
      }
    }
    
    Search on WILDCARD type
    GET escape_index/_search
    {
      "query": {
        "wildcard": {
          "wild": {
            "value": "\\**"
          }
        }
      }
    }
    
    Result:
    {
      "took": 1,
      "timed_out": false,
      "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": {
          "value": 0,
          "relation": "eq"
        },
        "max_score": null,
        "hits": []
      }
    }
    

Expected behavior

get the correct results when wildcard query contains raw * and ? characters

Additional Details

No response

Metadata

Metadata

Assignees

Labels

SearchSearch query, autocomplete ...etcbugSomething isn't working

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions