# Implementing Hybrid Search with k-NN and BM25 in Elasticsearch Open Source

**URL:** <https://discuss.elastic.co/t/implementing-hybrid-search-with-k-nn-and-bm25-in-elasticsearch-open-source/374680>\
**Category:** Elasticsearch\
**Created:** [February 18, 2025, 11:32am UTC](https://discuss.elastic.co/t/implementing-hybrid-search-with-k-nn-and-bm25-in-elasticsearch-open-source/374680 "2025-02-18T11:32:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saleh\_AbuAli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saleh_abuali/32/141444_2.png) [@Saleh\_AbuAli](https://discuss.elastic.co/u/Saleh_AbuAli)\
**Post date:** [February 18, 2025, 11:32am UTC](https://discuss.elastic.co/t/implementing-hybrid-search-with-k-nn-and-bm25-in-elasticsearch-open-source/374680/1 "2025-02-18T11:32:44Z")

</div>

Hi,

I am currently using Elasticsearch version 8.16 and am looking to implement hybrid search that combines k-NN and BM25. Since I am using the open-source version, I am unable to utilize RRF. Is there a way to use retrievers with the open-source version? If not, what would be the best alternatives for implementing hybrid search in the open-source version?

Thank you.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 18, 2025, 12:36pm UTC](https://discuss.elastic.co/t/implementing-hybrid-search-with-k-nn-and-bm25-in-elasticsearch-open-source/374680/2 "2025-02-18T12:36:47Z")

</div>

Welcome!

You can use boosting:

```auto
GET ecommerce/_search
{
  "query" : {
    "bool" : {
      "must" : [{
        "match": {
          "description": {
            "query": "summer clothes",
            "boost": 0.1
          }
        }
      },{
        "knn": {
          "field": "desc_embbeding",
          "query_vector": [0.123, 0.244,...],
          "boost": 2.0,
          "filter": {
            "term": {
              "department": "women"
            }
          }
        }
      }],
      "filter" : {
        "range" : { "price": { "lte": 30 } }
      }
    }
  }
}

```

If you want to do something like RRF, you can run a [multi search query](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html).  
Then use the different results to compute on your side the [RRF "score"](https://www.elastic.co/guide/en/elasticsearch/reference/current/rrf.html):

```auto
score = 0.0
for q in queries:
    if d in result(q):
        score += 1.0 / ( k + rank( result(q), d ) )
return score

# where
# k is a ranking constant
# q is a query in the set of queries
# d is a document in the result set of q
# result(q) is the result set of q
# rank( result(q), d ) is d's rank within the result(q) starting from 1

```

Of course, if you are lucky to have an enterprise license, all that will be much more easy to implement...

---

<div class="post-metadata">

**Author:** ![Saleh\_AbuAli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saleh_abuali/32/141444_2.png) [@Saleh\_AbuAli](https://discuss.elastic.co/u/Saleh_AbuAli)\
**Post date:** [February 18, 2025, 1:12pm UTC](https://discuss.elastic.co/t/implementing-hybrid-search-with-k-nn-and-bm25-in-elasticsearch-open-source/374680/3 "2025-02-18T13:12:52Z")

</div>

Thanks a lot, @dadoonet ! Just to clarify, does this mean there is no way to internally combine BM25 and k-NN results in the open-source version without relying on multi-search(Executes several searches)?

I tried writing a combined script, but it seems there is no way to separately access the k-NN and BM25 scores. From my understanding, the default combination simply adds the k-NN and BM25 scores together.
