# Sorting by Fields After Text Score

**URL:** https://discuss.elastic.co/t/sorting-by-fields-after-text-score/314673
**Category:** Elasticsearch
**Created:** [September 19, 2022, 8:03am UTC](https://discuss.elastic.co/t/sorting-by-fields-after-text-score/314673 "2022-09-19T08:03:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AymanHamdoun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aymanhamdoun/32/111000_2.png) [@AymanHamdoun](https://discuss.elastic.co/u/AymanHamdoun)
#### Post date: [September 19, 2022, 8:03am UTC](https://discuss.elastic.co/t/sorting-by-fields-after-text-score/314673/1 "2022-09-19T08:03:28Z")

</div>

Hello,

I was wondering if elastic has the ability to sort by certain indexed fields in a document but not prioritize them over the textual match...

For instance, lets say i have an index of products that has the following items:

```auto
{"_id": 1, "title" : "black headphones XM4", "product_rating": 91, "maker": "Sony", "maker_rating": 93}
{"_id": 2, "title" : "black headphones XM5", "product_rating": 89, "maker": "Sony", "maker_rating": 93}
{"_id": 3, "title" : "black headphones", "product_rating": 32, "maker": "AliBaba", "maker_rating": 34}
{"_id": 4, "title" : "white headphones", "product_rating": 91, "maker": "Sony", "maker_rating": 93}

```

and a user searches for "black headphones"

I would like to get the most textually matching results sure. But I also want to make sure to display them according to the highest maker rating and then the highest product ratings. So in my perfect world i would like elastic to return \_ids 1,2,3,4 in that order.

Is there any way to write an elastic query that can accomplish this behavior ?

Thank you in advance

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [September 19, 2022, 12:37pm UTC](https://discuss.elastic.co/t/sorting-by-fields-after-text-score/314673/3 "2022-09-19T12:37:35Z")

</div>

Hi @AymanHamdoun

Did you use sort with the two mentioned fields?  
I think it shouldn't work perfectly in the order you want. In your case I would try to use the [field value factor](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor) to get the results in the desired order using the rating fields along with the score.

---

<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: [October 17, 2022, 12:38pm UTC](https://discuss.elastic.co/t/sorting-by-fields-after-text-score/314673/4 "2022-10-17T12:38:05Z")

</div>

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