Score-Boosting Using Scripting

We have documents in ElasticSearch which contain proper names, dates of birth, addresses, ID numbers, and other related info.

We use a name-matching plugin which overrides the default scoring of ES and assigns a relevancy score between 0 and 1 based on how closely the name matches.

What we need to do is boost that score by a certain amount if other fields match. I have started to read up on ES scripting to achieve this. I need assistance on the script part of the query. Right now, our query looks like this:

{  
   "size":100,
   "query":{  
      "bool":{  
         "should":[  
            {"match":{"Name":"John Smith"}}
            ]
         }
   },
   "rescore":{  
         "window_size":100,
         "query":{  
            "rescore_query":{  
               "function_score":{  
                  "doc_score":{  
                     "fields":{
                       "Name":{"query_value":"John Smith"},
                       "DOB":{
                     	"function":{
                     		"function_score":{
                     			"script_score":{
                     				"script":{
                     					"lang":"painless",
                     					"params":{
                     						"query_value":"01-01-1999"
                     					         },
                     		   "inline":"if **<HERE'S WHERE I NEED ASSISTANCE>**"
                     		 }
                     	   }
                     	 }
                       }
                     }
                   }
                 }
               }
             },
             "query_weight":0.0,
             "rescore_query_weight":1.0
           }
         }

The Name field will always be required in a query and is the basis for the score, which is returned in the default _score field; for ease of demonstration, we'll just add one additional field, DOB, which if matched, should boost the score by 0.1. I believe I'm looking for something along the lines of if(query_value == doc['DOB'].value add 0.1 to _score), or something along these lines.

So, what would be the correct syntax to be entered into the inline row to achieve this? Or, if the query requires other syntax revision, please advise.

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