@@ -454,6 +454,14 @@ protected void prepareConfigIndexing(boolean indexingDryRun, ActionListener<T> l
454
454
}
455
455
}
456
456
457
+ private String getFlattenedResultIndexAlias (String configId ) {
458
+ return config .getCustomResultIndexOrAlias () + "_flattened_" + configId .toLowerCase (Locale .ROOT );
459
+ }
460
+
461
+ private String getFlattenResultIndexIngestPipelineId (String configId ) {
462
+ return "flatten_result_index_ingest_pipeline" + configId .toLowerCase (Locale .ROOT );
463
+ }
464
+
457
465
private void handlePutRequest (boolean indexingDryRun , ActionListener <T > listener ) {
458
466
handler .confirmJobRunning (clusterService , client , id , listener , () -> {
459
467
handleFlattenResultIndexMappingUpdate (listener );
@@ -465,17 +473,17 @@ private void handlePostRequest(boolean indexingDryRun, ActionListener<T> listene
465
473
createConfig (indexingDryRun , ActionListener .wrap (createConfigResponse -> {
466
474
if (shouldHandleFlattening (indexingDryRun , createConfigResponse )) {
467
475
IndexAnomalyDetectorResponse response = (IndexAnomalyDetectorResponse ) createConfigResponse ;
468
- String detectorId = response .getId ();
469
- String indexName = config . getCustomResultIndexOrAlias () + "_flattened_" + detectorId . toLowerCase ( Locale . ROOT );
470
- String pipelineId = "anomaly_detection_ingest_pipeline_" + detectorId . toLowerCase ( Locale . ROOT );
476
+ String configId = response .getId ();
477
+ String flattenedResultIndexAlias = getFlattenedResultIndexAlias ( configId );
478
+ String pipelineId = getFlattenResultIndexIngestPipelineId ( configId );
471
479
472
480
timeSeriesIndices
473
481
.initFlattenedResultIndex (
474
- indexName ,
475
- ActionListener .wrap (initResponse -> setupIngestPipeline (detectorId , ActionListener .wrap (pipelineResponse -> {
482
+ flattenedResultIndexAlias ,
483
+ ActionListener .wrap (initResponse -> setupIngestPipeline (configId , ActionListener .wrap (pipelineResponse -> {
476
484
updateResultIndexSetting (
477
485
pipelineId ,
478
- indexName ,
486
+ flattenedResultIndexAlias ,
479
487
ActionListener .wrap (updateResponse -> listener .onResponse (createConfigResponse ), listener ::onFailure )
480
488
);
481
489
}, listener ::onFailure )), listener ::onFailure )
@@ -493,12 +501,12 @@ private boolean shouldHandleFlattening(boolean indexingDryRun, Object createConf
493
501
&& createConfigResponse instanceof IndexAnomalyDetectorResponse ;
494
502
}
495
503
496
- protected void setupIngestPipeline (String detectorId , ActionListener <T > listener ) {
497
- String indexName = config . getCustomResultIndexOrAlias () + "_flattened_" + detectorId . toLowerCase ( Locale . ROOT );
498
- String pipelineId = "anomaly_detection_ingest_pipeline_" + detectorId . toLowerCase ( Locale . ROOT );
504
+ protected void setupIngestPipeline (String configId , ActionListener <T > listener ) {
505
+ String flattenedResultIndexAlias = getFlattenedResultIndexAlias ( configId );
506
+ String pipelineId = getFlattenResultIndexIngestPipelineId ( configId );
499
507
500
508
try {
501
- BytesReference pipelineSource = createPipelineDefinition (indexName );
509
+ BytesReference pipelineSource = createPipelineDefinition (flattenedResultIndexAlias );
502
510
503
511
PutPipelineRequest putPipelineRequest = new PutPipelineRequest (pipelineId , pipelineSource , XContentType .JSON );
504
512
@@ -576,10 +584,9 @@ private void handleFlattenResultIndexMappingUpdate(ActionListener<T> listener) {
576
584
return ;
577
585
}
578
586
if (config .getFlattenResultIndexMapping () != null && config .getFlattenResultIndexMapping ()) {
579
- // if field value is true, create the pipeline. No need to get and compare with previous value
580
587
setupIngestPipeline (id , listener );
581
588
} else {
582
- String pipelineId = "anomaly_detection_ingest_pipeline_" + config .getId ();
589
+ String pipelineId = getFlattenResultIndexIngestPipelineId ( config .getId () );
583
590
client .admin ().cluster ().deletePipeline (new DeletePipelineRequest (pipelineId ), new ActionListener <AcknowledgedResponse >() {
584
591
585
592
@ Override
0 commit comments