# Getting manual preferred/weighted results

**URL:** <https://discuss.elastic.co/t/getting-manual-preferred-weighted-results/249766>\
**Category:** Elasticsearch\
**Created:** [September 24, 2020, 8:19am UTC](https://discuss.elastic.co/t/getting-manual-preferred-weighted-results/249766 "2020-09-24T08:19:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![peepdurple](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@peepdurple](https://discuss.elastic.co/u/peepdurple)\
**Post date:** [September 24, 2020, 8:19am UTC](https://discuss.elastic.co/t/getting-manual-preferred-weighted-results/249766/1 "2020-09-24T08:19:52Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 24, 2020, 9:10am UTC](https://discuss.elastic.co/t/getting-manual-preferred-weighted-results/249766/2 "2020-09-24T09:10:33Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![peepdurple](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@peepdurple](https://discuss.elastic.co/u/peepdurple)\
**Post date:** [September 24, 2020, 9:50am UTC](https://discuss.elastic.co/t/getting-manual-preferred-weighted-results/249766/3 "2020-09-24T09:50:40Z")

</div>

Thank you, will do!

---

<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:** [October 22, 2020, 9:50am UTC](https://discuss.elastic.co/t/getting-manual-preferred-weighted-results/249766/4 "2020-10-22T09:50:49Z")

</div>

Closed on October 22, 2020, 9:50am UTC

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