# How to boost scoring for whole word hits over substring hits

**URL:** https://discuss.elastic.co/t/how-to-boost-scoring-for-whole-word-hits-over-substring-hits/344095
**Category:** Elasticsearch
**Created:** [September 29, 2023, 12:38am UTC](https://discuss.elastic.co/t/how-to-boost-scoring-for-whole-word-hits-over-substring-hits/344095 "2023-09-29T00:38:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![cookersjs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cookersjs/32/117689_2.png) [@cookersjs](https://discuss.elastic.co/u/cookersjs)
#### Post date: [September 29, 2023, 12:38am UTC](https://discuss.elastic.co/t/how-to-boost-scoring-for-whole-word-hits-over-substring-hits/344095/1 "2023-09-29T00:38:30Z")

</div>

Hi there,

I'd like to make it so that single-word query results that contain the entire query word by itself get higher scoring over results that contain the query word within another word.

For example in the case I am testing, when I search for 'pet', the result scoring does not seem to differentiate between cases containing 'pet' vs. 'appetite'. I would like to make it so that the phrase 'I have a **pet** allergy' would always return a higher score then 'I have no ap **pet** ite'.

My settings look like this:

```auto
"settings": {
      "index": {
        "number_of_replicas": 2,
        "max_ngram_diff": 7,
      },
      "analysis": {
        "normalizer": {
          "my_normalizer": {
            "type": "custom",
            "char_filter": [],
            "filter": [
              "lowercase"
            ]
          }
        },
        "char_filter": {
          "my_char_filter": {
            "type": "mapping",
            "mappings": [
              "- => _"
            ]
          }
        },        
        "analyzer": {
          "my_analyzer": {
            "tokenizer": "standard",
            "char_filter": [
              "my_char_filter"
            ],
            "filter": [
              "lowercase",
              "stop",
              "asciifolding",
              "my_ngram",
              "kstem"
            ]
          },
        "filter": {
          "my_ngram": {
            "type": "ngram",
            "min_gram": 4,
            "max_gram": 9,
            "preserve_original": true
          },
        }
      }
    },

```

Is this behaviour something that should be set in the index or the query itself?

Thank you in advance for any help!

---

<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 27, 2023, 12:38am UTC](https://discuss.elastic.co/t/how-to-boost-scoring-for-whole-word-hits-over-substring-hits/344095/2 "2023-10-27T00:38:33Z")

</div>

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