Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify custom_boost_factor, custom_score and custom_filters_score #3407

Closed
brwe opened this issue Jul 30, 2013 · 1 comment
Closed

Unify custom_boost_factor, custom_score and custom_filters_score #3407

brwe opened this issue Jul 30, 2013 · 1 comment

Comments

@brwe
Copy link
Contributor

brwe commented Jul 30, 2013

Unify custom scores

The custom boost factor, custom script boost and the filters function query all do the same thing: They take a query and for each found document compute a new score based on the query score and some script, come custom boost factor or a combination of these two. However, the json format for these three functionalities is very different. This makes it hard to add new functions.

It would be nice to consolidate the three custom scores under the keyword function_score.

The new format should provide the same functionality as before that is: compute a new score with one function:

"function_score": {
    "(query|filter)": {},
    "boost": "boost for the whole query",
    "function": {}
} 

or allow to combine the newly computed scores

"function_score": {
    "(query|filter)": {},
    "boost": "boost for the whole query",
    "functions": [
        {
            "filter": {},
            "function": {}
        },
        {
            "function": {}
        }
    ],
    "score_mode": "(mult|max|...)"
}

function here can be either

"script_score": {
    "lang": "lang",
    "params": {
        "param1": "value1",
        "param2": "value2"
     },
    "script": "some script"
}

or

"boost_factor" : number

Changes

The custom boost factor query

"custom_boost_factor" : {
    "query" : {
        ....
    },
    "boost_factor" : 5.2
}

would become

"function_score" : {
    "query" : {
        ....
    },
    "boost_factor" : 5.2
}

The custom script score

"custom_score" : {
    "query" : {
        ....
    },
    "params" : {
        "param1" : 2,
        "param2" : 3.1
    },
    "script" : "_score * doc['my_numeric_field'].value / pow(param1, param2)"
}

would become

"function_score" : {
    "query" : {
        ....
    },
    "script_score" : {

        "params" : {
            "param1" : 2,
            "param2" : 3.1
        },
        "script" : "_score * doc['my_numeric_field'].value / pow(param1, param2)"
    }
}

and the custom filters score query

"custom_filters_score" : {
    "query" : {
        "match_all" : {}
     },
    "filters" : [
        {
            "filter" : { "range" : { "age" : {"from" : 0, "to" : 10} } },
            "boost" : "3"
        },
        {
            "filter" : { "range" : { "age" : {"from" : 10, "to" : 20} } },
            "script" : "_score * doc['my_numeric_field'].value / pow(param1, param2)"
        }
    ],
    "score_mode" : "first",
    "params" : {
        "param1" : 2,
        "param2" : 3.1
    }
    "score_mode" : "first"
}       

becomes:

"function_score" : {
    "query" : {
        "match_all" : {}
    },
    "functions" : [
        {
            "filter" : { "range" : { "age" : {"from" : 0, "to" : 10} } },
            "boost" : "3"
        },
        {
            "filter" : { "range" : { "age" : {"from" : 10, "to" : 20} } },
            "script_score" : { 
                "script" : "_score * doc['my_numeric_field'].value / pow(param1, param2)",
                "params" : {
                    "param1" : 2,
                    "param2" : 3.1
                }

            }
        }
    ],
    "score_mode" : "first",     
}       
@brwe
Copy link
Contributor Author

brwe commented Aug 1, 2013

replaced by issue #3423

@brwe brwe closed this as completed Aug 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant