Skip to content

Commit 7cd997d

Browse files
authored
[ML] Make ml internal indices hidden (#52423) (#52509)
1 parent 4d006f0 commit 7cd997d

File tree

22 files changed

+78
-48
lines changed

22 files changed

+78
-48
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ public Iterator<Setting<?>> settings() {
256256
Setting.Property.Dynamic,
257257
Setting.Property.IndexScope);
258258

259+
public static final String SETTING_INDEX_HIDDEN = "index.hidden";
259260
/**
260261
* Whether the index is considered hidden or not. A hidden index will not be resolved in
261262
* normal wildcard searches unless explicitly allowed
262263
*/
263264
public static final Setting<Boolean> INDEX_HIDDEN_SETTING =
264-
Setting.boolSetting("index.hidden", false, Property.IndexScope, Property.Final);
265+
Setting.boolSetting(SETTING_INDEX_HIDDEN, false, Property.IndexScope, Property.Final);
265266

266267
/**
267268
* an internal index format description, allowing us to find out if this index is upgraded or needs upgrading

server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ public class MetaDataCreateIndexService {
121121
*/
122122
private static final CharacterRunAutomaton DOT_INDICES_EXCLUSIONS = new CharacterRunAutomaton(Regex.simpleMatchToAutomaton(
123123
".watch-history-*",
124-
".ml-anomalies-*",
125-
".ml-notifications-*",
126-
".ml-annotations*",
127124
".data-frame-notifications-*",
128125
".transform-notifications-*"
129126
));

server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,6 @@ public void testIndexNameExclusionsList() {
642642
// this test case should be removed when DOT_INDICES_EXCLUSIONS is empty
643643
List<String> excludedNames = Arrays.asList(
644644
".watch-history-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
645-
".ml-anomalies-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
646-
".ml-notifications-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
647-
".ml-annotations-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
648645
".data-frame-notifications-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
649646
".transform-notifications-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT)
650647
);

test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
2323
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
2424
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
25+
import org.elasticsearch.action.support.IndicesOptions;
2526
import org.elasticsearch.client.Client;
2627
import org.elasticsearch.client.Requests;
2728
import org.elasticsearch.cluster.ClusterName;
@@ -126,13 +127,20 @@ public void setUp() throws Exception {
126127
public void tearDown() throws Exception {
127128
logger.trace("[{}#{}]: cleaning up after test", getTestClass().getSimpleName(), getTestName());
128129
super.tearDown();
129-
assertAcked(client().admin().indices().prepareDelete("*").get());
130+
assertAcked(
131+
client().admin().indices().prepareDelete("*")
132+
.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN)
133+
.get());
130134
MetaData metaData = client().admin().cluster().prepareState().get().getState().getMetaData();
131135
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().keySet(),
132136
metaData.persistentSettings().size(), equalTo(0));
133137
assertThat("test leaves transient cluster metadata behind: " + metaData.transientSettings().keySet(),
134138
metaData.transientSettings().size(), equalTo(0));
135-
GetIndexResponse indices = client().admin().indices().prepareGetIndex().addIndices("*").get();
139+
GetIndexResponse indices =
140+
client().admin().indices().prepareGetIndex()
141+
.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN)
142+
.addIndices("*")
143+
.get();
136144
assertThat("test leaves indices that were not deleted: " + Strings.arrayToCommaDelimitedString(indices.indices()),
137145
indices.indices(), equalTo(Strings.EMPTY_ARRAY));
138146
if (resetNodeAfterTest()) {

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,9 @@ private void wipeCluster() throws Exception {
601601
protected static void wipeAllIndices() throws IOException {
602602
boolean includeHidden = minimumNodeVersion().onOrAfter(Version.V_7_7_0);
603603
try {
604-
final Request deleteReq = new Request("DELETE", "*");
605-
deleteReq.addParameter("expand_wildcards", "open,closed" + (includeHidden ? ",hidden" : ""));
606-
final Response response = adminClient().performRequest(deleteReq);
604+
final Request deleteRequest = new Request("DELETE", "*");
605+
deleteRequest.addParameter("expand_wildcards", "open,closed" + (includeHidden ? ",hidden" : ""));
606+
final Response response = adminClient().performRequest(deleteRequest);
607607
try (InputStream is = response.getEntity().getContent()) {
608608
assertTrue((boolean) XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true).get("acknowledged"));
609609
}
@@ -726,6 +726,13 @@ private void wipeRollupJobs() throws IOException {
726726
}
727727
}
728728

729+
protected void refreshAllIndices() throws IOException {
730+
boolean includeHidden = minimumNodeVersion().onOrAfter(Version.V_7_7_0);
731+
Request refreshRequest = new Request("POST", "/_refresh");
732+
refreshRequest.addParameter("expand_wildcards", "open,closed" + (includeHidden ? ",hidden" : ""));
733+
client().performRequest(refreshRequest);
734+
}
735+
729736
private void waitForPendingRollupTasks() throws Exception {
730737
waitForPendingTasks(adminClient(), taskName -> taskName.startsWith("xpack/rollup/job") == false);
731738
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/annotations/AnnotationIndex.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ public static void createAnnotationsIndexIfNecessary(Settings settings, Client c
6161
// Create the annotations index if it doesn't exist already.
6262
if (mlLookup.containsKey(INDEX_NAME) == false) {
6363

64-
CreateIndexRequest createIndexRequest = new CreateIndexRequest(INDEX_NAME);
65-
createIndexRequest.mapping(SINGLE_MAPPING_NAME, annotationsMapping(), XContentType.JSON);
66-
createIndexRequest.settings(Settings.builder()
67-
.put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "0-1")
68-
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, "1"));
64+
CreateIndexRequest createIndexRequest =
65+
new CreateIndexRequest(INDEX_NAME)
66+
.mapping(SINGLE_MAPPING_NAME, annotationsMapping(), XContentType.JSON)
67+
.settings(Settings.builder()
68+
.put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "0-1")
69+
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, "1")
70+
.put(IndexMetaData.SETTING_INDEX_HIDDEN, true));
6971

7072
executeAsyncWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN, createIndexRequest,
7173
ActionListener.<CreateIndexResponse>wrap(

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/AnomalyDetectorsIndexFields.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ public final class AnomalyDetectorsIndexFields {
99

1010
public static final String CONFIG_INDEX = ".ml-config";
1111

12-
public static final String RESULTS_INDEX_PREFIX = ".ml-anomalies-";
13-
1412
public static final String STATE_INDEX_PREFIX = ".ml-state";
15-
public static final String STATE_INDEX_PATTERN = STATE_INDEX_PREFIX + "*";
1613

14+
public static final String RESULTS_INDEX_PREFIX = ".ml-anomalies-";
1715
public static final String RESULTS_INDEX_DEFAULT = "shared";
1816

1917
private AnomalyDetectorsIndexFields() {}

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/anomalydetection/results_index_template.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"auto_expand_replicas" : "0-1",
1313
"query" : {
1414
"default_field" : "all_field_values"
15-
}
15+
},
16+
"hidden": true
1617
}
1718
},
1819
"mappings": ${xpack.ml.anomalydetection.results.mappings}

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/anomalydetection/state_index_template.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
],
77
"settings" : {
88
"index" : {
9-
"auto_expand_replicas" : "0-1"
9+
"auto_expand_replicas" : "0-1",
10+
"hidden": true
1011
}
1112
},
1213
"mappings" : {

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/notifications_index_template.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"settings" : {
88
"index" : {
99
"number_of_shards" : "1",
10-
"auto_expand_replicas" : "0-1"
10+
"auto_expand_replicas" : "0-1",
11+
"hidden": true
1112
}
1213
},
1314
"mappings" : {

0 commit comments

Comments
 (0)