Searching with special characters

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:

{
   "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:

{
   "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:

[
   {
      "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:

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

Results (some useless fields removed):

      "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.

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