问题描述:

i have an indexed string field in my docs with letters a-z as possible values.

Is it possible to sort the query result in specific(given) order?

Something like:

{

"sort" : [

{ "letters" : {"order" : ["k", "g", "a"...]}}

}

网友答案:

I think instead of sorting you can use function score

"query": {
    "function_score": {
        "query": {},
        "functions": [
           {
                "field_value_factor": 
                {
                    "field": "rank",
                    "factor": 1
                }
            },
            {
                "filter": {"term": {"letters": "k"}},
                "weight": 50
            },
            {
                "filter": {"term": {"letters": "g"}},
                "weight": 40
            },
            {
                "filter": {"term": {"letters": "a"}},
                "weight": 30
            }
        ],
        "score_mode": "sum",
        "boost_mode": "sum"
    }
}
相关阅读:
Top