Elasticsearch NodeJS Watcher
This is alternative to Elasticsearch X-Pack Watcher.
npm install --save elasticsearch-nodejs-watcher
Example usage - asking Elasticsearch each 30s if any new document that matches query appeared.
It's important that schedule and timestamp filter refer to same interval, e.g. schedule each 30s and filter timestamp now-30s. This blocks appearing already matched documents in new call.
const elasticWatcher = ;const connection =host: ''log: 'trace';const watcher =schedule: "*/30 * * * * *"query:index: 'logstash-*'body:query:bool:must: match: loglevel: "ERROR"filter:range: "@timestamp": gte: "now-30s"total > 0consoleconsole;elasticWatcher;
- Schedule is telling watcher when it needs to call Elasticsearch Values are provided in cron notation.
- Query is Elasticsearch's query object. Use it like in Elasticsearch Watcher. Query DSL documentation
- Predicate is same as Elasticsearch Condition. It checks if action should be executed.
- Action is task which will be executed when predicate returns true. Action is executed within Schedule. Data contains extracted hits and whole response.
- Error handler (optional) can be used to handle errors from Elasticsearch.
Elasticsearch connection configuration
Check out Elasticsearch.js documentation