# Scoring based on the field(s) results were matched

**URL:** <https://discuss.elastic.co/t/scoring-based-on-the-field-s-results-were-matched/128658>\
**Category:** Elasticsearch\
**Created:** [April 19, 2018, 8:30am UTC](https://discuss.elastic.co/t/scoring-based-on-the-field-s-results-were-matched/128658 "2018-04-19T08:30:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xan\_ps](https://avatars.discourse-cdn.com/v4/letter/x/c89c15/32.png) [@xan\_ps](https://discuss.elastic.co/u/xan_ps)\
**Post date:** [April 19, 2018, 8:30am UTC](https://discuss.elastic.co/t/scoring-based-on-the-field-s-results-were-matched/128658/1 "2018-04-19T08:30:44Z")

</div>

Currently, I'm trying to put a constant score according to the fields that have matched.

So, I want to assign a particular score if:  
the query matches in a particular field + boolean value on another field.

for it would be like:

```auto
query in field_1 match + boolean_field:true -> 1.0
query in field_1 match + boolean_field:false -> 0.9
query in field_2 match + boolean_field:true -> 0.75
query in field_2 match + boolean_field:false -> 0.65
query in field_3 match + boolean_field:true -> 0.5
query in field_3 match + boolean_field:false -> 0.4
query in field_4 match + boolean_field:true -> 0.25
query in field_4 match + boolean_field:false -> 0.15

```

My query goes something like this. I wanted to ask if there was any better way of writing it ([http://dpaste.com/3WGQHXG](http://dpaste.com/3WGQHXG)). (EDIT: if you wrap your code blocks in ``` then they will syntax highlight and code block format the blocks.)

```auto
   "query": {
      "function_score": {
         "boost_mode": "replace",
         "score_mode": "max",
         "query": {
            "bool": {
               "should": [
               query1,
               query2,
               query3
               query4
               ]
            }
         },
         "functions": [
            {
               "filter": {
                  "bool": {
                     "must": [
                        boolean_condition
                        query1
                     ]
                  }
               },
               "weight": "1"
            },
            {
               "filter": {
                  "bool": {
                     "must": [
                        not-boolean_condition
                        query1
                     ]
                  }
               },
               "weight": "0.9"
            },
            {
               "filter": {
                  "bool": {
                     "must": [
                        boolean_condition
                        query2
                     ]
                  }
               },
               "weight": ".75"
            },
            {
               "filter": {
                  "bool": {
                     "must": [
                        not-boolean_condition
                        query2
                     ]
                  }
               },
               "weight": ".65"
            },
            {
               "filter": {
                  "bool": {
                     "must": [
                        condition3
                        query3
                     ]
                  }
               },
               "weight": ".5"
            },
            {
               "filter": {
                  "bool": {
                     "must": [
                        boolean_condition
                        query3
                     ]
                  }
               },
               "weight": ".4"
            },
            {
               "filter": {
                  "bool": {
                     "must": [
                        boolean_condition
                        query4
                     ]
                  }
               },
               "weight": ".25"
            },
            {
               "filter": {
                  "bool": {
                     "must": [
                        not-boolean_condition
                        query4
                     ]
                  }
               },
               "weight": ".15"
            }
         ]
      }
   }

```

Indented query structure: [http://dpaste.com/3WGQHXG](http://dpaste.com/3WGQHXG)

---

<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:** [May 17, 2018, 8:30am UTC](https://discuss.elastic.co/t/scoring-based-on-the-field-s-results-were-matched/128658/2 "2018-05-17T08:30:59Z")

</div>

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