Skip to content

[BUG] Wildcard Query: Escaped Backslash before operator #19719

@lumaier

Description

@lumaier

Describe the bug

An escaped backslash directly in front of the wildcard operator * is not correctly handled.

Related component

Search:Query Capabilities

To Reproduce

  1. Create an index with a wildcard field:
curl -X PUT "http://localhost/my-index" -H 'Content-Type: application/json' -d'
{
    "mappings": {
        "properties": {
            "wildcard_field": {
                "type": "wildcard"
            }
        }
    }
}
'
  1. Insert a document containing a backslash:
curl -X POST "http://localhost/my-index/_doc/1" -H 'Content-Type: application/json' -d'
{
  "wildcard_field": "some\\string"
}
'
  1. Query the document:

This query correctly returns the document:

curl -X GET "http://localhost/my-index/search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "wildcard": {
      "wildcard_field": {
        "value": "*some\\\\str*"
      }
    }
  }
}
'

But this query returns nothing (even tough it should return the same document):

curl -X GET "http://localhost/my-index/search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "wildcard": {
      "wildcard_field": {
        "value": "*some\\\\*"
      }
    }
  }
}
'

Expected behavior

An escaped backslash before the operator * in a wildcard query must be treated as the literal character \.

Additional Details

Plugins
None

Screenshots
None

Host/Environment (please complete the following information):

  • OS: Docker image (Host: Linux Ubuntu 24)
  • Version docker.io/opensearchproject/opensearch:3.2.0 and docker.io/opensearchproject/opensearch:3.3.0

Additional context
None

Metadata

Metadata

Assignees

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions