我的索引有两个字段-
更新日期字段(例如“2020-01-04t05:00:06.870000z”)
numwrites是一个float
我需要一个问题-
按日期(yyyy-mm-dd)降序排序
对于每一天,按numwrites降序排序
样本数据:
"_source": {
"updated": "2020-01-04T05:00:06.870000Z",
"numWrites": 5.0
}
"_source": {
"updated": "2020-01-04T09:00:08.870000Z",
"numWrites": 3.0
}
"_source": {
"updated": "2019-12-04T01:00:06.870000Z",
"numWrites": 15.0
}
"_source": {
"updated": "2019-12-04T04:00:06.870000Z",
"numWrites": 12.0
}
}
以下查询按日期排序。但是,在同一天内,它没有排序 numWrites
正如所料,同一天内的时间戳是不同的。如何从yyyy-mm-dd中提取日期,然后按排序 numWrites
一天之内?
查询:
{
"sort":[
{"updated": {"order" : "desc"}},
{"numWrites": {"order" : "desc"}}
]
}
结果:
"_source": {
"updated_time": "2020-01-04T09:00:08.870000Z",
"numWrites": 3.0
}
"_source": {
"updated": "2020-01-04T05:00:06.870000Z",
"numWrites": 5.0
}
"_source": {
"updated_time": "2019-12-04T04:00:06.870000Z",
"numWrites": 12.0
}
"_source": {
"updated_time": "2019-12-04T01:00:06.870000Z",
"numWrites": 15.0
}
1条答案
按热度按时间vjrehmav1#
如果我已经很好地理解了您的问题,那么您可以使用子聚合,首先按日期排序,然后按这些天的numwrites排序。以下是建议的解决方案:
我试着在同一天添加两个numwrite。以下是我的示例索引:
对于日期“2019-12-04t04:00:06.870z”,我有两个numwrite,得到的结果是: