如何在 Elasticsearch 中有条件地调用高斯函数?
How do I conditionally call a gauss function in Elasticsearch?
我的网站有一个搜索索引,其中包含(除其他外)以下字段:
类型
标题
body
published_at
我想做的是只在type='article':
时执行下面的gauss函数
{
"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
}
],
您只需将 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
}
]
}
我的网站有一个搜索索引,其中包含(除其他外)以下字段:
类型 标题 body published_at
我想做的是只在type='article':
时执行下面的gauss函数 {
"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
}
],
您只需将 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
}
]
}