# Use reciprocal ranking fusion to combine the results of two queries

**URL:** <https://discuss.elastic.co/t/use-reciprocal-ranking-fusion-to-combine-the-results-of-two-queries/329614>\
**Category:** Elasticsearch\
**Created:** [April 8, 2023, 4:48pm UTC](https://discuss.elastic.co/t/use-reciprocal-ranking-fusion-to-combine-the-results-of-two-queries/329614 "2023-04-08T16:48:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![flando](https://avatars.discourse-cdn.com/v4/letter/f/9e8a1a/32.png) [@flando](https://discuss.elastic.co/u/flando)\
**Post date:** [April 8, 2023, 4:48pm UTC](https://discuss.elastic.co/t/use-reciprocal-ranking-fusion-to-combine-the-results-of-two-queries/329614/1 "2023-04-08T16:48:21Z")

</div>

Hi everyone,  
I'm trying to use reciprocal ranking fusion (RRF) to combine the results of two query performed with the following code:

```auto
GET /books_index/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "title": "the"
          }
        },
        {
          "match": {
            "description": "in"
          }
        }
      ]
    }
  }
}

```

In practice what I need to do is returning a single list of document based on the new score obtained by computing the RRF of each document.

The new score of each document should be: 1/(document position in the result list of the query on title) + 1/(document position in the result list of the query on description).

Maybe it can be done with scripted\_metric? But I do not know how.  
I was also thinking on using aggregation, but I did not succeeded.

---

<div class="post-metadata">

**Author:** ![flando](https://avatars.discourse-cdn.com/v4/letter/f/9e8a1a/32.png) [@flando](https://discuss.elastic.co/u/flando)\
**Post date:** [April 17, 2023, 2:32pm UTC](https://discuss.elastic.co/t/use-reciprocal-ranking-fusion-to-combine-the-results-of-two-queries/329614/2 "2023-04-17T14:32:21Z")

</div>

I have found that there is an open [pull request](https://github.com/elastic/elasticsearch/pull/93396).

There is no way to get it with `function_score`/`script_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:** [May 15, 2023, 2:32pm UTC](https://discuss.elastic.co/t/use-reciprocal-ranking-fusion-to-combine-the-results-of-two-queries/329614/3 "2023-05-15T14:32:27Z")

</div>

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