# Query\_string query with asterisk and escaped char not working

**URL:** <https://discuss.elastic.co/t/query-string-query-with-asterisk-and-escaped-char-not-working/313181>\
**Category:** Elasticsearch\
**Created:** [August 29, 2022, 3:17pm UTC](https://discuss.elastic.co/t/query-string-query-with-asterisk-and-escaped-char-not-working/313181 "2022-08-29T15:17:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Lipnyagov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_lipnyagov/32/110210_2.png) [@Nick\_Lipnyagov](https://discuss.elastic.co/u/Nick_Lipnyagov)\
**Post date:** [August 29, 2022, 3:17pm UTC](https://discuss.elastic.co/t/query-string-query-with-asterisk-and-escaped-char-not-working/313181/1 "2022-08-29T15:17:45Z")

</div>

Hi everyone!

Could you please help me on how to use **query\_string** with \* and escaped characters?

For example:

Mapping:

```auto
{
  "index": "test_user_name",
  "mappings": {
    "properties": {
      "userId": {
        "type": "keyword"
      },
      "name": {
        "type": "text"
      }
    }
  }
}

```

Record that is stored in index:

```auto
{"userId": "1", "name": "AliceV!ABC"}

```

Query:

```auto
{
    "query": {
        "query_string": {
            "query": "*Alice* AND *V\\!*",
            "default_field": "name"
        }
    }
}

```

**Expected result** : stored record is returned.  
**Actual result** : record is not returned.

**Note** : without special chars everything works correct.

Following query (without escaped char returns expected result):

```auto
{
    "query": {
        "query_string": {
            "query": "*Alice* AND *V*",
            "default_field": "name"
        }
    }
}

```

Thanks in advance, Nick.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [August 29, 2022, 4:39pm UTC](https://discuss.elastic.co/t/query-string-query-with-asterisk-and-escaped-char-not-working/313181/2 "2022-08-29T16:39:44Z")

</div>

Hi @Nick_Lipnyagov

When you do not define the analyzer, elastic defaults to "standard" and this analyzer removes the characters like "!".

You can use the whitespace analyzer and get results with the query you are trying to run.

```auto
{
  "mappings": {
    "properties": {
      "userId": {
        "type": "keyword"
      },
      "name": {
        "analyzer": "whitespace",
        "type": "text"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Nick\_Lipnyagov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_lipnyagov/32/110210_2.png) [@Nick\_Lipnyagov](https://discuss.elastic.co/u/Nick_Lipnyagov)\
**Post date:** [August 30, 2022, 2:41pm UTC](https://discuss.elastic.co/t/query-string-query-with-asterisk-and-escaped-char-not-working/313181/3 "2022-08-30T14:41:25Z")

</div>

Thanks, now it's much clearer how it works!

---

<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:** [September 27, 2022, 2:41pm UTC](https://discuss.elastic.co/t/query-string-query-with-asterisk-and-escaped-char-not-working/313181/4 "2022-09-27T14:41:45Z")

</div>

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