Query hints - make some records more important than others

Let say I have an index of cities: cities_ind. I'm querying this data with search_at_you_type to get the best recommendation while typing. Then, I want to make a few of them more important than others. The biggest cities, like Cracow, Warsaw, Gdansk are to be preferable over other cities with the same starting letters.

My mapping is:

{
   "mappings":{
      "properties":{
         "city_name":{
            "type":"search_as_you_type"
         },
         "city_name_txt":{
            "type":"keyword",
            "fields":{
               "keyword":{
                  "type":"keyword",
                  "ignore_above":256
               }
            }
         }
      }
   }
}

(cities_ind_txt is for collapse used in query)

And my query is:

{
   "size":10,
   "sort":[
      {
         "_score":"desc"
      }
   ],
   "query":{
      "multi_match":{
         "query": f'{key}',
         "fuzziness":2,
         "type":"best_fields",
         "fields":[
            "city_name",
            "city_name._indiex_prefix",
            "city_name._2gram",
            "city_name._3gram"
         ]
      }
   },
   "collapse":{
      "field":"city_name_txt.keyword"
   }
}

One idea is to add a special field with weights, but it would implicate database structure changing. Any other options? Like array of important keywords? Or may be it is possible to add weights while indexing (loading data from db)?

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