elasticsearch - 如何获取 Elastic 中每次出现的文档数量?
问题描述
我有一个弹性索引(比如file
),每次客户端下载文件时,我都会在其中附加一个文档。每个文档都非常基础,它包含一个字段filename
和一个日期when
来指示下载时间。
我想要实现的是获取每个文件在过去 3 个月内下载的次数。
目前,我最接近这个查询:
{
"query": {
"range": {
"when": {
"gte": "now-3M"
}
}
},
"aggs": {
"downloads": {
"terms": {
"field": "filename.keyword"
}
}
}
}
结果是这样的:
{
"took": 793,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 10000,
"relation": "gte"
},
"max_score": 1.0,
"hits": [
{
"_index": "file",
"_type": "_doc",
"_id": "8DkTFHQB3kG435svAA3O",
"_score": 1.0,
"_source": {
"filename": "taz",
"id": 24009,
"when": "2020-08-21T08:11:54.943Z"
}
},
...
]
},
"aggregations": {
"downloads": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 418486,
"buckets": [
{
"key": "file1",
"doc_count": 313873
},
{
"key": "file2",
"doc_count": 281504
},
...,
{
"key": "file10",
"doc_count": 10662
}
]
}
}
}
所以我对 很感兴趣aggregations.downloads.bucket
,但这仅限于 10 个结果。
我需要在查询中进行哪些更改才能获得所有列表(在我的情况下,我将拥有约 15,000 个不同的文件)?
谢谢。
解决方案
推荐阅读
- reactjs - 如何删除 React-Bootstrap 中 FormControl 组件默认提供的 class="form-control"
- javascript - 我可以从 HTML 字符串或 dom 节点/元素创建 React 元素吗
- actionscript-3 - cs6的charCode有什么替代品吗?
- google-app-engine - IntelliJ 寻找 appcfg.sh,但只存在 appcfg.py
- ruby - 无法定位框架?红宝石
- ios - 每次点击单元格时都会运行 layoutSubviews()
- c# - 如何将 MVVM 视图注入到 shell UWP 页面的区域中
- python - 如何将通知编号添加到按钮图标?
- c++ - 如何本地化格式为“[-][+]Xh Xmin”的文本
- powershell - Set-ADUser 不处理空或空变量