@@ -113,6 +113,8 @@ public class AnomalyDetectionIndices implements LocalNodeMasterListener {
113
113
private boolean allUpdated ;
114
114
// we only want one update at a time
115
115
private final AtomicBoolean updateRunning ;
116
+ // AD index settings
117
+ private final Settings setting ;
116
118
117
119
class IndexState {
118
120
// keep track of whether the mapping version is up-to-date
@@ -169,6 +171,8 @@ public AnomalyDetectionIndices(
169
171
.addSettingsUpdateConsumer (AD_RESULT_HISTORY_RETENTION_PERIOD , it -> { historyRetentionPeriod = it ; });
170
172
171
173
this .clusterService .getClusterSettings ().addSettingsUpdateConsumer (MAX_PRIMARY_SHARDS , it -> maxPrimaryShards = it );
174
+
175
+ this .setting = Settings .builder ().put ("index.hidden" , true ).build ();
172
176
}
173
177
174
178
/**
@@ -328,7 +332,8 @@ public void initAnomalyDetectorIndexIfAbsent(ActionListener<CreateIndexResponse>
328
332
*/
329
333
public void initAnomalyDetectorIndex (ActionListener <CreateIndexResponse > actionListener ) throws IOException {
330
334
CreateIndexRequest request = new CreateIndexRequest (AnomalyDetector .ANOMALY_DETECTORS_INDEX )
331
- .mapping (AnomalyDetector .TYPE , getAnomalyDetectorMappings (), XContentType .JSON );
335
+ .mapping (AnomalyDetector .TYPE , getAnomalyDetectorMappings (), XContentType .JSON )
336
+ .settings (setting );
332
337
adminClient .indices ().create (request , markMappingUpToDate (ADIndex .CONFIG , actionListener ));
333
338
}
334
339
@@ -357,6 +362,7 @@ private void choosePrimaryShards(CreateIndexRequest request) {
357
362
.put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , Math .min (nodeFilter .getNumberOfEligibleDataNodes (), maxPrimaryShards ))
358
363
// 1 replica for better search performance and fail-over
359
364
.put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 1 )
365
+ .put ("index.hidden" , true )
360
366
);
361
367
}
362
368
@@ -400,7 +406,8 @@ public void initAnomalyDetectorJobIndex(ActionListener<CreateIndexResponse> acti
400
406
public void initDetectionStateIndex (ActionListener <CreateIndexResponse > actionListener ) {
401
407
try {
402
408
CreateIndexRequest request = new CreateIndexRequest (CommonName .DETECTION_STATE_INDEX )
403
- .mapping (AnomalyDetector .TYPE , getDetectionStateMappings (), XContentType .JSON );
409
+ .mapping (AnomalyDetector .TYPE , getDetectionStateMappings (), XContentType .JSON )
410
+ .settings (setting );
404
411
adminClient .indices ().create (request , markMappingUpToDate (ADIndex .STATE , actionListener ));
405
412
} catch (IOException e ) {
406
413
logger .error ("Fail to init AD detection state index" , e );
@@ -469,20 +476,22 @@ void rolloverAndDeleteHistoryIndex() {
469
476
}
470
477
471
478
// We have to pass null for newIndexName in order to get Elastic to increment the index count.
472
- RolloverRequest request = new RolloverRequest (CommonName .ANOMALY_RESULT_INDEX_ALIAS , null );
479
+ RolloverRequest rollOverRequest = new RolloverRequest (CommonName .ANOMALY_RESULT_INDEX_ALIAS , null );
473
480
String adResultMapping = null ;
474
481
try {
475
482
adResultMapping = getAnomalyResultMappings ();
476
483
} catch (IOException e ) {
477
484
logger .error ("Fail to roll over AD result index, as can't get AD result index mapping" );
478
485
return ;
479
486
}
480
- request
481
- .getCreateIndexRequest ()
482
- .index (AD_RESULT_HISTORY_INDEX_PATTERN )
483
- .mapping (CommonName .MAPPING_TYPE , adResultMapping , XContentType .JSON );
484
- request .addMaxIndexDocsCondition (historyMaxDocs );
485
- adminClient .indices ().rolloverIndex (request , ActionListener .wrap (response -> {
487
+ CreateIndexRequest createRequest = rollOverRequest .getCreateIndexRequest ();
488
+
489
+ createRequest .index (AD_RESULT_HISTORY_INDEX_PATTERN ).mapping (CommonName .MAPPING_TYPE , adResultMapping , XContentType .JSON );
490
+
491
+ choosePrimaryShards (createRequest );
492
+
493
+ rollOverRequest .addMaxIndexDocsCondition (historyMaxDocs );
494
+ adminClient .indices ().rolloverIndex (rollOverRequest , ActionListener .wrap (response -> {
486
495
if (!response .isRolledOver ()) {
487
496
logger
488
497
.warn ("{} not rolled over. Conditions were: {}" , CommonName .ANOMALY_RESULT_INDEX_ALIAS , response .getConditionStatus ());
0 commit comments