Scoring based on the field(s) results were matched

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:

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). (EDIT: if you wrap your code blocks in ``` then they will syntax highlight and code block format the blocks.)

   "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

1 Like

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