elasticsearch - Elasticsearch 过滤聚合以返回一个指标
问题描述
我正在尝试计算在 Elasticsearch 上安装我的应用程序的用户百分比。
为了实现这一点,我做如下:
- 在索引上查询所有感兴趣的用户
filters bucket aggregation
过滤安装了android和ios应用程序的人sum_bucket
聚合以返回安装应用程序的用户总数。- Javascript在响应中使用
total hits
和计算百分比。total values
我的问题是是否有一种方法可以在聚合步骤上创建一个过滤器,它允许我只制作一个具有两个条件的过滤器并返回一个指标而不是一个存储桶,所以我可以跳过第 3 步。
这是我的查询:
{
"size": 0,
"query": {
"bool": {
"must": [
{
"match": {
"fieldId": "uuid"
}
}
]
}
},
"aggs": {
"byInstalled": {
"filters": {
"filters": [
{
"range": {
"firstIOSLoginAt": {
"gte": "2020-06-15T06:56:10.436Z",
"lte": "2022-06-15T06:56:10.436Z"
}
}
},
{
"range": {
"firstAndroidLoginAt": {
"gte": "2020-06-15T06:56:10.436Z",
"lte": "2022-06-15T06:56:10.436Z"
}
}
}
]
}
},
"totalInstalled": {
"sum_bucket": {
"buckets_path": "byInstalled>_count"
}
}
}
}
这是回应:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 546,
"relation" : "gte"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"byInstalled" : {
"meta" : { },
"buckets" : [
{
"doc_count" : 2
},
{
"doc_count" : 1
}
]
},
"totalInstalled" : {
"value" : 3.0
}
}
}
提前致谢。
解决方案
推荐阅读
- angular - 如何在 Angular 6+ 中实现 systemjs?
- azure-data-explorer - Kusto IngestionTime 策略是否存在于扩展级别或记录级别?
- svg - 如何转一个
(在一个svg里面)到一个复选框? - reactjs - 如何通过 Axios Post 方法将成功消息传递给另一个组件
- python - 每次发生“while”循环时,如何向列表添加新值?
- typescript - 在自定义定义中引用全局声明的命名空间类型
- android - 在 Android Java 中第一次调用后 LiveData 没有更新
- php - 如何包含应该内置的缺少的 PHP 函数?
- swift - 未捕获的异常 'NSInvalidArgumentException',原因:'-[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例
- c# - 将 WebClient.DownloadString 的结果拆分为多行