弹性搜索function_score decay不工作,总是返回1 [英] Elasticsearch function_score decay not working, always returns 1

查看:93
本文介绍了弹性搜索function_score decay不工作,总是返回1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力修复这个数小时,但是似乎没有改变function_score衰减函数的返回值。这一直只是一个。看起来它不能得到我指定的字段的整数?



数据模型看起来像这样(显然是假的):

  {
basics:{
name:Mr Augustus Flybynight(Jim),
$
位置:{
城市:墨尔本,
邮政编码:3040,
元 b $ bcountry:Australia
},
region:VIC,
address:iytiytiyt,tyiuyti
},
email:augustus.flybynight2@gmail.com,
申请人号:11882,
name_first:奥古斯都,
元:{
alternateContact:,
lastModified:1473353751,
alternateName:,
notificationType:-1,
alternatePhones :[

],
gender:M
},
name_last:Flybynight,
phone 44556677
}
}

我h ave 3这个实体的重复,唯一的区别是它们的时间戳(basics.meta.lastModified)。我正在努力创造一个更接近更好的功能得分,以便最新的到达顶峰。我们尚未将时间戳记映射为日期,但是将其映射为整数。



尝试使用以下


查询时

  {
query:{
function_score:{
functions:[
{
gauss:{
basics.meta.lastModified:{
origin:1474868635,// now
offset:86400,//一天
scale:604800,//七天
decay:0.5
}
},
weight:2
}
],
query:{
bool:{
should:[
{
match:{
_all :$ 8
$ b
match:{
basics.all_names.all_names_identifier_whitespace:{
query :augustus flybynight,
boost:2
}
}
},
{
match:{
basics.email.email_identifier_keyword:{
query:augustus flybynight,
boost:3
}
}
},
{
match
basics.applicantNumber.applicantNumber_identifier_keyword:{
query:augustus flybynight,
boost:3
}
}
} ,
{
wildcard:{
basics.email.email_identifier_keyword:{
wildcard:augustus flybynight *,
boost 2
}
}
},
{
通配符:{
basics.all_n ames.all_names_identifier_whitespace:{
wildcard:augustus flybynight *
}
}
}
],
必须:[]
}
}
}
},
size:25,
from:0,
min_score:0.2
}

但是,这总是为功能分数返回'1',然后乘以对查询不影响它。这是最奇怪的事情。



当查看解释时,这是返回的:

 code> {
value:1,
description:min of:,
details:[
{
:1,
description:product of:,
details:[
{
value:1,
description field for field basics.meta.lastModified:,
details:[
{
value:1,
description:max(0.0,( (2.0 - MIN [0.0])/ 2.0),
details:[

]
}
]
},
{
value:1,
description:weight,
details:[

]
}
]
},
{
value:3.4028235e + 38,
description:maxBoost,
details:[

]
}
]
}

似乎MIN [0.0]是应该返回的部分时间戳,但它不是,而是返回0并使衰减函数始终为1.如果我使衰减参数更严格,如origin:0,offset:0,scale:1和decay:0.5,我期望function_score接近0,但仍然为1。



请帮忙。我一直在尝试所有的东西,似乎没有很多在线例子。任何建议将受到欢迎。

解决方案

对于那些遇到同样问题的人,我终于找到了罪魁祸首。

似乎有人没有正确设置映射,因为 basics.meta 属性设置为嵌套类型,但因为它没有这样填充(你会认为在索引数据时会造成问题),当尝试访问其中的数据时,它始终返回 MIN [0.0] 因为找不到该属性的值。



所以是的,如果你遇到这个问题,请仔细查看你的映射而不是像我一样浪费一整天:|


I've been trying to fix this for hours, but nothing seems to change the return value of the function_score decay function. It's simply 1 at all time. It looks like it can't get the integer of the field I'm specifying?

The data model looks like this (obviously fake):

{
  "basics": {
    "name": "Mr Augustus Flybynight (Jim)",
    "name_pref": "Jim",
    "location": {
      "city": "Melbourne",
      "postalCode": "3040",
      "meta": {
        "country": "Australia"
      },
      "region": "VIC",
      "address": "iytiytiyt, tyiuyti"
    },
    "email": "augustus.flybynight2@gmail.com",
    "applicantNumber": "11882",
    "name_first": "Augustus",
    "meta": {
      "alternateContact": "",
      "lastModified": 1473353751,
      "alternateName": "",
      "notificationType": "-1",
      "alternatePhones": [

      ],
      "gender": "M"
    },
    "name_last": "Flybynight",
    "phone": "44556677"
  }
}

I have 3 duplicates of this entity which the only difference is their timestamp (basics.meta.lastModified). I'm trying to create a 'closer is better' functional score so that the latest comes to the top. We haven't mapped the timestamp as a date yet, but it is mapped as an integer.

When trying to query with the following

{
  "query": {
    "function_score": {
      "functions": [
        {
          "gauss": {
            "basics.meta.lastModified": {
              "origin": 1474868635, // now
              "offset": 86400, // one day
              "scale": 604800, // seven days
              "decay": 0.5
            }
          },
          "weight": 2
        }
      ],
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "_all": "augustus flybynight"
              }
            },
            {
              "match": {
                "basics.all_names.all_names_identifier_whitespace": {
                  "query": "augustus flybynight",
                  "boost": 2
                }
              }
            },
            {
              "match": {
                "basics.email.email_identifier_keyword": {
                  "query": "augustus flybynight",
                  "boost": 3
                }
              }
            },
            {
              "match": {
                "basics.applicantNumber.applicantNumber_identifier_keyword": {
                  "query": "augustus flybynight",
                  "boost": 3
                }
              }
            },
            {
              "wildcard": {
                "basics.email.email_identifier_keyword": {
                  "wildcard": "augustus flybynight*",
                  "boost": 2
                }
              }
            },
            {
              "wildcard": {
                "basics.all_names.all_names_identifier_whitespace": {
                  "wildcard": "augustus flybynight*"
                }
              }
            }
          ],
          "must": []
        }
      }
    }
  },
  "size": 25,
  "from": 0,
  "min_score": 0.2
}

But this always returns '1' for the functional score, which is then multiplied to the query and doesn't affect it. It's the weirdest thing.

When looking at the explanation, this is what's returned:

{
  "value": 1,
  "description": "min of:",
  "details": [
    {
      "value": 1,
      "description": "product of:",
      "details": [
        {
          "value": 1,
          "description": "Function for field basics.meta.lastModified:",
          "details": [
            {
              "value": 1,
              "description": "max(0.0, ((2.0 - MIN[0.0])/2.0)",
              "details": [

              ]
            }
          ]
        },
        {
          "value": 1,
          "description": "weight",
          "details": [

          ]
        }
      ]
    },
    {
      "value": 3.4028235e+38,
      "description": "maxBoost",
      "details": [

      ]
    }
  ]
}

Seems like 'MIN[0.0]' is the part that should be returning the timestamp, but it isn't, instead returning 0 and making the decay function always 1. if I make the decay parameters stricter, like origin:0, offset:0, scale:1 and decay:0.5, I'd expect the function_score to be close to 0, but it's still 1.

Please help. I've been trying everything and there doesn't seem to be a lot of examples online. Any suggestions would be welcomed.

解决方案

For those hitting the same issue, I've finally found the culprit.

It seems that someone didn't setup the mappings properly at that the basics.meta property was set as a nested type, but since it wasn't populated as such (you'd think that would of caused an issue when indexing data?), when trying to access the data within it, it always returned MIN[0.0] because it simply couldn't find the value of the property.

So yeah, if you ever hit this issue, thoroughly look through your mappings instead of wasting a whole day like I did :|

这篇关于弹性搜索function_score decay不工作,总是返回1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆