script_score returns 0 in elastic 1.3 using lang groovy

script_score returns 0 in elastic 1.3 using lang groovy

我是弹性新手。我正在使用 function_score 来自定义乐谱。这是我的代码:

body = {
        "from" : product_per_page*page,
        "size" : product_per_page,
        "query": {
            "function_score": {
                "query": {
                    "bool":{
                        "must": [
                            {
                                "range": {
                                    "price": {
                                        "gte": from_price,
                                        "lte": to_price
                                        }
                                    }
                            }, {
                                "match":{
                                    "text": {
                                        "query": query,
                                        }
                                    },
                                }
                            ]
                        },
                    },
                "script_score": {
                    "script": "floor(_score)*doc['boost'].value",
                    "lang":"groovy"
                    },
                "boost_mode": "replace",
                },
            }
        }

问题是分数总是 return 0.0。 当我将脚本设置为:

"script": "_score"

它会 return 正确分数,例如 0.98977035(介于 0.0 和 1.0 之间的数字)。也当设置为:

"script": "_score + 0.0001"

再次 return 正确。但是当我使用这个时:

"script": "_score + 1"

它 returns 1.0 或:

"script": "_score *10"

returns 0.0(以及我使用的任何函数 "script": "floor(_score)" returns 0.0)。还有:

"script": "doc['boost'].value"

returns 0.0 (doc['boost'].value 在 10 , 100 之间)

我也试过:

"script": "32"

并且它 return 是 32(如我所料)。所以我猜问题是 groovy。也许当数字很大时,它们会四舍五入到 0.0。我应该怎么办? 谢谢

我找到了解决方案,但没有找到问题所在! 如果我使用 floor( _score*10.0 ) 它将 return 正确答案!(我不知道为什么) 关于 "script": "doc['boost'].value" 它将 float 转换为 Integer(我还不能解决 float 的问题)。