# Count of hits per error

**URL:** https://discuss.elastic.co/t/count-of-hits-per-error/182486
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [May 23, 2019, 3:37pm UTC](https://discuss.elastic.co/t/count-of-hits-per-error/182486 "2019-05-23T15:37:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![devendra121dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/devendra121dev/32/46736_2.png) [@devendra121dev](https://discuss.elastic.co/u/devendra121dev)
#### Post date: [May 23, 2019, 3:37pm UTC](https://discuss.elastic.co/t/count-of-hits-per-error/182486/1 "2019-05-23T15:37:22Z")

</div>

Hi,

I am trying to get email notification with number of hits for each error types mentioned in my below query.

{  
"trigger": {  
"schedule": {  
"daily": {  
"at": [  
{  
"hour": [  
7,  
17  
],  
"minute": [  
0,  
30  
]  
}  
]  
}  
}  
},  
"input": {  
"search": {  
"request": {  
"search\_type": "query\_then\_fetch",  
"indices": [  
"\<filebeat-{now/d-7d}\>"  
],  
"types": ,  
"body": {  
"query": {  
"bool": {  
"should": [  
{  
"match\_phrase": {  
"message": "Error 1"  
}  
},  
{  
"match\_phrase": {  
"message": "Error 2"  
}  
}  
]  
}  
}  
}  
}  
}  
},  
"condition": {  
"compare": {  
"ctx.payload.hits.total": {  
"gt": 0  
}  
}  
},  
"actions": {  
"email\_administrator": {  
"email": {  
"profile": "standard",  
"attach\_data": {  
"format": "yaml"  
},  
"priority": "high",  
"to": [  
"abc@demo.com"  
],  
"subject": {  
"source": "{{ctx.metadata.color}} ERROR DEMO",  
"lang": "mustache"  
},  
"body": {  
"text": "Hello All, \n \n\n Issues the logs. \n\nCould you please check attached data ? \n \n Find the list of stores to check for failure:\n\n{{#ctx.payload.hits.hits}} \* Host = {{\_source.host}}, Log Time = {{\_source.LogTime}}\n\n{{/ctx.payload.hits.hits}}\n\nThank you\nKibana"  
}  
}  
}  
}  
}

The format I want should look like below table, where first error came for 5 times and 2nd error came for 7 times.  
|SN|Error Name|hits#|  
|1|Error 1|5|  
|2|Error 2|7|

Any type of help is appreciated.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [May 28, 2019, 8:46am UTC](https://discuss.elastic.co/t/count-of-hits-per-error/182486/2 "2019-05-28T08:46:51Z")

</div>

please take your time and format messages properly. Those are impossible to read. You can use markdown for sourcecode formatting here, which will also fix the indenting and make this much more readable.

I also have a hard time to understand, what exactly you are expecting and what is not working. Maybe you can describe it again and also show a sample search result in order to explain things.

--Alex

---

<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: [June 25, 2019, 8:47am UTC](https://discuss.elastic.co/t/count-of-hits-per-error/182486/3 "2019-06-25T08:47:06Z")

</div>

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