# Custom weights for fields, custom score

**URL:** https://discuss.elastic.co/t/custom-weights-for-fields-custom-score/236191
**Category:** Elasticsearch
**Created:** [June 8, 2020, 2:40pm UTC](https://discuss.elastic.co/t/custom-weights-for-fields-custom-score/236191 "2020-06-08T14:40:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_D](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Alex\_D](https://discuss.elastic.co/u/Alex_D)
#### Post date: [June 8, 2020, 2:40pm UTC](https://discuss.elastic.co/t/custom-weights-for-fields-custom-score/236191/1 "2020-06-08T14:40:38Z")

</div>

Hi all !  
I'm trying to make a query with a custom weights for fields and custom result score.

Suppose we have 3 fields:

- field1 : Text,
- field2 : Text,
- phrase : Text.

Each field must have a different weight in the resulting score.

- field1 (exact match, weight 70) +
- field2 (exact match, weight 20) +
- phrase (partial match, weight in range 0-10)

I expect to get a final score of 100 with a complete match.

I made an implementation through a "function\_score" and "weight" attribute,  
but this approach does not work for field "phrase".  
For this field I would like to get a relevance score in the range from 0 to 10.  
How can I do that ?

Below are my data and query.  
Will be glad to any comments.  
Thanks.

=== MY DATA ===

```auto
POST /_bulk
{"create":{"_index":"test_score","_id":"1"}}
{"text_field1":"v1","text_field2":"v10","phrase":"The best of both worlds"}
{"create":{"_index":"test_score","_id":"2"}}
{"text_field1":"v2","text_field2":"v20","phrase":"The best thing since sliced bread"}
{"create":{"_index":"test_score","_id":"3"}}
{"text_field1":"v3","text_field2":"v30","phrase":"The best song in the world"}

```

=== MY QUERY ===

```auto
GET /test_score/_search
{
    "query":
    { 
      "function_score": 
      {
        "query": {
          "match_all": {}
        },
        "functions": [
          {
              "filter": 
              {
                "term": {
                  "text_field1": "v1"
                } 
              },
              "weight": 70
          },
          {
              "filter": 
              {
                "term": {
                  "text_field2": "v10"
                } 
              },
              "weight": 20
          },
          {
              "filter": 
              {
                "match":{
                  "phrase": "world"
                }
              },
              "weight": 10
          }
        ],
        "max_boost": 105,
        "min_score": 0,
        "score_mode": "sum",
        "boost_mode": "replace"
      }
    }
}

```

---

<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 6, 2020, 2:40pm UTC](https://discuss.elastic.co/t/custom-weights-for-fields-custom-score/236191/2 "2020-07-06T14:40:43Z")

</div>

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