GET kibana_sample_data_logs/_search?filter_path=aggregations
{
"size":0,
"query": {
"bool": {
"filter": [
{
"match_phrase": {
"event.dataset": "sample_web_logs"
}
},
{
"range": {
"@timestamp": {
"gte": "2022-01-30T03:00:00.000Z",
"lte": "2022-01-30T04:00:00.000Z",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
],
"should": [],
"must_not": []
}
},
"aggs": {
"geo_dest": {
"terms": {
"field": "geo.dest",
"size": 2
},
"aggs": {
"per_15m": {
"date_histogram": {
"field": "@timestamp",
"fixed_interval": "15m"
},
"aggs": {
"referer_count": {
"cardinality": {
"field": "referer"
}
},
"card": {
"cumulative_cardinality": {
"buckets_path": "referer_count"
}
},
"referer_count_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"Referers": "referer_count",
"Cards": "card"
},
"script": "false"
}
}
}
},
"bucket_existing_bucket_filter":{
"bucket_selector": {
"buckets_path": {
"count":"per_15m._bucket_count"
},
"script": "params.count>0"
}
}
}
}
}
}
{
"aggregations" : {
"geo_dest" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 6,
"buckets" : [ ]
}
}
}
if you set referer_count_bucket_filter
to true
:
GET kibana_sample_data_logs/_search?filter_path=aggregations
{
"size":0,
"query": {
"bool": {
"filter": [
{
"match_phrase": {
"event.dataset": "sample_web_logs"
}
},
{
"range": {
"@timestamp": {
"gte": "2022-01-30T03:00:00.000Z",
"lte": "2022-01-30T04:00:00.000Z",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
],
"should": [],
"must_not": []
}
},
"aggs": {
"geo_dest": {
"terms": {
"field": "geo.dest",
"size": 2
},
"aggs": {
"per_15m": {
"date_histogram": {
"field": "@timestamp",
"fixed_interval": "15m"
},
"aggs": {
"referer_count": {
"cardinality": {
"field": "referer"
}
},
"card": {
"cumulative_cardinality": {
"buckets_path": "referer_count"
}
},
"referer_count_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"Referers": "referer_count",
"Cards": "card"
},
"script": "true"
}
}
}
},
"bucket_existing_bucket_filter":{
"bucket_selector": {
"buckets_path": {
"count":"per_15m._bucket_count"
},
"script": "params.count>0"
}
}
}
}
}
}
{
"aggregations" : {
"geo_dest" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 6,
"buckets" : [
{
"key" : "IN",
"doc_count" : 4,
"per_15m" : {
"buckets" : [
{
"key_as_string" : "2022-01-30T03:15:00.000Z",
"key" : 1643512500000,
"doc_count" : 2,
"referer_count" : {
"value" : 1
},
"card" : {
"value" : 1
}
},
{
"key_as_string" : "2022-01-30T03:30:00.000Z",
"key" : 1643513400000,
"doc_count" : 2,
"referer_count" : {
"value" : 1
},
"card" : {
"value" : 2
}
}
]
}
},
{
"key" : "CN",
"doc_count" : 2,
"per_15m" : {
"buckets" : [
{
"key_as_string" : "2022-01-30T03:45:00.000Z",
"key" : 1643514300000,
"doc_count" : 2,
"referer_count" : {
"value" : 1
},
"card" : {
"value" : 1
}
}
]
}
}
]
}
}
}
With this bucket_existing_bucket_filter
, you can select geo_dest
buckets only containing any buckets.