diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt b/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt index aaa17a56a..d2be2c8c0 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt @@ -490,7 +490,12 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ updatedProperties: MutableMap ): Pair { var targetQueryIndex = monitorMetadata.sourceToQueryIndexMapping[sourceIndex + monitor.id] - if (targetQueryIndex == null) { + if ( + targetQueryIndex == null || ( + targetQueryIndex != monitor.dataSources.queryIndex && + monitor.deleteQueryIndexInEveryRun == true + ) + ) { // queryIndex is alias which will always have only 1 backing index which is writeIndex // This is due to a fact that that _rollover API would maintain only single index under alias // if you don't add is_write_index setting when creating index initially diff --git a/core/src/main/resources/mappings/scheduled-jobs.json b/core/src/main/resources/mappings/scheduled-jobs.json index 2651c862e..311cc6d84 100644 --- a/core/src/main/resources/mappings/scheduled-jobs.json +++ b/core/src/main/resources/mappings/scheduled-jobs.json @@ -293,6 +293,9 @@ } } }, + "delete_query_index_in_every_run": { + "type": "boolean" + }, "ui_metadata": { "type": "object", "enabled": false