# Wildcard/regexp query with asterix chacter

**URL:** <https://discuss.elastic.co/t/wildcard-regexp-query-with-asterix-chacter/362153>\
**Category:** Elastic Search\
**Created:** [June 27, 2024, 12:06pm UTC](https://discuss.elastic.co/t/wildcard-regexp-query-with-asterix-chacter/362153 "2024-06-27T12:06:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaaba](https://avatars.discourse-cdn.com/v4/letter/k/c5a1d2/32.png) [@kaaba](https://discuss.elastic.co/u/kaaba)\
**Post date:** [June 27, 2024, 12:06pm UTC](https://discuss.elastic.co/t/wildcard-regexp-query-with-asterix-chacter/362153/1 "2024-06-27T12:06:40Z")

</div>

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:

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

```

with regexp:

```auto
{
  "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!

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [June 27, 2024, 7:08pm UTC](https://discuss.elastic.co/t/wildcard-regexp-query-with-asterix-chacter/362153/2 "2024-06-27T19:08:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 25, 2024, 7:09pm UTC](https://discuss.elastic.co/t/wildcard-regexp-query-with-asterix-chacter/362153/3 "2024-07-25T19:09:02Z")

</div>

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