# How to set alert on total size of indices matching a pattern?

**URL:** https://discuss.elastic.co/t/how-to-set-alert-on-total-size-of-indices-matching-a-pattern/330159
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [April 17, 2023, 6:37pm UTC](https://discuss.elastic.co/t/how-to-set-alert-on-total-size-of-indices-matching-a-pattern/330159 "2023-04-17T18:37:42Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ppine7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppine7/32/111560_2.png) [@ppine7](https://discuss.elastic.co/u/ppine7)
#### Post date: [April 17, 2023, 6:37pm UTC](https://discuss.elastic.co/t/how-to-set-alert-on-total-size-of-indices-matching-a-pattern/330159/1 "2023-04-17T18:37:42Z")

</div>

Hi!  
I've posted this question on SO: [elastic stack - Elasticsearch how to set alert on total size of indices matching a pattern? - Stack Overflow](https://stackoverflow.com/questions/76035746/elasticsearch-how-to-set-alert-on-total-size-of-indices-matching-a-pattern) but am re-posting it here in hopes to get a more focused audience 🙂

I would like to set an Alert Rule in Elastic - to trigger an alert when a total size of indices, matching a specific pattern, exceeds some limit.

I know how to get the total size by running a query:

```auto
GET /.ds-elastic-cloud-logs*/_stats

```

this would give me:

```auto
...
"_all": {
"primaries": {
  "docs": {
    "count": 12865686,
    "deleted": 0
  },
  "shard_stats": {
    "total_count": 5
  },
  "store": {
    "size_in_bytes": 2205540490,
    "total_data_set_size_in_bytes": 2205540490,
    "reserved_in_bytes": 0
  },
...

```

and the value I'm looking for is: **"size\_in\_bytes": 2205540490**

But I could not find how to create an alert based on this value...  
I looked at the "index threshold" type of alerts: [Index threshold | Kibana Guide [master] | Elastic](https://www.elastic.co/guide/en/kibana/master/rule-type-index-threshold.html) - and while I am able to specify the index pattern (.ds-elastic-cloud-logs\*) in the rule - the "size-in-bytes" field is not available for use in the alert...

Also looked at the "elasticsearch query" type of alerts: [Elasticsearch query | Kibana Guide [master] | Elastic](https://www.elastic.co/guide/en/kibana/master/rule-type-es-query.html) - but I can only get a count of documents returned by a query to be used as the metric, not the size of indices ...

Any other way to achieve what I want?  
Thank you!  
Marina

---

<div class="post-metadata">

### Author: ![grfneto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grfneto/32/125776_2.png) [@grfneto](https://discuss.elastic.co/u/grfneto)
#### Post date: [April 17, 2023, 9:20pm UTC](https://discuss.elastic.co/t/how-to-set-alert-on-total-size-of-indices-matching-a-pattern/330159/2 "2023-04-17T21:20:26Z")

</div>

Hi @ppine7

Have you tried to create a pipeline that gets information from the \_stats API and saves it in another index? In this other index that will make the storage summary, you can create an alert for the desired field. Another possibility, if applicable to your scenario, is the use of ILM to manage your index storage and perform the rollup.  
[ILM: Manage the index lifecycle | Elasticsearch Guide [8.7] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.7/index-lifecycle-management.html)

Best regards

---

<div class="post-metadata">

### Author: ![vincenbr](https://avatars.discourse-cdn.com/v4/letter/v/8edcca/32.png) [@vincenbr](https://discuss.elastic.co/u/vincenbr)
#### Post date: [April 17, 2023, 9:58pm UTC](https://discuss.elastic.co/t/how-to-set-alert-on-total-size-of-indices-matching-a-pattern/330159/3 "2023-04-17T21:58:54Z")

</div>

Hi,  
I am afraid you cannot (at least for now) call an arbitrary API with Kibana alert Rules.  
I would go with the [Watcher](https://www.elastic.co/guide/en/elasticsearch/reference/current/input-http.html), which is more flexible. You could get inspiration from sample Watches repo, like this one: [examples/Alerting/Sample Watches/large\_shard\_watch at master · elastic/examples · GitHub](https://github.com/elastic/examples/tree/master/Alerting/Sample%20Watches/large_shard_watch)

---

<div class="post-metadata">

### Author: ![ppine7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppine7/32/111560_2.png) [@ppine7](https://discuss.elastic.co/u/ppine7)
#### Post date: [April 18, 2023, 1:48pm UTC](https://discuss.elastic.co/t/how-to-set-alert-on-total-size-of-indices-matching-a-pattern/330159/4 "2023-04-18T13:48:46Z")

</div>

Thank you, @grfneto ! I was looking for something out of the box for Alerts - will keep this option in mind too. And I do use ILM - but wanted to add alerts as a precaution as well.

---

<div class="post-metadata">

### Author: ![ppine7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppine7/32/111560_2.png) [@ppine7](https://discuss.elastic.co/u/ppine7)
#### Post date: [April 18, 2023, 1:50pm UTC](https://discuss.elastic.co/t/how-to-set-alert-on-total-size-of-indices-matching-a-pattern/330159/5 "2023-04-18T13:50:14Z")

</div>

Thank you, @vincenbr ! I was hoping to have an out-of-the-box option like that for Alerts - will keep the Watch approach in mind - although as I checked the GIT repo example - it does look quite intimidating 🙂

---

<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: [May 16, 2023, 1:50pm UTC](https://discuss.elastic.co/t/how-to-set-alert-on-total-size-of-indices-matching-a-pattern/330159/6 "2023-05-16T13:50:31Z")

</div>

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