# How does span near scoring work

**URL:** <https://discuss.elastic.co/t/how-does-span-near-scoring-work/379193>\
**Category:** Elastic Search\
**Created:** [June 16, 2025, 6:28am UTC](https://discuss.elastic.co/t/how-does-span-near-scoring-work/379193 "2025-06-16T06:28:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![symphony](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/symphony/32/143675_2.png) [@symphony](https://discuss.elastic.co/u/symphony)\
**Post date:** [June 16, 2025, 6:28am UTC](https://discuss.elastic.co/t/how-does-span-near-scoring-work/379193/1 "2025-06-16T06:28:02Z")

</div>

Hi, I'm facing an issue with the keyword search I'm building where documents seem to rack up a huge score out of nowhere and overtake documents that seem to be more relevant. For example, if the query is "quick brown fox", huge wordy documents where seemingly the only somewhat relevant word is "for" (due to fuzzy matching) manages to overtake documents that have exact word matchings with either the entirety or part of "quick brown fox".

I believed the issue could have been due to the repeated "for" matching against the query. However, when I tested this by creating a document with many repetitions of the word "fox", it did not overtake the documents with "quick brown fox".

I'd appreciate any insights into how the scoring works for span near queries or guidance on how to prevent documents with weak matches from overpowering higher-quality matches.

I'm using a `bool` query over multiple `span_near` queries (with `span_term`) to accommodate partial matches. The query is split into segments to support documents that may not contain all the words in the original phrase. Each segment combination is wrapped in a `span_near` and passed into the `should` clause of the `bool` query. This will be how the search query look like when the query is "quick brown fox".

```auto
GET /connector-test-8.18-connector-new/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "span_near": {
            "clauses": [
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "quick", "fuzziness": "auto" } } } } }
            ],
            "slop": 1,
            "in_order": true,
            "boost": 1
          }
        },
        {
          "span_near": {
            "clauses": [
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "quick", "fuzziness": "auto" } } } } },
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "brown", "fuzziness": "auto" } } } } }
            ],
            "slop": 2,
            "in_order": true,
            "boost": 2
          }
        },
        {
          "span_near": {
            "clauses": [
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "quick", "fuzziness": "auto" } } } } },
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "brown", "fuzziness": "auto" } } } } },
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "fox", "fuzziness": "auto" } } } } }
            ],
            "slop": 3,
            "in_order": true,
            "boost": 3
          }
        },
        {
          "span_near": {
            "clauses": [
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "fox", "fuzziness": "auto" } } } } }
            ],
            "slop": 1,
            "in_order": true,
            "boost": 1
          }
        },
        {
          "span_near": {
            "clauses": [
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "brown", "fuzziness": "auto" } } } } }
            ],
            "slop": 1,
            "in_order": true,
            "boost": 1
          }
        },
        {
          "span_near": {
            "clauses": [
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "brown", "fuzziness": "auto" } } } } },
              { "span_multi": { "match": { "fuzzy": { "body": { "value": "fox", "fuzziness": "auto" } } } } }
            ],
            "slop": 2,
            "in_order": true,
            "boost": 2
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [June 16, 2025, 12:11pm UTC](https://discuss.elastic.co/t/how-does-span-near-scoring-work/379193/2 "2025-06-16T12:11:48Z")

</div>

Hey there @symphony and welcome to the community!

You may be interested in checking out the [dis\_max](https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-dis-max-query) query, I think this will meet your needs for scoring relevance smoothing.
