Elasticsearch function_score衰减不起作用,总是返回1

时间:2016-09-26 05:56:26

标签: elasticsearch

我一直试图解决这个问题几个小时,但似乎没有任何东西改变了function_score衰减函数的返回值。它总是只有1个。看起来它无法获取我指定的字段的整数?

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

{
  "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"
  }
}

我有3个这个实体的副本,唯一的区别是他们的时间戳(basics.meta.lastModified)。我正在尝试创建一个“更接近更好”的功能分数,以便最新的功能达到顶峰。我们还没有将时间戳映射为日期,但它被映射为整数。

尝试使用以下

进行查询时
{
  "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
}

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

在查看解释时,这是返回的内容:

{
  "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": [

      ]
    }
  ]
}

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

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

1 个答案:

答案 0 :(得分:1)

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

似乎有人没有正确设置映射,因为compute属性被设置为嵌套类型,但因为它没有被填充(你认为这会引起一个问题)索引数据时?),当试图访问其中的数据时,它总是返回basics.meta,因为它根本找不到属性的值。

所以是的,如果你遇到过这个问题,那么会彻底查看你的映射而不是像我一样浪费一整天:|