Boosting documents in search results which are matched to array

Hi all,
I have this relatively complex search query that's already being built and working with perfect sorting.

But I think here searching is slow just because of script so all I want to remove script and write query accordingly.

current code :-

"sort": [
{
  "_script": {
    "type": "number",
    "script": {
      "lang": "painless",
      "source": "double pscore = 0;for(id in params.boost_ids){if(params._source.midoffice_master_id == id){pscore = -999999999;}}return pscore;",
      "params": {
        "boost_ids": [
         3,
         4,
         5
        ]
      }
    }
  }
},
{
  "_geo_distance": {
    "location": {
      "lat": -8.435345,
      "lon": 103.184316
    },
    "order": "asc"
  }
}
```

] }

Above code explaination:-

For example, if an emtpy match query would give a result like:

[{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, ...]

So here I implemented sorting which has script which take array and then from array if any element matched with the id of searched result get boost and appear to top with minimum distance(which is calculated with geo_distance query)

Like provide array [3, 4, 5] which would then transform the result into:

[{id: 3}, {id: 4}, {id: 5}, {id: 1}, {id: 2}, ...]

Please help me with this situation and to remove script from query.

Thanks in advance. :slight_smile:

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