【发布时间】:2017-06-16 01:06:14
【问题描述】:
(我对 ELK 堆栈还很陌生,可能会问一些明显的问题......)
我有描述客户信息的文件,包括姓名、地址、年龄等数据... 有时,并非所有这些字段都存在,我想知道填写了这些字段的文档数量。
如果数据看起来像:
PUT customers
{
"mappings": {
"customer": {
"properties": {
"id": {
"type": "integer"
},
"category": {
"type": "keyword"
},
"email": {
"type": "text"
},
"age": {
"type": "integer"
},
"address": {
"type": "text"
}
}
}
}
}
POST _bulk
{"index":{"_index":"customers","_type":"customer"}}
{"id":"1","category":"aa","email":"sam@test.com"}
{"index":{"_index":"customers","_type":"customer"}}
{"id": "2", "category" : "aa", "age": "5"}
{"index":{"_index":"customers","_type":"customer"}}
{"id": "3", "category" : "aa", "email": "bob@test.com", "age": "36"}
{"index":{"_index":"customers","_type":"customer"}}
{"id": "4", "category" : "bb", "email": "kim@test.com", "age": "42", "address": "london"}
我们的想法是在 Kibana 中可视化如下数据表:
+----------+-------+-------+-----+---------+
| category | total | email | age | address |
+----------+-------+-------+-----+---------+
| aa | 3 | 2 | 2 | 0 |
| bb | 1 | 1 | 1 | 1 |
+----------+-------+-------+-----+---------+
(例如:我们有 3 个客户属于“aa”类别;其中 2 个提供了他们的电子邮件,2 个提供了他们的年龄,没有一个提供了它的地址)
我可以通过如下查询弄清楚如何做到这一点:
POST /customers/_search?size=0
{
"aggs": {
"category": {
"terms": {
"field": "category"
},
"aggs": {
"count_email": {
"filter": {
"exists": {
"field": "email"
}
}
},
"count_age": {
"filter": {
"exists": {
"field": "age"
}
}
},
"count_address": {
"filter": {
"exists": {
"field": "address"
}
}
}
}
}
}
}
但我无法在 Kibana Visualize 中找到如何做到这一点。 我应该使用脚本字段吗? JSON 输入 ?如何 ?有没有更好的办法?
感谢您的建议。
【问题讨论】:
-
这没有给你合适的桌子?结果如何?
-
我更新了我的答案以包含 kibana 的起始 url...这更接近您的需要吗?
标签: elasticsearch kibana