# How to create mapping for special characters and autocomplete search

**URL:** <https://discuss.elastic.co/t/how-to-create-mapping-for-special-characters-and-autocomplete-search/324115>\
**Category:** Elasticsearch\
**Created:** [January 27, 2023, 3:00pm UTC](https://discuss.elastic.co/t/how-to-create-mapping-for-special-characters-and-autocomplete-search/324115 "2023-01-27T15:00:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ismet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ismet/32/103499_2.png) [@Ismet](https://discuss.elastic.co/u/Ismet)\
**Post date:** [January 27, 2023, 3:00pm UTC](https://discuss.elastic.co/t/how-to-create-mapping-for-special-characters-and-autocomplete-search/324115/1 "2023-01-27T15:00:45Z")

</div>

Hi,

In my project, I need to search data with special characters like č,ć,ž,đ, ?, !.

What is the best practice for searching special characters in version 8.5?

Also, how to create a mapping for autocomplete search? How to put together special characters and autocomplete features?

Thanks.

---

<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:** [January 28, 2023, 6:50pm UTC](https://discuss.elastic.co/t/how-to-create-mapping-for-special-characters-and-autocomplete-search/324115/2 "2023-01-28T18:50:57Z")

</div>

Hi @Ismet

Could you give more details about how this autocomplete should work, some documents can help too.  
With that I could help you.

---

<div class="post-metadata">

**Author:** ![Ismet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ismet/32/103499_2.png) [@Ismet](https://discuss.elastic.co/u/Ismet)\
**Post date:** [January 30, 2023, 12:42pm UTC](https://discuss.elastic.co/t/how-to-create-mapping-for-special-characters-and-autocomplete-search/324115/3 "2023-01-30T12:42:45Z")

</div>

Hi @RabBit_BR ,

I use multiple fields for text search (10 fields), those fields have letters, digits, and special characters like -,/,&,č,ć,š,ž,đ.

The string needs to be long min 3 characters and needs to find a result if the string is in the middle of words (search string "or" need to find "word").

Search should include both uppercase and lowercase letters, and blank space.

---

<div class="post-metadata">

**Author:** ![Ismet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ismet/32/103499_2.png) [@Ismet](https://discuss.elastic.co/u/Ismet)\
**Post date:** [February 1, 2023, 9:47am UTC](https://discuss.elastic.co/t/how-to-create-mapping-for-special-characters-and-autocomplete-search/324115/4 "2023-02-01T09:47:07Z")

</div>

> [@Ismet](#):
>
> The string needs to be long min 3 characters and needs to find a result if the string is in the middle of words (search string "or" need to find "word").
> 
> Search should include both uppercase and lowercase letters, and blank space.

Is this good solution if i have 10 fileds for full text search and autocomplete search?

```auto
PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "icu_tokenizer",
          "filter": [
            "lowercase",
            "icu_normalizer"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "my_field": {
        "type": "text",
        "analyzer": "my_analyzer",
        "fields": {
          "keyword": {
            "type": "keyword"
          },
          "completion": {
            "type": "completion",
            "analyzer": "my_analyzer",
            "search_analyzer": "my_analyzer",
            "min_input_length": 3
          }
        }
      }
    }
  }
}

```

---

<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:** [February 1, 2023, 5:28pm UTC](https://discuss.elastic.co/t/how-to-create-mapping-for-special-characters-and-autocomplete-search/324115/5 "2023-02-01T17:28:00Z")

</div>

Hi @Ismet

I like to use completion suggester as autocomplete solution. Currently my application uses the completion suggester in two fields, in your case it will be 10.

It is worth remembering that you will have to create the inputs for the 10 fields, I don't know if it will be too much work for you, but in fact this solution works.

There are other options like "search-as-you-type" that can also serve this scenario.

I imagined an option (I don't know if it's possible because I haven't tested it), you use copy\_to in the 10 fields and copy the values to a single destination field, this destination field can be of the "search-as-you-type" type . So you write a query using only one field that has the values of 10 fields copied.

When searching for full text I recommend having another query for this purpose.

---

<div class="post-metadata">

**Author:** ![Ismet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ismet/32/103499_2.png) [@Ismet](https://discuss.elastic.co/u/Ismet)\
**Post date:** [February 3, 2023, 2:14pm UTC](https://discuss.elastic.co/t/how-to-create-mapping-for-special-characters-and-autocomplete-search/324115/6 "2023-02-03T14:14:06Z")

</div>

Hi @RabBit_BR, that is a good idea to make one runtime copy\_to filed.

search-as-you-type doesn't support special characters like č,ć,š...

In this case, mapping is like this:

```auto
PUT my_index
{
  "mappings": {
    "properties": {
      "field_name": {
        "type": "text",
        "analyzer": ["search_as_you_type_analyzer", "special_char_analyzer"]
      }
    }
  },
  "settings": {
    "analysis": {
      "analyzer": {
        "search_as_you_type_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "nGram"
          ]
        },
       "special_char_analyzer": {
          "tokenizer": "icu_tokenizer",
          "filter": [
            "lowercase",
            "icu_normalizer"
          ]
        }
      },
      "filter": {
        "nGram": {
          "type": "nGram",
          "min_gram": 1,
          "max_gram": 20,
          "token_chars": [
            "letter",
            "digit",
            "punctuation",
            "symbol"
          ]
        }
      }
    }
  }
}

```

---

<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:** [March 3, 2023, 2:14pm UTC](https://discuss.elastic.co/t/how-to-create-mapping-for-special-characters-and-autocomplete-search/324115/7 "2023-03-03T14:14:27Z")

</div>

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