【发布时间】:2018-01-10 15:41:33
【问题描述】:
问题继续Elasticsearch: Influence scoring with custom score field in document pt.2
这一切都可以作为@Joanna 的回答。我只想在查询中添加衰减函数:
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [{
"nested": {
"path": "tags",
"score_mode": "sum",
"query": {
"function_score": {
"query": {
"match": {
"tags.tag": "landscape"
}
},
"field_value_factor": {
"field": "tags.confidence",
"factor": 1,
"missing": 0
}
}
}
}
}]
}
},
"field_value_factor": {
"field": "boost_multiplier",
"factor": 1,
"missing": 0
}
}
}
}
基于文档的 created_at 字段:
{
"created_at" : "2017-07-31T20:30:14-04:00",
"description" : null,
"height" : 3213,
"id" : "1",
"tags" : [
{
"confidence" : 65.48948436785749,
"tag" : "beach"
},
{
"confidence" : 57.31950504425406,
"tag" : "sea"
},
{
"confidence" : 43.58207236617374,
"tag" : "coast"
},
{
"confidence" : 35.6857910950816,
"tag" : "sand"
},
{
"confidence" : 33.660057321079655,
"tag" : "landscape"
},
{
"confidence" : 32.53252312423727,
"tag" : "sky"
}
],
"width" : 5712,
"color" : "#0C0A07",
"boost_multiplier" : 1
}
我尝试将文档中示例中所示的高斯函数添加为内部“field_value_factor”的兄弟,并给出错误提示“无法解析 [function_score] 查询。已经找到函数 [field_value_factor],现在遇到 [ gauss]。如果要定义多个函数,请使用 [functions] 数组。"。
然后我将“field_value_factor”和“gauss”都放在内部“查询”内的函数数组下,这次我收到错误消息“无法解析 [START_OBJECT]。格式错误的查询,在解析函数时需要 [VALUE_STRING],但是得到一个 [function_score] 代替”。
我只是找不到在查询中放置“高斯”函数的位置,以使用基于 created_at 字段的衰减。
更新 我还尝试了以下查询:
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [{
"nested": {
"path": "tags",
"score_mode": "sum",
"query": {
"function_score": {
"query": {
"match": {
"tags.tag": "landscape city"
}
},
"field_value_factor": {
"field": "tags.confidence",
"factor": 5,
"missing": 0
}
}
}
}
}]
}
},
"functions": [
{
"decay": {
"gauss": {
"created_at": {
"origin": "2013-09-17",
"scale": "10d",
"offset": "5d",
"decay": 0.5
}
}
}
},
{
"field_value_factor": {
"field": "boost_multiplier",
"factor": 1,
"missing": 0
}
}
]
}
}
}
这一次它给出了错误提示“没有为 [decay] 注册 [query]”。
有什么帮助吗?
UPDATE-2 以下查询有效:
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [{
"nested": {
"path": "tags",
"score_mode": "sum",
"query": {
"function_score": {
"query": {
"match": {
"tags.tag": "landscape city"
}
},
"field_value_factor": {
"field": "tags.confidence",
"factor": 5,
"missing": 0
}
}
}
}
}]
}
},
"functions": [
{
"field_value_factor": {
"field": "boost_multiplier",
"factor": 1,
"missing": 0
}
},
{
"gauss": {
"created_at": {
"scale": "365d",
"offset": "5d",
"decay" : 0.5
}
}
}
]
}
}
}
有效意味着它不会给出错误,但我没有得到我预期的结果。我只是想推动最近的文件而不是旧的文件。任何帮助如何实现它?
【问题讨论】:
标签: elasticsearch