# Rank results by sorting the matched field

**URL:** <https://discuss.elastic.co/t/rank-results-by-sorting-the-matched-field/70588>\
**Category:** Elasticsearch\
**Created:** [January 4, 2017, 5:21pm UTC](https://discuss.elastic.co/t/rank-results-by-sorting-the-matched-field/70588 "2017-01-04T17:21:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leeavital](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leeavital/32/11151_2.png) [@leeavital](https://discuss.elastic.co/u/leeavital)\
**Post date:** [January 4, 2017, 5:21pm UTC](https://discuss.elastic.co/t/rank-results-by-sorting-the-matched-field/70588/1 "2017-01-04T17:21:43Z")

</div>

I often have Elasticsearch results searching across multiple fields. Some fields are more important than others, so I use a combination of query weighting and result post-processing to sort results based on the importance of fields. My queries look like:

```auto
{"multi_match": {
     "foo": "query",
     "foo.raw^2": "query"
}

```

With the hopes that matches on `foo.raw` show up above matches on `foo`. But there's no reliable way to make sure that `foo.raw` shows up above `foo` Is there a way to tell Elasticsearch to always rank matches on field above another without using boosting?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [January 5, 2017, 12:52pm UTC](https://discuss.elastic.co/t/rank-results-by-sorting-the-matched-field/70588/2 "2017-01-05T12:52:30Z")

</div>

Hi @leeavital,

there is a whole section about [controlling relevance](https://www.elastic.co/guide/en/elasticsearch/guide/current/controlling-relevance.html) in the Definitive Guide. To me it sounds like you might be interested in [function scoring](https://www.elastic.co/guide/en/elasticsearch/guide/current/function-score-query.html) or even [script scoring](https://www.elastic.co/guide/en/elasticsearch/guide/current/script-score.html) but you should keep an eye on the impact on performance.

Daniel

---

<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:** [February 2, 2017, 12:52pm UTC](https://discuss.elastic.co/t/rank-results-by-sorting-the-matched-field/70588/3 "2017-02-02T12:52:47Z")

</div>

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