Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
9ff0b94
[ML] 8Manage rollover of AD results indices
edsavage Oct 6, 2025
78d0d8e
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 6, 2025
0ec99b6
Spotless Apply
edsavage Oct 6, 2025
8405ff3
Spotless Apply
edsavage Oct 6, 2025
d10d09d
Bit of a tidy up
edsavage Oct 6, 2025
dfb1939
Slight refactor
edsavage Oct 6, 2025
ffc2842
Another tidy
edsavage Oct 6, 2025
9863169
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 6, 2025
8f17540
Remove unused accessor
edsavage Oct 7, 2025
d60a811
Update docs/changelog/136065.yaml
edsavage Oct 7, 2025
2729a86
Merge branch 'main' into manage_ad_results_indices
edsavage Oct 7, 2025
c5f58e1
[CI] Auto commit changes from spotless
Oct 7, 2025
7b6caf0
Address some test failures
edsavage Oct 8, 2025
52ab642
Merge remote-tracking branch 'origin/manage_ad_results_indices' into …
edsavage Oct 8, 2025
66d7268
Typos
edsavage Oct 8, 2025
f9296fd
[CI] Auto commit changes from spotless
Oct 8, 2025
07ddbaa
Make the max results index size for rollover user configurable.
edsavage Oct 8, 2025
e7eb106
Merge remote-tracking branch 'origin/manage_ad_results_indices' into …
edsavage Oct 8, 2025
cb85a49
Fix bad merge
edsavage Oct 8, 2025
123c8cb
[CI] Auto commit changes from spotless
Oct 8, 2025
1a5d0da
Merge branch 'main' into manage_ad_results_indices
edsavage Oct 8, 2025
c54a354
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 8, 2025
80b1b71
Test fixes
edsavage Oct 8, 2025
84ad33d
Merge remote-tracking branch 'origin/manage_ad_results_indices' into …
edsavage Oct 8, 2025
2a66d40
Remove assertion for condition that is no longer entirely true
edsavage Oct 8, 2025
83e7e2b
A few more test fixes
edsavage Oct 9, 2025
e9c0c2c
Fixed typo in docs
edsavage Oct 9, 2025
0b6b79a
Tweaks to yamlRestCompatTests
edsavage Oct 10, 2025
97106a1
A few more test fixes
edsavage Oct 10, 2025
468f712
Another test fix through rewrite rules
edsavage Oct 13, 2025
96cecaf
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 13, 2025
63f97c5
Another REST compatibility test transformation
edsavage Oct 13, 2025
8050133
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 13, 2025
c320ccc
First draft of integration tests
edsavage Oct 16, 2025
8e22944
2nd draft of integration test
edsavage Oct 16, 2025
644c57f
spotless fixes
edsavage Oct 16, 2025
0532c8b
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 16, 2025
5465b24
[CI] Auto commit changes from spotless
Oct 16, 2025
42e63c9
spotless fixes
edsavage Oct 16, 2025
5e7a9da
Merge remote-tracking branch 'origin/manage_ad_results_indices' into …
edsavage Oct 16, 2025
16cb2d1
Fix broken test case
edsavage Oct 17, 2025
7abf680
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 17, 2025
b5513a2
Tidy up
edsavage Oct 17, 2025
29faf9e
Add more test scenarios
edsavage Oct 17, 2025
77ab9df
[CI] Auto commit changes from spotless
Oct 17, 2025
8bf9e6f
Merge branch 'main' into manage_ad_results_indices
edsavage Oct 19, 2025
f9f6881
Merge branch 'main' into manage_ad_results_indices
edsavage Oct 19, 2025
cd9b467
Refactor integration tests
edsavage Oct 20, 2025
fe2c12d
Merge remote-tracking branch 'origin/manage_ad_results_indices' into …
edsavage Oct 20, 2025
326eedd
Attend to code review comments
edsavage Oct 23, 2025
21ea400
Remove unneeded variable
edsavage Oct 23, 2025
f90e4b8
[CI] Auto commit changes from spotless
Oct 23, 2025
5d06353
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 23, 2025
988eeeb
Merge remote-tracking branch 'origin/manage_ad_results_indices' into …
edsavage Oct 23, 2025
000e1b3
Bugfix and typo
edsavage Oct 23, 2025
cc157c8
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 23, 2025
58540ae
More tests and fixes
edsavage Oct 24, 2025
74d92ae
* Clarified documentation regarding results_index_rollover_max_size
edsavage Oct 29, 2025
0c2fbe9
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Oct 30, 2025
fe85b26
[ML] Add daily task to manage .ml-state indices
edsavage Nov 5, 2025
7602106
Merge branch 'main' of github.com:elasticsearch/elasticsearch into ma…
edsavage Nov 5, 2025
e95a85a
Update docs/changelog/137603.yaml
edsavage Nov 5, 2025
f6ac275
[ML] Add daily task to manage .ml-state indices
edsavage Oct 6, 2025
8ba07e0
Merge remote-tracking branch 'origin/manage_ad_state_indices' into ma…
edsavage Nov 5, 2025
98035bd
Merge branch 'main' into manage_ad_state_indices
edsavage Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/137603.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 137603
summary: Add daily task to manage .ml-state indices
area: Machine Learning
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public final class MlIndexAndAlias {
private static final Predicate<String> IS_ANOMALIES_SHARED_INDEX = Pattern.compile(
AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + AnomalyDetectorsIndexFields.RESULTS_INDEX_DEFAULT + "-\\d{6}"
).asMatchPredicate();
private static final Predicate<String> IS_ANOMALIES_STATE_INDEX = Pattern.compile(
AnomalyDetectorsIndexFields.STATE_INDEX_PREFIX + "-\\d{6}"
).asMatchPredicate();
public static final String ROLLOVER_ALIAS_SUFFIX = ".rollover_alias";

static final Comparator<String> INDEX_NAME_COMPARATOR = (index1, index2) -> {
Expand Down Expand Up @@ -495,6 +498,16 @@ public static boolean isAnomaliesSharedIndex(String indexName) {
return IS_ANOMALIES_SHARED_INDEX.test(indexName);
}

/**
* Checks if an index name matches the pattern for the ML anomalies state indices (e.g., ".ml-state-000001").
*
* @param indexName The name of the index to check.
* @return {@code true} if the index is an anomalies state index, {@code false} otherwise.
*/
public static boolean isAnomaliesStateIndex(String indexName) {
return IS_ANOMALIES_STATE_INDEX.test(indexName);
}

/**
* Returns the latest index. Latest is the index with the highest
* 6 digit suffix.
Expand Down Expand Up @@ -630,6 +643,47 @@ public static void updateAliases(IndicesAliasesRequestBuilder request, ActionLis
request.execute(listener.delegateFailure((l, response) -> l.onResponse(Boolean.TRUE)));
}

/**
* Adds alias actions to a request builder to move the ML state write alias from an old index to a new one after a rollover.
* This method is robust and will move the correct alias regardless of the current alias state on the old index.
*
* @param aliasRequestBuilder The request builder to add actions to.
* @param oldIndex The index from which the alias is being moved.
* @param newIndex The new index to which the alias will be moved.
* @param clusterState The current cluster state, used to inspect existing aliases on the old index.
* @param allStateIndices A list of all current .ml-state indices
* @return The modified {@link IndicesAliasesRequestBuilder}.
*/
public static IndicesAliasesRequestBuilder addStateIndexRolloverAliasActions(
IndicesAliasesRequestBuilder aliasRequestBuilder,
String oldIndex,
String newIndex,
ClusterState clusterState,
String[] allStateIndices
) {
var meta = clusterState.metadata().getProject().index(oldIndex);
if (meta == null) {
// This should not happen in practice as we are iterating over existing indices, but we defend against it.
return aliasRequestBuilder;
}

// Remove the write alias from ALL state indices to handle any inconsistencies where it might exist on more than one.
aliasRequestBuilder.addAliasAction(
IndicesAliasesRequest.AliasActions.remove().indices(allStateIndices).alias(AnomalyDetectorsIndex.jobStateIndexWriteAlias())
);

aliasRequestBuilder.addAliasAction(
IndicesAliasesRequest.AliasActions.add()
.index(newIndex)
.alias(AnomalyDetectorsIndex.jobStateIndexWriteAlias())
.isHidden(true)
.writeIndex(true)
);

return aliasRequestBuilder;

}

/**
* Adds alias actions to a request builder to move ML job aliases from an old index to a new one after a rollover.
* This includes moving the write alias and re-creating the filtered read aliases on the new index.
Expand All @@ -640,7 +694,7 @@ public static void updateAliases(IndicesAliasesRequestBuilder request, ActionLis
* @param clusterState The current cluster state, used to inspect existing aliases on the old index.
* @return The modified {@link IndicesAliasesRequestBuilder}.
*/
public static IndicesAliasesRequestBuilder addIndexAliasesRequests(
public static IndicesAliasesRequestBuilder addResultsIndexRolloverAliasActions(
IndicesAliasesRequestBuilder aliasRequestBuilder,
String oldIndex,
String newIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public void testBuildIndexAliasesRequest() {
);

var newIndex = anomaliesIndex + "-000001";
var request = MlIndexAndAlias.addIndexAliasesRequests(aliasRequestBuilder, anomaliesIndex, newIndex, csBuilder.build());
var request = MlIndexAndAlias.addResultsIndexRolloverAliasActions(aliasRequestBuilder, anomaliesIndex, newIndex, csBuilder.build());
var actions = request.request().getAliasActions();
assertThat(actions, hasSize(6));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"index" : {
"auto_expand_replicas" : "0-1",
"hidden": true
},
"index.lifecycle.name": "${xpack.ml.index.lifecycle.name}",
"index.lifecycle.rollover_alias": "${xpack.ml.index.lifecycle.rollover_alias}"
}
},
"mappings" : {
"_meta": {
Expand Down
Loading