0
votes

I am trying to modify a search score in elasticsearch by multiplying the _score by the square root of a single value stored with each document. Below is the JSON query I am using. Where have I gone wrong?

{
"index": "resources",
"type": "page",
"from": "0",
"size": "20",
"body": {
    "query": {
        "match": {
            "content": "baseball"
        },
        "function_score": {
            "functions": [{
                "script_score": {
                    "params": [],
                    "script": "_score * sqrt(page['obls'].value)"
                }
            }]
        }
    }
}

}

Thanks in advance for your help!

1

1 Answers

0
votes

If you are using 1.4.X I would use field value factor function as follows:

{
    "query": {
        "function_score": {
            "query": {
                "match": {
                    "content": "baseball"
                }
            },
            "functions": [
                {
                    "field_value_factor": {
                        "field": "obls",
                        "factor": 1,
                        "modifier": "sqrt"
                    }
                }
            ]
        }
    },
    "from": "0",
    "size": "20"
}