# Score with ngram filter

**URL:** <https://discuss.elastic.co/t/score-with-ngram-filter/135912>\
**Category:** Elasticsearch\
**Created:** [June 14, 2018, 12:25pm UTC](https://discuss.elastic.co/t/score-with-ngram-filter/135912 "2018-06-14T12:25:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francisco\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/f/ce7236/32.png) [@Francisco\_Fernandez](https://discuss.elastic.co/u/Francisco_Fernandez)\
**Post date:** [June 14, 2018, 12:25pm UTC](https://discuss.elastic.co/t/score-with-ngram-filter/135912/1 "2018-06-14T12:25:50Z")

</div>

Hi,

I have a problem with the score in a search.

I have two elements, for example: "London Barking" and "Derry / Londonderry".

When I execute this query:

```
"query": {
        "match": {
          "name": {
            "query": "london"
          }
        }
  }

```

I get the same score for "London Barking" and "Derry / Londonderry", but I want a different score, higher for "London Barking" because has an exact word and "Derry / Londonderry" hasn't.

For analysis I use ngram\_filter. This is my complete mapping:

```
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1,
    "analysis": {
      "filter": {
        "ngram_filter": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 100
        }
      },
      "analyzer": {
        "ngram_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "ngram_filter"
          ]
        }
      }
    }
  },
  "mappings": {
    "hotel": {
      "properties": {
        "name": {
          "type": "text",
          "analyzer": "ngram_analyzer",
          "search_analyzer": "standard"
        }
      }
    }
  }
}

```

Can I give more score to elements with an exact word?

Thanks

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [June 14, 2018, 1:28pm UTC](https://discuss.elastic.co/t/score-with-ngram-filter/135912/2 "2018-06-14T13:28:37Z")

</div>

What you could do, is to add another version of the field name :  
The `name` field will be tokenized with the standard analyzer, and the `name.analyzed` field will be tokenized with the ngram analyzer.

```
{
  "mappings": {
    "hotel": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "analyzed": {
              "type": "text",
              "analyzer": "ngram_analyzer",
              "search_analyzer": "standard"
            }
          }
        }
      }
    }
  }
}

```

Then you will query on both fields, and apply a boost on the default version of field name :

```
{
  "query": {
    "multi_match": {
      "fields": [
        "name^2",
        "name.analyzed"
      ],
      "query": "london"
    }
  }
}
```

---

<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:** [July 12, 2018, 1:38pm UTC](https://discuss.elastic.co/t/score-with-ngram-filter/135912/3 "2018-07-12T13:38:49Z")

</div>

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