Compare the number of indexes

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?

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

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

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?

can you paste (properly formatted please) the output of the Execute Watch API for this watch please? This will make it much easier to take a closer look.

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={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}}}}"
              }
            }
          }
        }
      ]
    }
  }
}

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

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

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...

have you tried setting this as parameter? Or just try

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

instead of using host, port, scheme and path

I just tried it out like this:

"input": {
"http": {
"request": {
"url": "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
}

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.

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