Wildcard/regexp query with asterix chacter

Hi,
I'm new to elasticsearch. I would write a query, that matches a document with the following attribute:

description: 20*40x555

I want the query matches with the following inputs:

  • 20X40X555
  • 20*40*555
  • 20x40x555
  • the combination of these

I tired the wildcard, and the regex query also. If the document's attribute does not contains any asterix characters the query works fine, but when the description attribute contains an * character it does not find.

I tried with the following queries:

with wildcard:

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "short_description": "*20?40?555*"
          }
        }
      ]
    }
  }
}

with regexp:

{
  "query": {
    "bool": {
      "must": [
        {
          "regexp": {
            "short_description": ".*20.*40.*555.*"
          }
        }
      ]
    }
  }
}

When the short attribute is ex 20x40x555 both of these working, but if I change the value to 20*40x555 it does not returns the document unfortunately.

How can I achieve to get results when the value of the sort_description is eg. 20*40x555 ? Thanks!

What's the mapping of your field? If it's text try searching the same content against a keyword field. If you've used default mappings you may have short_description.keyword already mapped.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.