# Elasticsearch ranking shorter/less relevant titles first

**URL:** <https://discuss.elastic.co/t/elasticsearch-ranking-shorter-less-relevant-titles-first/197408>\
**Category:** Elasticsearch\
**Created:** [August 29, 2019, 7:30pm UTC](https://discuss.elastic.co/t/elasticsearch-ranking-shorter-less-relevant-titles-first/197408 "2019-08-29T19:30:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cannon\_Moyer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cannon_moyer/32/46269_2.png) [@Cannon\_Moyer](https://discuss.elastic.co/u/Cannon_Moyer)\
**Post date:** [August 29, 2019, 7:30pm UTC](https://discuss.elastic.co/t/elasticsearch-ranking-shorter-less-relevant-titles-first/197408/1 "2019-08-29T19:30:22Z")

</div>

I'm working on a product search with Elasticsearch 7.3. The product titles are not formatted the same but there is nothing I can do about this.

Some titles might look like this:

```
Ford Hub Bearing

```

And others like this:

```
Hub bearing for a Chevrolet Z71 - model number 5528923-01

```

If someone searches for "Chevrolet Hub Bearing" the "Ford Hub Bearing" product ranks #1 and the Chevrolet part ranks #2. If I remove all the extra text (model number 5528923-01) from the product title, the Chevrolet part ranks #1 as desired.

Unfortunately I am unable to fix the product titles, so I need to be able to rank the Chevrolet part as #1 when someone searches `Chevrolet Hub Bearing` . I have simply set the type of `name` to `text` and applied the `standard` analyzer in my index. Here is my query code:

```auto
{
    query:{

        bool: {
            must: [
                {
                    multi_match:{
                        fields: 
                            [
                               'name'
                             ],
                             query: "Chevrolet Hub Bearing"
                    }
                 }                  
            ]
        }

    }         
}

```

> <https://stackoverflow.com/questions/57716590/elasticsearch-ranking-shorter-less-relevant-titles-first>

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [August 30, 2019, 7:29am UTC](https://discuss.elastic.co/t/elasticsearch-ranking-shorter-less-relevant-titles-first/197408/2 "2019-08-30T07:29:16Z")

</div>

Matches found in shorter length fields end up scoring higher than matches found in longer length fields.

In many cases this makes sense, but sometimes you don't want the field length to contribute to the relevancy score. When you don't want it to contribute, you can [disable `norms` on the field mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/norms.html)

```auto
PUT /my_index
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "norms": false
      }
    }
  }
}

```

It's better to disable this in the mapping at index and mapping creation time as above, but if you have an existing index and mapping it can be applied to the existing mapping

```auto
PUT my_index/_mapping
{
  "properties": {
    "title": {
      "type": "text",
      "norms": false
    }
  }
}

```

Just be aware that

1. `norms` will not be removed instantly, but will be merged as old segments are merged into new segments as new documents are indexed.
2. Once disabled, they cannot be re-enabled in the index; you would need to create a new index

I think you _should_ be able to use `update_by_query` API to help with point 1

```auto
POST my_index/_update_by_query?conflicts=proceed

```

which will cause each existing document to be updated (reindexed)

---

<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 27, 2019, 7:29am UTC](https://discuss.elastic.co/t/elasticsearch-ranking-shorter-less-relevant-titles-first/197408/3 "2019-09-27T07:29:19Z")

</div>

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