# Searching with special characters

**URL:** <https://discuss.elastic.co/t/searching-with-special-characters/253083>\
**Category:** Elasticsearch\
**Created:** [October 23, 2020, 4:08am UTC](https://discuss.elastic.co/t/searching-with-special-characters/253083 "2020-10-23T04:08:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Pravdin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_pravdin/32/45475_2.png) [@Alex\_Pravdin](https://discuss.elastic.co/u/Alex_Pravdin)\
**Post date:** [October 23, 2020, 4:08am UTC](https://discuss.elastic.co/t/searching-with-special-characters/253083/1 "2020-10-23T04:08:53Z")

</div>

I'm trying to make an autocomplete search that will account for special characters and add weights to the results which match a query with these characters.

Index:

```auto
{
   "institution_test":{
      "settings":{
         "index":{
            "analysis":{
               "filter":{
                  "autocomplete_filter":{
                     "type":"ngram",
                     "min_gram":"2",
                     "max_gram":"14"
                  }
               },
               "analyzer":{
                  "autocomplete":{
                     "type":"custom",
                     "filter":[
                        "lowercase",
                        "asciifolding",
                        "autocomplete_filter"
                     ],
                     "tokenizer":"whitespace"
                  }
               }
            }
         }
      }
   }
}

```

Mapping:

```auto
{
   "institution_test":{
      "mappings":{
         "default":{
            "properties":{
               "local_name":{
                  "type":"text",
                  "copy_to":[
                     "search_by_name"
                  ],
                  "analyzer":"autocomplete",
                  "search_analyzer":"standard"
               },
               "name":{
                  "type":"text",
                  "copy_to":[
                     "search_by_name"
                  ],
                  "analyzer":"autocomplete",
                  "search_analyzer":"standard"
               },
               "search_by_name":{
                  "type":"text",
                  "analyzer":"autocomplete",
                  "search_analyzer":"standard"
               }
            }
         }
      }
   }
}

```

Documents:

```auto
[
   {
      "name":"Adam SMITH"
   },
   {
      "name":"Abd MIT Abd"
   },
   {
      "name":"Massachusetts (MIT)"
   },
   {
      "name":"MI TOO"
   }
]

```

Task: to pull up rows which contain `(MIT)`, next `MIT` as a separate word, next partial matches.

Search query:

```auto
http://localhost:9200/institution_test/_search?q=search_by_name:\(mit\)

```

Results (some useless fields removed):

```auto
      "hits":[
         {
            "_score":0.5691198,
            "_source":{
               "name":"Adam SMITH"
            }
         },
         {
            "_score":0.5691198,
            "_source":{
               "name":"Massachusetts (MIT)"
            }
         },
         {
            "_score":0.55140024,
            "_source":{
               "name":"Abd MIT Abd"
            }
         }
      ]

```

Why `Adam SMITH` which is a partial match has the highest position? Why it has the weight identical to the second row?

How to make the results as follows and all rows have different weights?

- `Massachusetts (MIT)`
- `Abd MIT Abd`
- `Adam SMITH`

Thanks.

---

<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:** [November 20, 2020, 4:09am UTC](https://discuss.elastic.co/t/searching-with-special-characters/253083/2 "2020-11-20T04:09:07Z")

</div>

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