# How to use "function\_score" mehod to modify the score for a document?

**URL:** https://discuss.elastic.co/t/how-to-use-function-score-mehod-to-modify-the-score-for-a-document/21842
**Category:** Elasticsearch
**Created:** [January 26, 2015, 11:35pm UTC](https://discuss.elastic.co/t/how-to-use-function-score-mehod-to-modify-the-score-for-a-document/21842 "2015-01-26T23:35:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Panzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panzer/32/927_2.png) [@Panzer](https://discuss.elastic.co/u/Panzer)
#### Post date: [January 26, 2015, 11:35pm UTC](https://discuss.elastic.co/t/how-to-use-function-score-mehod-to-modify-the-score-for-a-document/21842/1 "2015-01-26T23:35:25Z")

</div>

I have this JSON object where I wish to change the scoring function of the  
search query:

POST /index/document/\_search  
{  
"query": {  
"function\_score": {  
"query": {"match": {"\_all": "fox"}},  
"script\_score": {  
"script": "\_score"  
}  
}  
}  
}

I want to change the score function so that it multiplies the TF and IDF of  
the term "fox". I ran a search query with "\_explain" set to true and in the  
explanantion part I got this:

"\_explanation": {  
"value": 1.110572,  
"description": "weight(text:fox in 76) [PerFieldSimilarity], result of:",  
"details": [  
{  
"value": 1.110572,  
"description": "fieldWeight in 76, product of:",  
"details": [  
{  
"value": 1,  
"description": "tf(freq=1.0), with freq of:",  
"details": [  
{  
"value": 1,  
"description": "termFreq=1.0"  
}  
]  
},  
{  
"value": 4.442288,  
"description": "idf(docFreq=123, maxDocs=3453)"  
},  
{  
"value": 0.25,  
"description": "fieldNorm(doc=76)"  
}  
]  
}  
]  
}

How can use the values of IDF and TF to change the actual score of the  
document?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6bb5b692-da40-4e2a-9221-40ccad5c5f6f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6bb5b692-da40-4e2a-9221-40ccad5c5f6f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:36am UTC](https://discuss.elastic.co/t/how-to-use-function-score-mehod-to-modify-the-score-for-a-document/21842/2 "2017-07-06T00:36:33Z")

</div>


