# Capture-now-and-now-15min & Array\_compare condition

**URL:** <https://discuss.elastic.co/t/capture-now-and-now-15min-array-compare-condition/207855>\
**Category:** Elasticsearch\
**Created:** [November 14, 2019, 10:13am UTC](https://discuss.elastic.co/t/capture-now-and-now-15min-array-compare-condition/207855 "2019-11-14T10:13:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Irfan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muhammad_irfan/32/47241_2.png) [@Muhammad\_Irfan](https://discuss.elastic.co/u/Muhammad_Irfan)\
**Post date:** [November 14, 2019, 10:13am UTC](https://discuss.elastic.co/t/capture-now-and-now-15min-array-compare-condition/207855/1 "2019-11-14T10:13:39Z")

</div>

**Dear All,**

Greetings! I have been working on Watcher and successfully received email notification but want to make changes as per my assignment. So need your assistance and help

Task :  
ELK work as a anti-spam filter and my task is watcher trigger email if sender is not from "for e.g Germany" country and domain should not be ".com"

Additional Task :

1- Capture-now-and-now-15min in watcher email body  
2-Array\_compare condition met but shows values which is not required.

Please find JSON code..

> {  
> "trigger": {  
> "schedule": {  
> "interval": "1m"  
> }  
> },  
> "input": {  
> "search": {  
> "request": {  
> "search\_type": "query\_then\_fetch",  
> "indices": [  
> "file-name-_"  
> ],  
> "rest\_total\_hits\_as\_int": true,  
> "body": {  
> "size": 0,  
> "query": {  
> "bool": {  
> "filter": [  
> {  
> "range": {  
> "@timestamp": {  
> "from": "now-5m",  
> "to": "now"  
> }  
> }  
> },  
> {  
> "wildcard": {  
> "sender": {  
> "value": "_.com"  
> }  
> }  
> },  
> {  
> "exists": {  
> "field": "sender.keyword"  
> }  
> }  
> ],  
> "must\_not": [  
> {  
> "match\_phrase": {  
> "geoip.country\_name": {  
> "query": "Germany"  
> }  
> }  
> },  
> {  
> "match\_phrase": {  
> "sender": "reply "  
> }  
> },  
> {  
> "match\_phrase": {  
> "sender": "bounce"  
> }  
> },  
> {  
> "match\_phrase": {  
> "sender": "bounces"  
> }  
> },  
> {  
> "match\_phrase": {  
> "sender": "srs0"  
> }  
> },  
> {  
> "match\_phrase": {  
> "sender": "prvs="  
> }  
> },  
> {  
> "match\_phrase": {  
> "is\_spam.keyword": {  
> "query": "1"  
> }  
> }  
> }  
> ]  
> }  
> },  
> "aggs": {  
> "sender\_email": {  
> "terms": {  
> "field": "sender.keyword",  
> "size": 5,  
> "order": {  
> "\_count": "desc"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> },  
> "condition": {  
> "array\_compare": {  
> "ctx.payload.aggregations.sender\_email.buckets": {  
> "path": "doc\_count",  
> "gt": {  
> "value": 50,  
> "quantifier": "some"  
> }  
> }  
> }  
> },  
> "actions": {  
> "email\_admin": {  
> "email": {  
> "profile": "standard",  
> "to": [  
> "myemal@.com"  
> ],  
> "subject": "spam email notification",  
> "body": {  
> "html": "
> 
> {{#ctx.payload.aggregations.sender\_email.buckets}} 
> 
> | Sender | Count |
> | --- | --- |
> | {{key}} | {{doc\_count}}{{/ctx.payload.aggregations.sender\_email.buckets}} |
> 
> "  
> }  
> }  
> }  
> }  
> }

> WATCHER OUTPUT  
> ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/f/0f6b3214dcf283b3460a14d0d2a8d9114696c0d1.png)

> As per my array condition, emails counts should be greater then 50, but with 50+ counts i m also getting count less than 50 so please assist  
> gt": {  
> "value": 50,  
> "quantifier": "some"

> Secondly, i want to add time range ["from": "now-5m", "to": "now"] in my watcher body so my output will be like this

Dear Team,

We are receiving spam email from below users with time range : Thu 14/11/2019 2:08 PM to Thu 14/11/2019 2:13 PM

![image](https://us1.discourse-cdn.com/elastic/original/3X/0/f/0f6b3214dcf283b3460a14d0d2a8d9114696c0d1.png)

> so I need your urgent help to complete this task 🙂

Regards,  
Irfan

---

<div class="post-metadata">

**Author:** ![Muhammad\_Irfan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muhammad_irfan/32/47241_2.png) [@Muhammad\_Irfan](https://discuss.elastic.co/u/Muhammad_Irfan)\
**Post date:** [November 16, 2019, 10:01am UTC](https://discuss.elastic.co/t/capture-now-and-now-15min-array-compare-condition/207855/2 "2019-11-16T10:01:15Z")

</div>

Dears,

I m still waiting for your valuable comments

Regards,  
IQ

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 14, 2019, 10:01am UTC](https://discuss.elastic.co/t/capture-now-and-now-15min-array-compare-condition/207855/3 "2019-12-14T10:01:20Z")

</div>

Closed on December 14, 2019, 10:01am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
