# How ElasticSearch supporting customized ranking

**URL:** <https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000>\
**Category:** Elasticsearch\
**Created:** [July 7, 2015, 12:59am UTC](https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000 "2015-07-07T00:59:14Z")\
**Posts on this page:** 8\
**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 7, 2015, 12:59am UTC](https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000/1 "2015-07-07T00:59:14Z")

</div>

Hello Elastic experts,

For each record, it has a few float features, and want to rank the results by linear combination of features.

For example,

User 1 has feature 1 with value is 0.1, and feature 2 with value 0.2;  
User 2 has feature 1 with value is 0.3, and feature 2 with value 0.1;

If feature 1 has weight 1 and feature 2 has weight 2, the score of user 1 is 0.1 \* 1 + 0.2 \* 2 = 0.5, while user 2 has score 0.3 \* 1 + 0.1 \* 2 = 0.5, which user 1 should rank higher than user 2.

Wondering if ElasticSearch support such customized ranking. If any sample index design/code, it will be highly appreciated.

thanks in advance,  
Lin

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 7, 2015, 8:17am UTC](https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000/2 "2015-07-07T08:17:46Z")

</div>

You will probably find the function score useful for what you are trying to do: [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)

---

<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 7, 2015, 8:41am UTC](https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000/3 "2015-07-07T08:41:32Z")

</div>

Thanks Colin,

Wondering if the score functions are executed in parallel on each node so that it is fully scale? The concern is if score is executed on a single node, if results set is too big, it may reach the limit of a single node. So a bit more details on internals of score function is appreciated.

regards,  
Lin

---

<div class="post-metadata">

**Author:** ![Jason\_Wee](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jason\_Wee](https://discuss.elastic.co/u/Jason_Wee)\
**Post date:** [July 7, 2015, 2:18pm UTC](https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000/4 "2015-07-07T14:18:04Z")

</div>

iirc , if you are using filters and query in the function scores, it should not really matter. unless you function score query come with sorting..then it matter. how large data you have?

---

<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 7, 2015, 5:23pm UTC](https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000/5 "2015-07-07T17:23:56Z")

</div>

Thanks Jason,

I need to return top N documents. In this case, wondering how Elastic Search doing internally? Is there a single node handling sorting? For dataset, it is about 1B documents and I want to return top 1M, and top 10M, any advice is appreciated.

regards,  
Lin

---

<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 8, 2015, 3:10am UTC](https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000/6 "2015-07-08T03:10:28Z")

</div>

Hi Colin,

I studied the document and it is really helpful. I am a new user of ElasticSearch and still a bit lost how to use score function to implement my use case. Let us make it simple, each document has two fields, f1 and f2. f1 has weight 0.1 and f2 has weight 0.2, and I want to score like this, and appreciate if you could help to specify a bit more details which score function should I use?

1. Retrieve the value of field f1, and multiply by 0.1;
2. Retrieve the value of field f2, and multiply by 0.2;
3. Sum the result from step 1 and step 2, which is the final score of the document;
4. return top 100 document.

regards,  
Lin

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 8, 2015, 9:02am UTC](https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000/7 "2015-07-08T09:02:49Z")

</div>

1. Use the [field-value-factor function score](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor) on field f1 with factor 0.1
2. Use the [field-value-factor function score](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor) on field f2 with factor 0.2
3. Use the [`sum` score mode](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score) and the [`replace` boost mode](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score)
4. Use the `size` parameter

---

<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:02am UTC](https://discuss.elastic.co/t/how-elasticsearch-supporting-customized-ranking/25000/8 "2017-07-06T00:02:55Z")

</div>


