# Plug-in Java or Python or Scala function to re-calculate document score?

**URL:** <https://discuss.elastic.co/t/plug-in-java-or-python-or-scala-function-to-re-calculate-document-score/25545>\
**Category:** Elasticsearch\
**Created:** [July 14, 2015, 6:31pm UTC](https://discuss.elastic.co/t/plug-in-java-or-python-or-scala-function-to-re-calculate-document-score/25545 "2015-07-14T18:31:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 14, 2015, 6:31pm UTC](https://discuss.elastic.co/t/plug-in-java-or-python-or-scala-function-to-re-calculate-document-score/25545/1 "2015-07-14T18:31:57Z")

</div>

Hello ElasticSearch experts,

Is it possible to plug-in Java or Python or Scala customized function (any one of them is ok) into ElasticSearch cluster, so that for each returned documents, we can use the customized function to calculate a document score based on fields of documents? And return ordered document based on customized function score?

If so, any samples is appreciated.

thanks in advance,  
Lin

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [July 14, 2015, 6:48pm UTC](https://discuss.elastic.co/t/plug-in-java-or-python-or-scala-function-to-re-calculate-document-score/25545/2 "2015-07-14T18:48:30Z")

</div>

> [@linlma](#):
>
> function score

> **[Function Score Query | Elasticsearch Guide \[1.6\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/1.6/query-dsl-function-score-query.html#function-script-score)**

See the script\_score. You can use a native script if you are ok with deploying it into Elasticsearch's classpath. If its simple enough you can use "expression" which is the Lucene Expression language. Its plenty for lots of use cases and its fast and sandboxed.

---

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 14, 2015, 8:03pm UTC](https://discuss.elastic.co/t/plug-in-java-or-python-or-scala-function-to-re-calculate-document-score/25545/3 "2015-07-14T20:03:31Z")

</div>

Thanks Nik,

Is there a guide how to write a sample native script and deploy into Elasticsearch's class path, and leverage it during query?

BTW, I have another question on customized scoring, and if you could comment, it will be great,

> [@Calculate top common fields for matched documents](https://discuss.elastic.co/t/calculate-top-common-fields-for-matched-documents/25546):
>
> Hello Elastic Search experts, I want to calculate top common fields, and their values for matched documents for a query, other than return the matched document itself. I want to calculate top common fields by a customized function (could be implemented by Java/Python or Scala). The question is, is it possible to plug-in the customized function inside ElasticSearch cluster? Which has the benefit of saving bandwidth to transfer all documents back (which is huge number), v.s. only return top comm…

regards,  
Lin

---

<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:01am UTC](https://discuss.elastic.co/t/plug-in-java-or-python-or-scala-function-to-re-calculate-document-score/25545/4 "2017-07-06T00:01:30Z")

</div>


