List of indices that were getting data 2 days ago, but not in the last 1 day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST _watcher/watch/_execute | |
{ | |
"watch": { | |
"trigger": { | |
"schedule": { | |
"interval": "1d" | |
} | |
}, | |
"metadata": { | |
"longer_time": "2d/d", | |
"shorter_time": "1d/d" | |
}, | |
"input": { | |
"search": { | |
"request": { | |
"indices": [ | |
"al*", "stir*" | |
], | |
"body": { | |
"size": 0, | |
"aggs": { | |
"indices": { | |
"terms": { | |
"field": "_index", | |
"size": 1000 | |
}, | |
"aggs": { | |
"older": { | |
"filter": { | |
"query_string": { | |
"default_field": "@timestamp", | |
"query": "@timestamp:[now-{{ctx.metadata.longer_time}} TO now-{{ctx.metadata.shorter_time}}]" | |
} | |
} | |
}, | |
"newer": { | |
"filter": { | |
"query_string": { | |
"default_field": "@timestamp", | |
"query": "@timestamp:[now-{{ctx.metadata.shorter_time}} TO now]" | |
} | |
} | |
}, | |
"expose_olders_not_in_newers": { | |
"bucket_selector": { | |
"buckets_path": { | |
"older": "older._count", | |
"newer": "newer._count" | |
}, | |
"script": "params.older > 0 && params.newer == 0" | |
} | |
} | |
} | |
}, | |
"final_count": { | |
"stats_bucket": { | |
"buckets_path": "indices>_count" | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"condition": { | |
"script": """ | |
ctx.payload.aggregations.final_count.count > 0 | |
""" | |
}, | |
"actions": { | |
"log": { | |
"transform": { | |
"script": "return ctx.payload.aggregations.indices.buckets.stream().map(p -> ['index':p.key]).collect(Collectors.toList());" | |
}, | |
"logging": { | |
"text": """ | |
indices that had data 2 days ago, but not in last 1 day: | |
{{#ctx.payload._value}} | |
{{index}} | |
{{/ctx.payload._value}} | |
""" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
snippet of output in DevTools: