Getting manual preferred/weighted results

Hey there,

I hope I'm in the right spot for my question.

I'm currently facing an issue that I think is easier than I make it out to be and I need some input on that.

We are consuming location data from several APIs, all of them return simple strings like "Cologne, DE", "New York, USA".

We also have a database that match those strings. Basically like so:
{ "city": "Cologne", "countryCode": "DE" }.

They are in sync with elastic search.

We prepare the query by splitting the comma, and get city/countryCode. This works so far. It's not a nice solution. But get's the job done.

However, some APIs only return city, missing the countryCode. There's nothing to be done about that. Searching for Cologne would also contain results from Texas, Minnesota and Virginia.

We know for sure which of those results are preferred, it's always Cologne in Germany, not somewhere in USA.

I guess this is where the scoring comes into play. And this is where I don't know the right solution.

Would I set some manual scoring value directly inside elastic, therefore edit each wanted result? It will most likely get overwritten with the next sync, right?

Would I create a new column like "preferred", import, and sort by preferred and score?
Does Elastic has it's own functionality which I can't seem to find?

I've searched a lot on that regard, and maybe I just don't find the right words? I do find information about weighting results, but it doesn't seem to apply to my issue.

Any help would be pretty much appreciated
Thank you all in advance!

You can indeed add a preferred field and use a bool query like:

POST _search
{
  "query": {
    "bool" : {
      "must" : {
        "match" : { "city" : "Cologne" }
      },
      "should" : [
        { "term" : { "preferred" : true } }
      ]
    }
  }
}
1 Like

Thank you, will do!

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