# Optimization of function\_score's functions clause to adjust scores for a range of specific fields

**URL:** <https://discuss.elastic.co/t/optimization-of-function-scores-functions-clause-to-adjust-scores-for-a-range-of-specific-fields/307015>\
**Category:** Elasticsearch\
**Created:** [June 13, 2022, 10:29am UTC](https://discuss.elastic.co/t/optimization-of-function-scores-functions-clause-to-adjust-scores-for-a-range-of-specific-fields/307015 "2022-06-13T10:29:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuki\_Akano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuki_akano/32/106930_2.png) [@Yuki\_Akano](https://discuss.elastic.co/u/Yuki_Akano)\
**Post date:** [June 13, 2022, 10:29am UTC](https://discuss.elastic.co/t/optimization-of-function-scores-functions-clause-to-adjust-scores-for-a-range-of-specific-fields/307015/1 "2022-06-13T10:29:53Z")

</div>

Hi everyone,

I want to adjust the score according to the range of a particular field in function\_score.  
For example, I have the following query in mind.

```auto
{
   "query":{
      "function_score":{
         "query": { ....hogehoge }
      },
      "functions":[
         {
            "filter":{
               "range":{
                  "lastLogin":{
                     "lte":"2022-05-29T06:58:53.652Z"
                  }
               }
            },
            "weight":1
         },
         {
            "filter":{
               "range":{
                  "lastLogin":{
                     "gte":"2022-05-29T06:58:53.652Z",
                     "lte":"2022-05-30T06:58:53.652Z"
                  }
               }
            },
            "weight":2
         },
         {
            "filter":{
               "range":{
                  "lastLogin":{
                     "gte":"2022-05-30T06:58:53.652Z",
                     "lte":"2022-05-31T06:58:53.652Z"
                  }
               }
            },
            "weight":3
         },
         ..... and more
      ],
      "score_mode":"sum"
   }
}

```

However, I'm afraid this writing style is not performing well  
Is there any efficient way to write it?  
The version of ES used is 6.8.12

Thank you.

---

<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:** [July 11, 2022, 10:30am UTC](https://discuss.elastic.co/t/optimization-of-function-scores-functions-clause-to-adjust-scores-for-a-range-of-specific-fields/307015/2 "2022-07-11T10:30:04Z")

</div>

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