# How to rescore Elasticsearch results using semantic search with custom boosting conditions?

**URL:** https://discuss.elastic.co/t/how-to-rescore-elasticsearch-results-using-semantic-search-with-custom-boosting-conditions/372337
**Category:** Elasticsearch
**Created:** [December 23, 2024, 5:54pm UTC](https://discuss.elastic.co/t/how-to-rescore-elasticsearch-results-using-semantic-search-with-custom-boosting-conditions/372337 "2024-12-23T17:54:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Jacques\_du\_Plessis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jacques_du_plessis/32/35413_2.png) [@Jacques\_du\_Plessis](https://discuss.elastic.co/u/Jacques_du_Plessis)
#### Post date: [December 23, 2024, 5:54pm UTC](https://discuss.elastic.co/t/how-to-rescore-elasticsearch-results-using-semantic-search-with-custom-boosting-conditions/372337/1 "2024-12-23T17:54:35Z")

</div>

I am using Elasticsearch's ELSER inference model to perform semantic searches. I need to rescore the search results based on specific conditions: spotlighted documents should be at the top, followed by verified documents, and finally sorted by the highest votes in descending order.

Here is the current Elasticsearch query I am using for semantic search:

```auto
GET business-index/_search?filter_path=hits.hits._source.title,hits.hits._source.subtitle,hits.hits._source.categorySearch,hits.hits._source.spotlight,hits.hits._source.verified,hits.hits._source.votes,hits.hits._source.createdAt
{
  "query": {
    "semantic": {
      "query": "hungry",
      "field": "elser"
    }
  }
}

```

it seems like if i add function\_score it does not really take the query into account anymore. I always want the filtered response to take the query into account.  
.

```auto
"functions": [
        {
          "filter": {
            "term": {
              "spotlight": true
            }
          },
          "weight": 20
        },
        {
          "filter": {
            "term": {
              "verified": true
            }
          },
          "weight": 10
        },
        {
          "field_value_factor": {
            "field": "votes",
            "factor": 1,
            "modifier": "log1p",
            "missing": 0
          },
          "weight": 20
        }
      ],
      "boost_mode": "sum",
      "score_mode": "sum"
    }

```

Also is there a way to remove some of the weak scores that gets returned from elser field.

If i search hungry i expect to see thing from restaurants and fast foods etc., but i also get results from hair salons and other weird things. i want the aggregate to be on the query as well.

I did look at [Reciprocal rank fusion | Elasticsearch Guide [8.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/rrf.html)

but not sure how that would help me as i cant figure this out.
