# Combine knn score and match score

**URL:** <https://discuss.elastic.co/t/combine-knn-score-and-match-score/304032>\
**Category:** Elasticsearch\
**Created:** [May 5, 2022, 12:45pm UTC](https://discuss.elastic.co/t/combine-knn-score-and-match-score/304032 "2022-05-05T12:45:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![not\_correct](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/not_correct/32/105273_2.png) [@not\_correct](https://discuss.elastic.co/u/not_correct)\
**Post date:** [May 5, 2022, 12:45pm UTC](https://discuss.elastic.co/t/combine-knn-score-and-match-score/304032/1 "2022-05-05T12:45:01Z")

</div>

hi,  
my index has one knn vector field and one text field. I would like to create a search query which score would combile a score of KNN vector(cosinemil) and match score . Also I would like to boost KNN score so it can outweight the match score. Is it possible?  
many thanks

---

<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:** [May 5, 2022, 1:01pm UTC](https://discuss.elastic.co/t/combine-knn-score-and-match-score/304032/2 "2022-05-05T13:01:30Z")

</div>

Hi!!  
Maybe this [doc](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#query-dsl-function-score-query) can you help.

You can use functions to get the score from the vector and combine the scores through boost\_mode.

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [May 25, 2022, 3:13pm UTC](https://discuss.elastic.co/t/combine-knn-score-and-match-score/304032/3 "2022-05-25T15:13:37Z")

</div>

Are your vectors indexed ("index" : true), and you use `_knn_search` API? If yes, currently there is no way to combine scores from a match query and knn search on the Elasticsearch side. You need to do it on your application level. But we are actively working on this functionality, and the progress can be tracked [here](https://github.com/elastic/elasticsearch/issues/84324).

If your vectors are not indexed, you can use [script\_score query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-score-query.html) where you can combine `cosineSimilarity` with a `_score` from a match query through a script in any way you like.

---

<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:** [June 22, 2022, 3:13pm UTC](https://discuss.elastic.co/t/combine-knn-score-and-match-score/304032/4 "2022-06-22T15:13:59Z")

</div>

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