【发布时间】:2018-08-16 16:16:33
【问题描述】:
我需要找到相关或相似的帖子,然后按日期对它们进行排序。我怎样才能做到这一点? 这是一个查询:
{
"fields":[
"id", "score"
],
"size":0,
"query":{
"function_score":{
"query":{
"bool":{
"should":[
{ "match":{ "main_headline.en":{"query":"some text"}}},
{"match":{"body.en":"some text" }}
],
"must_not":{ "term":{ "id":76484 }}
}
},
"functions":[
{
"gauss":{
"published_at":{ "scale":"140w","decay":0.3
}
}
}]
}
},
"aggregations":{
"postslug":{
"terms":{
"field":"slug",
"size":9,
"order":{"max_score":"desc"}
},
"aggs":{
"max_score":{
"max":{ "script":"_score" }
},
"fields":{
"top_hits":{
"size":1,
"_source":{
"includes":["id", "published_at", "slug"]
}
}
},
"aggs":{
"byDate":{
"max":{"field":"published_at"}
}
}
}
}
}
}
我已经尝试通过子聚合来实现 - byDate 但我得到一个错误`在 [aggs] 中找不到聚合器类型 [byDate]。如何修复此错误或如何在聚合后对数据进行排序?
【问题讨论】:
标签: elasticsearch elasticsearch-2.0 elasticsearch-aggregation