# CustomScoreQuery in ElasticSearch

**URL:** <https://discuss.elastic.co/t/customscorequery-in-elasticsearch/2268>\
**Category:** Elasticsearch\
**Created:** [June 10, 2015, 2:22am UTC](https://discuss.elastic.co/t/customscorequery-in-elasticsearch/2268 "2015-06-10T02:22:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CaoManhDat](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@CaoManhDat](https://discuss.elastic.co/u/CaoManhDat)\
**Post date:** [June 10, 2015, 2:22am UTC](https://discuss.elastic.co/t/customscorequery-in-elasticsearch/2268/1 "2015-06-10T02:22:15Z")

</div>

In Lucene i can using CustomScoreQuery to customize the score of Lucene search. So how to do similar thing in Elasticsearch.  
My case :

- Get field value from document
- Do some computation
- Elasticsearch score + my computation = new score

---

<div class="post-metadata">

**Author:** ![shinyke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinyke/32/587_2.png) [@shinyke](https://discuss.elastic.co/u/shinyke)\
**Post date:** [June 10, 2015, 2:37am UTC](https://discuss.elastic.co/t/customscorequery-in-elasticsearch/2268/2 "2015-06-10T02:37:13Z")

</div>

Hi ,CaoManhDat:

If you want to customize the score , may be you can use script score：  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#\_script\_score](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_script_score)

It can modify Elasticsearch score and add your computation like this：

```
"script_score" : {
    "script" : "_score * doc['my_numeric_field'].value"
}

```

you can also decide the script lang and use params：

```
"script_score": {
    "lang": "lang",
    "params": {
        "param1": value1,
        "param2": value2
     },
    "script": "_score * doc['my_numeric_field'].value / pow(param1, param2)"
}

```

wish that may help you.

Best regard ,  
shinyke

---

<div class="post-metadata">

**Author:** ![CaoManhDat](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@CaoManhDat](https://discuss.elastic.co/u/CaoManhDat)\
**Post date:** [June 12, 2015, 1:11am UTC](https://discuss.elastic.co/t/customscorequery-in-elasticsearch/2268/3 "2015-06-12T01:11:28Z")

</div>

Thanks you, but it no sufficient in my case. Because I need to transform field value in string -\> rank in integer (dynamically).

---

<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 6, 2017, 12:07am UTC](https://discuss.elastic.co/t/customscorequery-in-elasticsearch/2268/4 "2017-07-06T00:07:59Z")

</div>


