# Use function\_score with index.sort to get top X and rescore on those

**URL:** <https://discuss.elastic.co/t/use-function-score-with-index-sort-to-get-top-x-and-rescore-on-those/359575>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [May 15, 2024, 8:19pm UTC](https://discuss.elastic.co/t/use-function-score-with-index-sort-to-get-top-x-and-rescore-on-those/359575 "2024-05-15T20:19:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmlucjav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmlucjav/32/5870_2.png) [@jmlucjav](https://discuss.elastic.co/u/jmlucjav)\
**Post date:** [May 15, 2024, 8:19pm UTC](https://discuss.elastic.co/t/use-function-score-with-index-sort-to-get-top-x-and-rescore-on-those/359575/1 "2024-05-15T20:19:58Z")

</div>

Hi,

I have a field 'mysort', I can declare it float, rankfeature...whatever I want.

I use it for index sort:

```auto
{
  "settings": {
    "index": {
      "sort.field": "mysort", 
      "sort.order": "desc"  
    }
  },

```

And now I want to run a query such that:

```auto
    "query": {
        "function_score": {
            "functions": [{ "field_value_factor": { "field": "mysort", "factor": 0.5, "modifier": "ln1p"}}],
            "query": {....}
     },
     "rescore" : {
        "window_size" : 200,
        "query" : { "rescore_query" : {... }, "query_weight" : 0.7, "rescore_query_weight" : 1.2 }
     }

```

- use a function\_score with field\_value\_factor and some filters
- the index sort field is used to get top X docs, without touching the rest
- and those are then rescored with a 'rescore' query that is much more complex and slow, with some painless and such.

But I am struggling to find the way, not sure it's possible? As I am not 'sorting' per se, not sure if the index sort would be used if I use function\_score??

Any other idea??

thanks
