我们正在对我们的应用程序日志文件运行报告,这些日志文件收集在ElasticSearch存储中。
@timestamp:
Oct 24, 2023 @ 20:15:52.043
Action:
INSTALL
Components:
a; b
UserName:
U12345
字符串
最后,我需要运行一个查询,它将按组件分组,并返回安装计数和完成这些操作的唯一用户。
我可以在查询中按原始Components字段分组,结果如下:
{
"key" : "a;b",
"doc_count" : 10,
"unique_user_ids" : {
"value" : 2
}
},
{
"key" : "a;c",
"doc_count" : 8,
"unique_user_ids" : {
"value" : 1
}
},
型
然而,我不知道如何计算每个记录的次数,因为一个组件被列出,得到的结果如下
{
"key" : "a",
"doc_count" : 18,
"unique_user_ids" : {
"value" : 3
}
},
{
"key" : "b",
"doc_count" : 10,
"unique_user_ids" : {
"value" : 2
}
},
{
"key" : "c",
"doc_count" : 8,
"unique_user_ids" : {
"value" : 1
}
},
型
1条答案
按热度按时间0qx6xfy61#
如果你可以控制你要进入的数据,最好的方法是在索引它之前拆分键。换句话说,你的记录应该变成:
字符串
一个不需要重新索引数据的慢得多的解决方案是使用运行时字段来拆分组件。运行时字段可以在查询或in the index mapping中定义。下面是如何在查询中执行的示例:
型