# Elasticsearch - how to make shorter phrase more relevant in result

**URL:** <https://discuss.elastic.co/t/elasticsearch-how-to-make-shorter-phrase-more-relevant-in-result/195452>\
**Category:** Elasticsearch\
**Created:** [August 16, 2019, 8:04am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-make-shorter-phrase-more-relevant-in-result/195452 "2019-08-16T08:04:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladimir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vladimir/32/91042_2.png) [@Vladimir](https://discuss.elastic.co/u/Vladimir)\
**Post date:** [August 16, 2019, 8:04am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-make-shorter-phrase-more-relevant-in-result/195452/1 "2019-08-16T08:04:43Z")

</div>

Hi can somebody explain me please how to achieve higher score in search result for shorter phrase in compare with longer phrase? E.g. if I have two words **ABCXXX** and **ABCXXXXX** with edge ngram tokenizer and if I want to find **ABC** token **score is the same**. I would like to get higher score for ABCXXX and lower for ABCXXXXXX. Mapping looks like:

```auto
    {
        "settings": {
            "index": {
                "refresh_interval": "1m",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "analysis": {
                    "filter": {
                        "autocomplete_filter": {
                            "type": "edge_ngram",
                            "min_gram": "1",
                            "max_gram": "20"
                        }
                    },
                    "analyzer": {
                        "autocomplete": {
                            "filter": [
                                "lowercase",
                                "asciifolding",
                                "autocomplete_filter"
                            ],
                            "type": "custom",
                            "tokenizer": "standard"
                        },
                        "default": {
                            "filter": [
                                "lowercase",
                                "asciifolding"
                            ],
                            "type": "custom",
                            "tokenizer": "standard"
                        }
                    }
                }
            }
        },
        "mappings": {
            "doc": {
                "dynamic": "strict",
                "_all": {
                    "enabled": false
                },
                "properties": {
                    "normalized2": {
                        "type": "text",
                        "analyzer": "autocomplete"
                    }
                }
            }
        }
    }

```

and the query looks like:

```auto
{
    "sort": {
        "_score": "desc"
    },
    "query": {
        "bool": {
            "should": [
                {
                    "term": {
                        "normalized2": {
                            "value": "abc",
                            "boost": 2
                        }
                    }
                }
            ]
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 16, 2019, 11:31am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-make-shorter-phrase-more-relevant-in-result/195452/2 "2019-08-16T11:31:56Z")

</div>

[This post](https://discuss.elastic.co/t/ngram-filter-and-relevance-score/22475/2) has a good solution: instead of using the `edge_ngram` filter, use the `edge_ngram` tokenizer:

```auto
  "settings": {
    "index": {
      "refresh_interval": "1m",
      "number_of_shards": "1",
      "number_of_replicas": "1",
      "analysis": {
        "tokenizer": {
          "autocomplete_tokenizer": {
            "type": "edge_ngram",
            "min_gram": "1",
            "max_gram": "20"
          }
        },
        "analyzer": {
          "autocomplete": {
            "filter": [
              "lowercase",
              "asciifolding"
            ],
            "type": "custom",
            "tokenizer": "autocomplete_tokenizer"
          },
          "default": {
            "filter": [
              "lowercase",
              "asciifolding"
            ],
            "type": "custom",
            "tokenizer": "standard"
          }
        }
      }
    }
  }

```

---

<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:** [September 13, 2019, 11:32am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-make-shorter-phrase-more-relevant-in-result/195452/3 "2019-09-13T11:32:06Z")

</div>

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