# Search any term startswith including special char

**URL:** <https://discuss.elastic.co/t/search-any-term-startswith-including-special-char/349288>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [December 13, 2023, 5:48pm UTC](https://discuss.elastic.co/t/search-any-term-startswith-including-special-char/349288 "2023-12-13T17:48:07Z")\
**Posts on this page:** 6\
**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:** [December 13, 2023, 5:48pm UTC](https://discuss.elastic.co/t/search-any-term-startswith-including-special-char/349288/1 "2023-12-13T17:48:07Z")

</div>

Hello All,  
I have a field called title and it has value  
"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.  
Query used  
query\_string : {  
"fields": ["title", "title.keyword"],  
"query": "^oo\* %ic\*"  
}

if I use pe\* then it fetches the documents

---

<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:** [December 13, 2023, 6:13pm UTC](https://discuss.elastic.co/t/search-any-term-startswith-including-special-char/349288/2 "2023-12-13T18:13:49Z")

</div>

Hi there @Sankar_S , it sounds like you might want to use the [Whitespace analyzer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-whitespace-analyzer.html) as the default analysis chain will strip out special characters.

---

<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:** [December 13, 2023, 6:49pm UTC](https://discuss.elastic.co/t/search-any-term-startswith-including-special-char/349288/3 "2023-12-13T18:49:38Z")

</div>

The field uses

```auto
"title" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" : "keyword"
            }
          },
          "analyzer" : "en_us_analyzer"
        },

```

```auto
"en_us_analyzer" : {
              "filter" : [
                "lowercase",
                "porter_stem",
                "asciifolding",
                "stop"
              ],
              "char_filter" : [
                "html_strip"
              ],
              "tokenizer" : "standard"
            }`Preformatted text`

```

reindexing it with whitespace tokenizer is the only possibility to solve this requirement?

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [December 15, 2023, 3:06pm UTC](https://discuss.elastic.co/t/search-any-term-startswith-including-special-char/349288/4 "2023-12-15T15:06:15Z")

</div>

hi there,

another option is you use the keyword field (non analyzed) and use a prefix match if you want to match on "starts with"

---

<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:** [December 15, 2023, 4:48pm UTC](https://discuss.elastic.co/t/search-any-term-startswith-including-special-char/349288/5 "2023-12-15T16:48:45Z")

</div>

requirement is to find document starts with any term/word in the field value.

---

<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:** [January 12, 2024, 4:48pm UTC](https://discuss.elastic.co/t/search-any-term-startswith-including-special-char/349288/6 "2024-01-12T16:48:54Z")

</div>

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