当使用高斯衰变分数函数时,它总是在嵌套元素上得分1 [英] When using gauss decay score funtion, it always scores 1 on nested elements
问题描述
对于
{
_id:abc123,
_score :3.7613528,
_source:{
id:abc123,
pricePeriods:[{
periodTo:
eur:1036,
gbp:782,
dkk:6880,
sek:9025,
periodFrom:2015 -12-26,
nok:8065
},{
periodTo:2016-06-18,
eur:671,
gbp:457,
dkk:4625,
sek:5725,
periodFrom:2016-011-02,
nok :5430
}]
}
}
<我想在这个价格上有一个高斯衰变函数得分。
我已经尝试过这样的
query:{
function_score:{
functions:[{
gauss:{
pricePeriods.dkk:{
origin:2500,
scale:2500,
decay:0.8
}
},
filter:{
nested:{
filter:{
range:{
pricePeriods.periodTo :{
gte:2016-03-17T00:00:00.000
}
}
},
path:价格周期
}
}
}
]
,似乎过滤器找到我想要高斯的价格,但得到的分数总是为1。
解释说
{ value:1,
description:min of:,
details:[
{
value:1,
description :功能得分,得分模式[乘法],
细节:[
{
value:1,
description of:
details:[
{
value:1,
description:match filter:ToParentBlockJoinQuery(+ ConstantScore(pricePeriods.periodTo: [32 30 31 36 2d 30 33 2d 31 37 54 30 30 3a 30 30 3a 30 30 2e 30 30 30] TO *])#QueryWrapperFilter(_type:__ pricePeriods)),
details:[]
},
{
value:1,
description:function for Value pricePeriods.dkk:,
details:[
{
value:1,
description:exp(-0.5 * pow(MIN [0.0],2.0)/1.4004437867889222E7),
details:[]
}
]
}
]
}
]
}
<我可以看到这里高斯显然返回1,当它找不到字段。
但问题是为什么它无法在嵌套文档中找到该字段,以及如何ix。解决方案原来 gauss函数
正在返回1是因为你说没有找到该字段,因为它是嵌套
您基本上需要将整个 function_score
查询包含到嵌套查询中
{
query:{
nested:{
path:pricePeriods,
query :{
function_score:{
functions:[
{
gauss:{
pricePeriods.dkk:{
起始:2500,
scale:2500,
decay:0.8
}
},
filter:{
range:{
pricePeriods.periodTo:{
gte:2016-03-17T00:00:00.000
}
}
}
}
]
}
}
}
}
}
这是否有帮助?
For documents like
{
"_id" : "abc123",
"_score" : 3.7613528,
"_source" : {
"id" : "abc123",
"pricePeriods" : [{
"periodTo" : "2016-01-02",
"eur" : 1036,
"gbp" : 782,
"dkk" : 6880,
"sek" : 9025,
"periodFrom" : "2015-12-26",
"nok" : 8065
}, {
"periodTo" : "2016-06-18",
"eur" : 671,
"gbp" : 457,
"dkk" : 4625,
"sek" : 5725,
"periodFrom" : "2016-01-02",
"nok" : 5430
} ]
}
}
I would like to have a gauss decay function score on the prices.
I have tried like this
"query" : {
"function_score" : {
"functions" : [{
"gauss" : {
"pricePeriods.dkk" : {
"origin" : "2500",
"scale" : "2500",
"decay" : 0.8
}
},
"filter" : {
"nested" : {
"filter" : {
"range" : {
"pricePeriods.periodTo" : {
"gte" : "2016-03-17T00:00:00.000"
}
}
},
"path" : "pricePeriods"
}
}
}
]
and it seems that the filter finds the prices I want to make a gauss on, but the resulting score is always 1.
Explain says
{ "value": 1,
"description": "min of:",
"details": [
{
"value": 1,
"description": "function score, score mode [multiply]",
"details": [
{
"value": 1,
"description": "function score, product of:",
"details": [
{
"value": 1,
"description": "match filter: ToParentBlockJoinQuery (+ConstantScore(pricePeriods.periodTo:[[32 30 31 36 2d 30 33 2d 31 37 54 30 30 3a 30 30 3a 30 30 2e 30 30 30] TO *]) #QueryWrapperFilter(_type:__pricePeriods))",
"details": []
},
{
"value": 1,
"description": "Function for field pricePeriods.dkk:",
"details": [
{
"value": 1,
"description": "exp(-0.5*pow(MIN[0.0],2.0)/1.4004437867889222E7)",
"details": []
}
]
}
]
}
]
}
I can see here that gauss apparently returns 1 when it can't find the field.
But the questions is why it can't find the field in nested docs and how to ix that.
解决方案 The reason gauss function
is returning 1 is because as you said it can't find the field as it is nested
, you basically need to wrap your whole function_score
query into nested query
{
"query": {
"nested": {
"path": "pricePeriods",
"query": {
"function_score": {
"functions": [
{
"gauss": {
"pricePeriods.dkk": {
"origin": "2500",
"scale": "2500",
"decay": 0.8
}
},
"filter": {
"range": {
"pricePeriods.periodTo": {
"gte": "2016-03-17T00:00:00.000"
}
}
}
}
]
}
}
}
}
}
Does this help?
这篇关于当使用高斯衰变分数函数时,它总是在嵌套元素上得分1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!