# Compare the number of indexes

**URL:** https://discuss.elastic.co/t/compare-the-number-of-indexes/109726
**Category:** Elasticsearch
**Created:** [November 30, 2017, 10:09am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726 "2017-11-30T10:09:18Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [November 30, 2017, 10:09am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/1 "2017-11-30T10:09:18Z")

</div>

Is there a way to compare the number of indexes created today with the number of indexes that existed already using a search operation with query?

---

<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: [December 1, 2017, 8:13am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/2 "2017-12-01T08:13:00Z")

</div>

No, there is no query support for that. But using this call to query all index settings, you can find out the creation dates of all indices

```auto
GET _settings?human&filter_path= **.creation_date_string,**.creation_date

```

---

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [December 5, 2017, 8:48am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/3 "2017-12-05T08:48:09Z")

</div>

So sad! I really would like to know when an index was created or deleted using watcher. But I just get the creation dates of all indices.  
I did it like this:

```
PUT _watcher/watch/my-watcher
{
  "trigger": {
    "schedule": {
      "daily": {
        "at": "05:00"
      }
    }
  },
  "input": {
    "http": {
      "request": {
        "host": "localhost",
        "port": 9200,
        "path": "/_all/_settings/index.creation_date",
        "method": "get"
      }
    }
  },
  "condition": {
     "always": {}
  },
  "throttle_period": "3h",
  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "to": "my-email",
        "subject": "List of all indices",
        "body": {
          "html": "Creation dates of all indexes: {{ctx.payload}}"
        }
      }
    }
  }
}

```

When I execute my-watcher, I see the creation date of my-index:

```
"my-index": {
   "settings": {
      "index": {
         "creation_date": "1511451835244"
       }
    }
 }

```

If I replace the path with

`settings?human&filter_path= **.creation_date_string,**.creation_date`

The payload is empty.

Or if I replace the path with

`"path": "/_all/_settings/index.creation_date_string"`

The payload is also empty.

Do you have any idea how I can get the creation\_date\_string to show in the payload of my watcher?

---

<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: [December 6, 2017, 8:49am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/4 "2017-12-06T08:49:56Z")

</div>

can you paste (properly formatted please) the output of the [Execute Watch API](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/watcher-api-execute-watch.html) for this watch please? This will make it much easier to take a closer look.

---

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [December 7, 2017, 8:29am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/5 "2017-12-07T08:29:24Z")

</div>

Hi @spinscale, sure!  
I changed the name of the index AND the name of the watcher to **library**.  
This is the output:

> ```
> {
> "_id": "library_0-2017-12-07T08:24:27.930Z",
> "watch_record": {
> "watch_id": "library",
> "state": "executed",
> "trigger_event": {
> "type": "manual",
> "triggered_time": "2017-12-07T08:24:27.923Z",
> "manual": {
> "schedule": {
> "scheduled_time": "2017-12-07T08:24:27.923Z"
> }
> }
> },
> "input": {
> "http": {
> "request": {
> "scheme": "http",
> "host": "localhost",
> "port": 9200,
> "method": "get",
> "path": "/_all/_settings/index.creation_date",
> "params": {},
> "headers": {}
> }
> }
> },
> "condition": {
> "always": {}
> },
> "messages": [],
> "result": {
> "execution_time": "2017-12-07T08:24:27.930Z",
> "execution_duration": 296,
> "input": {
> "type": "http",
> "status": "success",
> "payload": {
> ".watch_history-2017.11.28": {
> "settings": {
> "index": {
> "creation_date": "1511870100625"
> }
> }
> },
> "test": {
> "settings": {
> "index": {
> "creation_date": "1511865319097"
> }
> }
> },
> ".kibana": {
> "settings": {
> "index": {
> "creation_date": "1511450953109"
> }
> }
> },
> ".triggered_watches": {
> "settings": {
> "index": {
> "creation_date": "1511450988459"
> }
> }
> },
> ".watches": {
> "settings": {
> "index": {
> "creation_date": "1511450981480"
> }
> }
> },
> ".watch_history-2017.11.30": {
> "settings": {
> "index": {
> "creation_date": "1512042240371"
> }
> }
> },
> "library": {
> "settings": {
> "index": {
> "creation_date": "1511451835244"
> }
> }
> }
> },
> "http": {
> "request": {
> "host": "localhost",
> "port": 9200,
> "scheme": "http",
> "method": "get",
> "path": "/_all/_settings/index.creation_date"
> },
> "status_code": 200
> }
> },
> "condition": {
> "type": "always",
> "status": "success",
> "met": true
> },
> "actions": [
> {
> "id": "send_email",
> "type": "email",
> "status": "success",
> "email": {
> "account": "exchange_account",
> "message": {
> "id": "library_0-2017-12-07T08:24:27.930Z",
> "from": " **my email**",
> "sent_date": "2017-12-07T08:24:28.008Z",
> "to": [
> " **my email**"
> ],
> "subject": "New index",
> "body": {
> "html": "Creation date of all indexes: {.watch_history-2017.11.28&#61;{settings&#61;{index&#61;{creation_date&#61;1511870100625}}}, test&#61;{settings&#61;{index&#61;{creation_date&#61;1511865319097}}}, .kibana&#61;{settings&#61;{index&#61;{creation_date&#61;1511450953109}}}, .triggered_watches&#61;{settings&#61;{index&#61;{creation_date&#61;1511450988459}}}, .watches&#61;{settings&#61;{index&#61;{creation_date&#61;1511450981480}}}, .watch_history-2017.11.30&#61;{settings&#61;{index&#61;{creation_date&#61;1512042240371}}}, library&#61;{settings&#61;{index&#61;{creation_date&#61;1511451835244}}}}"
> }
> }
> }
> }
> ]
> }
> }
> }
> 
> ```

And I get in my email the content:

> Creation date of all indexes: {.watch\_history-2017.11.28={settings={index={creation\_date=1511870100625}}}, test={settings={index={creation\_date=1511865319097}}}, .kibana={settings={index={creation\_date=1511450953109}}}, .triggered\_watches={settings={index={creation\_date=1511450988459}}}, .watches={settings={index={creation\_date=1511450981480}}}, .watch\_history-2017.11.30={settings={index={creation\_date=1512042240371}}}, library={settings={index={creation\_date=1511451835244}}}}

with html format

---

<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: [December 7, 2017, 8:42am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/6 "2017-12-07T08:42:48Z")

</div>

the `human` parameter in your http request is missing to show the creation date string

---

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [December 7, 2017, 8:48am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/7 "2017-12-07T08:48:56Z")

</div>

But if I put this in the path field inside of **input** , e.g. like this:

> "input": {  
> "http": {  
> "request": {  
> "host": "localhost",  
> "port": 9200,  
> "path": "/\_all/\_settings?human=index.creation\_date\_string",  
> "method": "get"  
> }  
> }  
> }

the payload is empty, it means that I get also an empty email content...

---

<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: [December 7, 2017, 8:57am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/8 "2017-12-07T08:57:32Z")

</div>

have you tried setting this as parameter? Or just try

```auto
"url" : "http://localhost:9200/_all/settings?human`

```

instead of using `host`, `port`, `scheme` and `path`

---

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [December 7, 2017, 9:26am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/9 "2017-12-07T09:26:37Z")

</div>

I just tried it out like this:

> "input": {  
> "http": {  
> "request": {  
> "url": "[http://localhost:9200/\_all/\_settings?human=index.creation\_date\_string](http://localhost:9200/_all/_settings?human=index.creation_date_string)",  
> "method": "get"  
> }  
> }  
> }

And got the following error:

> {  
> "error": {  
> "root\_cause": [  
> {  
> "type": "parse\_exception",  
> "reason": "could not parse http request template. unexpected string field [url]"  
> }  
> ],  
> "type": "parse\_exception",  
> "reason": "could not parse [http] input for watch [library]. failed to parse http request template",  
> "caused\_by": {  
> "type": "parse\_exception",  
> "reason": "could not parse http request template. unexpected string field [url]"  
> }  
> },  
> "status": 400  
> }

---

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [December 7, 2017, 9:51am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/10 "2017-12-07T09:51:21Z")

</div>

I just figured out why I got the error. I am using version 2.1 of Elasticsearch. There is no url field in this version. And the problem is if I add human after \_settings? it shows nothing as result.

---

<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 4, 2018, 9:51am UTC](https://discuss.elastic.co/t/compare-the-number-of-indexes/109726/11 "2018-01-04T09:51:28Z")

</div>

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