# Search Special char support

**URL:** <https://discuss.elastic.co/t/search-special-char-support/352058>\
**Category:** Elasticsearch\
**Created:** [January 30, 2024, 6:12am UTC](https://discuss.elastic.co/t/search-special-char-support/352058 "2024-01-30T06:12:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sankar\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sankar_s/32/112213_2.png) [@Sankar\_S](https://discuss.elastic.co/u/Sankar_S)\
**Post date:** [January 30, 2024, 6:12am UTC](https://discuss.elastic.co/t/search-special-char-support/352058/1 "2024-01-30T06:12:26Z")

</div>

Hello All,  
I have a field called title and it has value

```auto
"title" : "Toddler- $kitkat @taste &roll ^yart !here #you %ice ^oops *jam (pot) [beat] pep |old {jet} `egg /lol"

```

For given input i would like to match any term startswith the given input.  
For example If i give #yo or ^oop or %ic it has to return the above document  
query\_string with field type text works for the above use case if no special char is there but with specical char it is not working. How to solve the usecase.  
I used whitespace\_analyser for keyword field.  
The query not working fine for chars like ^, !, {, [, (, ), },] and /  
Query used

```auto
query_string : {
"fields": ["title.keyword"],
"query": "(* {*"
}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 30, 2024, 6:17am UTC](https://discuss.elastic.co/t/search-special-char-support/352058/2 "2024-01-30T06:17:59Z")

</div>

Have you tried using an [edge\_ngram token filter](https://www.elastic.co/guide/en/elasticsearch/reference/8.12/analysis-edgengram-tokenfilter.html#analysis-edgengram-tokenfilter) together with a [whitespace tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/8.12/analysis-whitespace-tokenizer.html)? That way you would not need to use wildcards in your query string either.

---

<div class="post-metadata">

**Author:** ![yago82](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yago82/32/97755_2.png) [@yago82](https://discuss.elastic.co/u/yago82)\
**Post date:** [January 30, 2024, 9:35am UTC](https://discuss.elastic.co/t/search-special-char-support/352058/3 "2024-01-30T09:35:45Z")

</div>

Hi,

In Elasticsearch, certain characters are considered special and need to be escaped with a backslash (`\` ). These special characters are: `+ - = && || > < ! ( ) { } [] ^ " ~ * ? : \ /` .

you can modify your query to escape the special characters:

```auto
{
  "query": {
    "query_string" : {
      "fields": ["title.keyword"],
      "query": "\\(\\* \\{\\*"
    }
  }
}

```

Regards

---

<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:** [February 27, 2024, 9:36am UTC](https://discuss.elastic.co/t/search-special-char-support/352058/4 "2024-02-27T09:36:08Z")

</div>

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