# Distance feature relevance score behaviour with boost \> 1

**URL:** <https://discuss.elastic.co/t/distance-feature-relevance-score-behaviour-with-boost-1/283386>\
**Category:** Elasticsearch\
**Created:** [September 5, 2021, 9:00pm UTC](https://discuss.elastic.co/t/distance-feature-relevance-score-behaviour-with-boost-1/283386 "2021-09-05T21:00:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Courtan](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@Courtan](https://discuss.elastic.co/u/Courtan)\
**Post date:** [September 5, 2021, 9:00pm UTC](https://discuss.elastic.co/t/distance-feature-relevance-score-behaviour-with-boost-1/283386/1 "2021-09-05T21:00:30Z")

</div>

Hello,

I am confused about the calculation of relevance scores with `distance_feature`. In the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/query-dsl-distance-feature-query.html) it says that:

> The `distance_feature` query calculates a document’s relevance score as follows:  
> relevance score = boost \* pivot / (pivot + distance)

I have the following query

```auto
{
  "_source": false,
  "query": {
    "distance_feature": {
      "field": "address.location",
      "origin": {
        "lat": 52.5065133,
        "lon": 13.1445545
      },
      "pivot": "100000m",
      "boost": __BOOST__
    }
  },
  "script_fields": {
    "distance": {
      "script": {
        "source": "doc['address.location'].arcDistance(params.lat,params.lon)",
        "params": {
          "lat": 52.5065133,
          "lon": 13.1445545
        }
      }
    }
  }
}

```

When running the query with `boost=1.0`, the documents are scored as expected.  
The document below has score `1 * (100000/(100000+2398.9804327731676)) = 0.9765722`.  
All scores are in [0, 1].

```auto
{
  "_index" : "some_index",
  "_type" : "_doc",
  "_id" : "57114",
  "_score" : 0.9765722,
  "fields" : {
    "distance" : [
      2398.9804327731676
    ]
  }
}

```

Yet when running the same query with `boost=2.0`, some score values are bigger than 2.0.  
For the same document the calculation does not work out anymore: `2 * (100000/(100000+2398.9804327731676)) = 1.9531444` yet the returned score is `3.9062889`

```auto
{
  "_index" : "some_index",
  "_type" : "_doc",
  "_id" : "57114",
  "_score" : 3.9062889,
  "fields" : {
    "distance" : [
      2398.9804327731676
    ]
  }
}

```

Am I misunderstanding the docs or have a stupid mistake in my thought process 🤔? I would be glad if someone could help me out with this 🙂

**EDIT** Just to give some context: This is relevant for me because i sometimes use `constant_score` queries to make sure that certain hits are sorted to the top. In such a case it's useful to know that the `distance_feature` only adds to the score within a certain range. This is how I interpreted the formula, the additional score is in `[0, boost]`.

Best regards

---

<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:** [October 3, 2021, 9:01pm UTC](https://discuss.elastic.co/t/distance-feature-relevance-score-behaviour-with-boost-1/283386/2 "2021-10-03T21:01:08Z")

</div>

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