0

我的网站有一个搜索索引,其中包含(除其他外)以下字段:

类型标题正文 published_at

我要做的是仅在 type='article' 时执行以下高斯函数:

        {
          "gauss": {
            "published_at": {
              "scale": "14d",
              "offset": "7d",
              "decay": 0.95
            }
          }
        },

基本上,我想保持所有类型的搜索结果相关,但文章被允许老化并慢慢下降排名。

谁能帮我解决这个问题,因为我无法解决。

这是完整的 function_score,其中包括不同类型值的权重:

    "function_score": {
      "functions": [
        {
          "gauss": {
            "published_at": {
              "scale": "14d",
              "offset": "7d",
              "decay": 0.95
            }
          }
        },
        {
          "filter": {
            "match": {
              "type": "programme"
            }
          },
          "weight": 60
        },
        {
          "filter": {
            "match": {
              "type": "podcast"
            }
          },
          "weight": 50
        },
        {
          "filter": {
            "match": {
              "type": "article"
            }
          },
          "weight": 40
        },
        {
          "filter": {
            "match": {
              "type": "clip"
            }
          },
          "weight": 30
        }
      ],
4

1 回答 1

1

您只需将gauss功能移动到您有过滤器的位置type: article

  "function_score": {
    "functions": [
      {
        "filter": {
          "match": {
            "type": "programme"
          }
        },
        "weight": 60
      },
      {
        "filter": {
          "match": {
            "type": "podcast"
          }
        },
        "weight": 50
      },
      {
        "filter": {
          "match": {
            "type": "article"
          }
        },
        "gauss": {
          "published_at": {
            "scale": "14d",
            "offset": "7d",
            "decay": 0.95
          }
        },
        "weight": 40
      },
      {
        "filter": {
          "match": {
            "type": "clip"
          }
        },
        "weight": 30
      }
    ]
  }
于 2021-03-11T14:16:06.100 回答