# Watcher - Divide two input in advanced alert

**URL:** <https://discuss.elastic.co/t/watcher-divide-two-input-in-advanced-alert/161333>\
**Category:** Elasticsearch\
**Created:** [December 18, 2018, 1:17pm UTC](https://discuss.elastic.co/t/watcher-divide-two-input-in-advanced-alert/161333 "2018-12-18T13:17:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cemkuleyin](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@cemkuleyin](https://discuss.elastic.co/u/cemkuleyin)\
**Post date:** [December 18, 2018, 1:17pm UTC](https://discuss.elastic.co/t/watcher-divide-two-input-in-advanced-alert/161333/1 "2018-12-18T13:17:29Z")

</div>

Hi all,

I created advanced alert on watcher. But my condition didnt work. I want to calculate first input divide to second input. but cannot calculate.

Can you help me?

**_My condition -\>_**

"condition": {  
"script": {  
"source": "return (ctx.payload.first.hits.total / ctx.payload.second.hits.total) \> 0.8",  
"lang": "painless"\*\*  
}

_ **My json-\>** _

{  
"trigger": {  
"schedule": {  
"interval": "1h"  
}  
},  
"input": {  
"chain": {  
"inputs": [  
{  
"first": {  
"search": {  
"request": {  
"search\_type": "query\_then\_fetch",  
"indices": [  
"graylog\*"  
],  
"types": ,  
"body": {  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"ctxt\_page\_name": "Thank You"  
}  
}  
],  
"filter": {  
"range": {  
"timestamp": {  
"gte": "now-10m"  
}  
}  
}  
}  
}  
}  
},  
"extract": [  
"hits.total"  
]  
}  
}  
},  
{  
"second": {  
"search": {  
"request": {  
"search\_type": "query\_then\_fetch",  
"indices": ,  
"types": ,  
"body": {  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"ctxt\_page\_name": "Payment"  
}  
}  
],  
"filter": {  
"range": {  
"timestamp": {  
"gte": "now-10m"  
}  
}  
}  
}  
}  
}  
},  
"extract": [  
"hits.total"  
]  
}  
}  
}  
]  
}  
},  
"condition": {  
"script": {  
"source": "return (ctx.payload.first.hits.total / ctx.payload.second.hits.total) \> 0.8",  
"lang": "painless"  
}  
},  
"actions": {  
"send\_email": {  
"email": {  
"profile": "standard",  
"to": [  
"cem.kuleyin@enuygun.com"  
],  
"subject": "Watcher Notification",  
"body": {  
"text": "{{ctx.payload.first.hits.total}} Thank You - {{ctx.payload.second.hits.total}} Payment "  
}  
}  
}  
},  
"throttle\_period\_in\_millis": 60000  
}

---

<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:** [January 15, 2019, 1:17pm UTC](https://discuss.elastic.co/t/watcher-divide-two-input-in-advanced-alert/161333/2 "2019-01-15T13:17:35Z")

</div>

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