在Elasticsearch中排序聚合结果集并进行过滤 [英] Sorting aggregation resultset in Elasticsearch and filtering
本文介绍了在Elasticsearch中排序聚合结果集并进行过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Elasticsearch索引中的数据样本:
Data sample in Elasticsearch index:
"_source": {
"Type": "SELL",
"Id": 31,
"status": "YES",
"base": "FIAT",
"orderDate": "2019-02-01T05:00:00.000Z",
}
我需要1.根据'base'=?过滤记录和'Type'=?然后2.获取每个Id和THEN的这些筛选记录的堆栈顶部或最新记录3.从这些结果中,我只需要'status'='YES'的记录.
I need to 1. Filter the records based on 'base'=? and 'Type'=? THEN 2. get the top of stack or latest records for these filtered records for each Id and THEN 3. from the results of these I need only the records with 'status'= 'YES'.
我编写的Elasticsearch查询:
Elasticsearch query I wrote:
{
"size":0,
"query":{
"bool":{
"must":[
{ "match":{ "base":"FIAT" } },
{ "match":{ "Type":"SELL" } }
]
}
},
"aggs":{
"sources":{
"terms":{ "field":"Id" },
"aggs":{
"latest":{
"top_hits":{
"size":1,
"_source":{
"includes":[
"Id",
"orderDate",
"status"
]
},
"sort":{ "orderDate":"desc" }
}
}
}
}
}
}
推荐答案
您尝试使用复合聚合.
这篇关于在Elasticsearch中排序聚合结果集并进行过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文