Hi All,
I am working on a aggregation and I am looking from a count of uniqueue senders and source ip's derived from a email subject.
I am trying the following but it does not seem to give what I need, I hope some one can help me with this.
Aggration:
{
"size": 0,
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "tags:cmgw AND action:P6* AND _exists_:hdr_subject AND cm_score: [0 TO 90] AND NOT dkim:pass* AND NOT dmarc:pass*",
"analyze_wildcard": true
}
},
{
"range": {
"@timestamp": {
"gte": "now-5m",
"lte": "now"
}
}
}
],
"must_not": []
}
},
"aggs": {
"2": {
"terms": {
"field": "hdr_subject.keyword",
"size": 15,
"order": {
"_count": "desc"
}
},
"aggs": {
"3": {
"terms": {
"field": "ip",
"size": 10,
"order": {
"_count": "desc"
}
},
"aggs": {
"4": {
"value_count": {
"field": "hdr_from.keyword"
}
}
}
}
}
}
}
}
Output:
"aggregations": {
"2": {
"doc_count_error_upper_bound": 38,
"sum_other_doc_count": 5756,
"buckets": [
{
"3": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 2,
"buckets": [
{
"4": {
"value": 409
},
"key": "46.236.37.165",
"doc_count": 409
},
{
"4": {
"value": 352
},
"key": "46.236.37.155",
"doc_count": 352
},
{
"4": {
"value": 198
},
"key": "46.236.37.151",
"doc_count": 198
},
{
"4": {
"value": 2
},
"key": "77.238.176.205",
"doc_count": 2
},
{
"4": {
"value": 1
},
"key": "62.24.135.68",
"doc_count": 1
},
{
"4": {
"value": 1
},
"key": "62.128.193.156",
"doc_count": 1
},
{
"4": {
"value": 1
},
"key": "64.147.108.55",
"doc_count": 1
},
{
"4": {
"value": 1
},
"key": "91.136.10.27",
"doc_count": 1
},
{
"4": {
"value": 1
},
"key": "185.201.17.31",
"doc_count": 1
},
{
"4": {
"value": 1
},
"key": "209.85.161.174",
"doc_count": 1
}
]
},
"key": "Fantastic new properties...",
"doc_count": 969
}
Expected output:
"aggregations": {
"2": {
"doc_count_error_upper_bound": 38,
"sum_other_doc_count": 5756,
"buckets": [
{
"3": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 2,
"buckets": [
{
"uniqueFromAddr": {
"value": 1
},
"key": "46.236.37.165",
"doc_count": 409
},
{
"uniqueFromAddr": {
"value": 2
},
"key": "56.236.37.13",
"doc_count": 409
}
]
},
"key": "Fantastic new properties...",
"doc_count": 969
}]
}