Kibana aggregation with missing / null fields

Background

Kibana is a good tool for aggregations. It looks like the group by in mysql. However Kibana will ignore documents without a given field when computing the aggregation. How can we take those documents with the given field missing into accout?

Let us take an example.

{                                                                                  
  "k": "v",                                                                        
  "k1": "v1"                                                                       
}                                                                                  
{                                                                                  
  "k": "v",                                                                        
  "k1": "v2"                                                                       
}                                                                                  
{                                                                                  
  "k": "v",                                                                        
  "k1": "v2"                                                                       
}                                                                                  
{                                                                                  
  "k": "v",                                                                        
  "k1": "v2"                                                                       
}                                                                                  
{                                                                                  
  "k": "v",                                                                        
}  

We have 5 documents, and when we aggregate over the k1 field in Kibana visualization, then it will return results like the following:

{                                                                                  
  "v1": 1,                                                                         
  "v2": 3,                                                                         
} 

LOOK, it misses the last document which does not contain k1. How can we solve this?

Solution

This is a normal aggregation (will ignore documents with missing fields).
这里写图片描述

We can configure the aggregation buckets like this. We add the json in the JSON Input

{"missing":"NULL"}

This says if it comes across a document without this field, then this document will be classified into NULL bucket.
这里写图片描述

If we apply this to the above case, the final results should return like

{                                                                                  
  "v1": 1,                                                                         
  "v2": 3,                                                                         
  "NULL": 1                                                                        
}

Another case

Before using {"missing": "NULL"}, it looks like,
这里写图片描述

After using {"missing": "NULL"}, it looks like:
这里写图片描述

Hope this helps. If you got any question, you are welcome to contact me via:

  • email: nisxiya@yeah.net
  • wechat: nisxiya
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值