script_score return is strange


(Jianfeng Ye) #1

I need to get documents order by custom score, so i use script_score:

$params = [
            'index' => "questions",
            'type' => "baichebao",
            'body' => [
                'from' => $from,
                'size' => $size,
                'sort' => [
                    "_score" => 'asc',
                ],
                'query' => [
                    'bool' => [
                        'should' => [
                            'function_score' => [
                                'query' => [
                                    'match' => [
                                        'content' => '斯巴鲁',
                                    ]
                                ],
                                'script_score' => [
                                    "lang" => "groovy",
                                    'params' => [
                                        'now' => 1442184014,
                                    ],
                                    'script' => 'now - doc["created_at"].value',
                                ],
                            ]
                        ]
                    ]
                ]
            ]
        ];

and I got the documents like

{
    "code": 0,
    "message": "处理成功",
    "timestamp": 1442184477,
    "im": true,
    "result": {
        "took": 6,
        "timed_out": false,
        "_shards": {
            "total": 5,
            "successful": 5,
            "failed": 0
        },
        "hits": {
            "total": 2680,
            "max_score": null,
            "hits": [
                {
                    "_index": "questions",
                    "_type": "baichebao",
                    "_id": "2536263",
                    "_score": 740085.6,
                    "_source": {
                        "id": 2536263,
                        "content": "06年斯巴鲁力狮4at,近日出现行驶中熄火,油温过高指示灯闪一下就熄火,感觉车身下面确实有一点热,而且熄火前发动机转数还会乱跳,开着有点供不上油的感觉,时好时坏",
                        "uid": 877461,
                        "all_answer_count": 33,
                        "answer_users": 1,
                        "best_answer": 2951111,
                        "status": 1,
                        "is_closed": false,
                        "tags": [
                            "故障维修"
                        ],
                        "channel_type": 3,
                        "channel_sub_type": 0,
                        "created_at": 1441386486,
                        "distrust": 0,
                        "is_expert": false,
                        "series_id": 0
                    },
                    "sort": [
                        740085.6
                    ]
                }
            ]
        }
    }
}

please notice the _score is 740085.6, but my script will be : 1442184014-1441386486, how the elasticsearch got the strange score?


My query result will change in same params
My query result will change in same params
(Mark Walkom) #2

Please see My query result will change in same params


(Mark Walkom) #3