diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/AnomalyDetectorsIndex.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/AnomalyDetectorsIndex.java index 6ab6e56e5ba..a832bde3ace 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/AnomalyDetectorsIndex.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/AnomalyDetectorsIndex.java @@ -9,7 +9,7 @@ package org.elasticsearch.xpack.prelert.job.persistence; * Methods for handling index naming related functions */ public final class AnomalyDetectorsIndex { - private static final String RESULTS_INDEX_PREFIX = "prelertresults-"; + private static final String RESULTS_INDEX_PREFIX = ".ml-anomalies-"; private static final String STATE_INDEX_NAME = ".ml-state"; private AnomalyDetectorsIndex() { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/integration/PrelertJobIT.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/integration/PrelertJobIT.java index c4a97c7ff42..05256c18b2d 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/integration/PrelertJobIT.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/integration/PrelertJobIT.java @@ -10,6 +10,7 @@ import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.prelert.PrelertPlugin; +import org.elasticsearch.xpack.prelert.job.persistence.AnomalyDetectorsIndex; import org.junit.After; import java.io.BufferedReader; @@ -191,7 +192,8 @@ public class PrelertJobIT extends ESRestTestCase { response = client().performRequest("get", "_aliases"); assertEquals(200, response.getStatusLine().getStatusCode()); String responseAsString = responseEntityToString(response); - assertThat(responseAsString, containsString("\"prelertresults-" + indexName + "\":{\"aliases\":{\"prelertresults-" + jobId + "\"")); + assertThat(responseAsString, containsString("\"" + AnomalyDetectorsIndex.jobResultsIndexName(indexName) + + "\":{\"aliases\":{\"" + AnomalyDetectorsIndex.jobResultsIndexName(jobId) + "\"")); response = client().performRequest("get", "_cat/indices"); assertEquals(200, response.getStatusLine().getStatusCode()); @@ -205,7 +207,7 @@ public class PrelertJobIT extends ESRestTestCase { responseAsString = responseEntityToString(response); assertThat(responseAsString, containsString("\"count\":2")); - response = client().performRequest("get", "prelertresults-" + indexName + "/result/_search"); + response = client().performRequest("get", AnomalyDetectorsIndex.jobResultsIndexName(indexName) + "/result/_search"); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); responseAsString = responseEntityToString(response); assertThat(responseAsString, containsString("\"total\":2")); @@ -222,7 +224,7 @@ public class PrelertJobIT extends ESRestTestCase { response = client().performRequest("get", "_aliases"); assertEquals(200, response.getStatusLine().getStatusCode()); responseAsString = responseEntityToString(response); - assertThat(responseAsString, not(containsString("prelertresults-" + jobId ))); + assertThat(responseAsString, not(containsString(AnomalyDetectorsIndex.jobResultsIndexName(jobId)))); response = client().performRequest("get", "_cat/indices"); assertEquals(200, response.getStatusLine().getStatusCode()); @@ -232,7 +234,8 @@ public class PrelertJobIT extends ESRestTestCase { private Response addBucketResult(String jobId, String timestamp, long bucketSpan) throws Exception { try { - client().performRequest("put", "prelertresults-" + jobId, Collections.emptyMap(), new StringEntity(RESULT_MAPPING)); + client().performRequest("put", AnomalyDetectorsIndex.jobResultsIndexName(jobId), + Collections.emptyMap(), new StringEntity(RESULT_MAPPING)); } catch (ResponseException e) { // it is ok: the index already exists assertThat(e.getMessage(), containsString("index_already_exists_exception")); @@ -244,13 +247,14 @@ public class PrelertJobIT extends ESRestTestCase { jobId, timestamp, bucketSpan); String id = String.format(Locale.ROOT, "%s_%s_%s", jobId, timestamp, bucketSpan); - return client().performRequest("put", "prelertresults-" + jobId + "/result/" + id, + return client().performRequest("put", AnomalyDetectorsIndex.jobResultsIndexName(jobId) + "/result/" + id, Collections.singletonMap("refresh", "true"), new StringEntity(bucketResult)); } private Response addRecordResult(String jobId, String timestamp, long bucketSpan, int sequenceNum) throws Exception { try { - client().performRequest("put", "prelertresults-" + jobId, Collections.emptyMap(), new StringEntity(RESULT_MAPPING)); + client().performRequest("put", AnomalyDetectorsIndex.jobResultsIndexName(jobId), Collections.emptyMap(), + new StringEntity(RESULT_MAPPING)); } catch (ResponseException e) { // it is ok: the index already exists assertThat(e.getMessage(), containsString("index_already_exists_exception")); @@ -261,7 +265,7 @@ public class PrelertJobIT extends ESRestTestCase { String.format(Locale.ROOT, "{\"job_id\":\"%s\", \"timestamp\": \"%s\", \"bucket_span\":%d, \"sequence_num\": %d, \"result_type\":\"record\"}", jobId, timestamp, bucketSpan, sequenceNum); - return client().performRequest("put", "prelertresults-" + jobId + "/result/" + timestamp, + return client().performRequest("put", AnomalyDetectorsIndex.jobResultsIndexName(jobId) + "/result/" + timestamp, Collections.singletonMap("refresh", "true"), new StringEntity(recordResult)); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedDocumentsIteratorTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedDocumentsIteratorTests.java index 602f2f0b0ed..b1edf137c58 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedDocumentsIteratorTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/ElasticsearchBatchedDocumentsIteratorTests.java @@ -30,7 +30,7 @@ import org.junit.Before; import org.mockito.Mockito; public class ElasticsearchBatchedDocumentsIteratorTests extends ESTestCase { - private static final String INDEX_NAME = "prelertresults-foo"; + private static final String INDEX_NAME = ".ml-anomalies-foo"; private static final String SCROLL_ID = "someScrollId"; private Client client; diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/JobResultsPersisterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/JobResultsPersisterTests.java index 1a53bdf9cd7..85e92e8df82 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/JobResultsPersisterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/JobResultsPersisterTests.java @@ -37,8 +37,8 @@ public class JobResultsPersisterTests extends ESTestCase { BulkResponse response = mock(BulkResponse.class); String responseId = "abcXZY54321"; MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME) - .prepareIndex("prelertresults-" + JOB_ID, Result.TYPE.getPreferredName(), responseId, captor) - .prepareIndex("prelertresults-" + JOB_ID, Result.TYPE.getPreferredName(), "", captor) + .prepareIndex(AnomalyDetectorsIndex.jobResultsIndexName(JOB_ID), Result.TYPE.getPreferredName(), responseId, captor) + .prepareIndex(AnomalyDetectorsIndex.jobResultsIndexName(JOB_ID), Result.TYPE.getPreferredName(), "", captor) .prepareBulk(response); Client client = clientBuilder.build(); @@ -91,7 +91,7 @@ public class JobResultsPersisterTests extends ESTestCase { ArgumentCaptor captor = ArgumentCaptor.forClass(XContentBuilder.class); BulkResponse response = mock(BulkResponse.class); MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME) - .prepareIndex("prelertresults-" + JOB_ID, Result.TYPE.getPreferredName(), "", captor) + .prepareIndex(AnomalyDetectorsIndex.jobResultsIndexName(JOB_ID), Result.TYPE.getPreferredName(), "", captor) .prepareBulk(response); Client client = clientBuilder.build(); @@ -152,7 +152,7 @@ public class JobResultsPersisterTests extends ESTestCase { ArgumentCaptor captor = ArgumentCaptor.forClass(XContentBuilder.class); BulkResponse response = mock(BulkResponse.class); MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME) - .prepareIndex("prelertresults-" + JOB_ID, Result.TYPE.getPreferredName(), "", captor) + .prepareIndex(AnomalyDetectorsIndex.jobResultsIndexName(JOB_ID), Result.TYPE.getPreferredName(), "", captor) .prepareBulk(response); Client client = clientBuilder.build(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/UsagePersisterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/UsagePersisterTests.java index 030cefaf093..50855c25c6a 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/UsagePersisterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/persistence/UsagePersisterTests.java @@ -54,7 +54,7 @@ public class UsagePersisterTests extends ESTestCase { verify(updateRequestBuilder, times(2)).setRetryOnConflict(ElasticsearchScripts.UPDATE_JOB_RETRY_COUNT); verify(updateRequestBuilder, times(2)).get(); - assertEquals(Arrays.asList("prelert-usage", "prelertresults-job1"), indexCaptor.getAllValues()); + assertEquals(Arrays.asList("prelert-usage", AnomalyDetectorsIndex.jobResultsIndexName("job1")), indexCaptor.getAllValues()); assertEquals(2, idCaptor.getAllValues().size()); String id = idCaptor.getValue(); assertEquals(id, idCaptor.getAllValues().get(0)); @@ -62,7 +62,7 @@ public class UsagePersisterTests extends ESTestCase { String timestamp = id.substring("usage-".length()); assertEquals("prelert-usage", indexCaptor.getAllValues().get(0)); - assertEquals("prelertresults-job1", indexCaptor.getAllValues().get(1)); + assertEquals(AnomalyDetectorsIndex.jobResultsIndexName("job1"), indexCaptor.getAllValues().get(1)); Script script = updateScriptCaptor.getValue(); assertEquals("ctx._source.inputBytes += params.bytes;ctx._source.inputFieldCount += params.fieldCount;ctx._source.inputRecordCount" diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/delete_model_snapshot.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/delete_model_snapshot.yaml index c38b47128d8..418a2b4ea8b 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/delete_model_snapshot.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/delete_model_snapshot.yaml @@ -26,7 +26,7 @@ setup: - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: model_snapshot id: "foo1" body: > @@ -63,7 +63,7 @@ setup: - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: model_snapshot id: "foo2" body: > @@ -83,7 +83,7 @@ setup: - do: indices.refresh: - index: prelertresults-foo + index: .ml-anomalies-foo --- "Test delete snapshot missing snapshotId": @@ -121,7 +121,7 @@ setup: - do: indices.refresh: - index: prelertresults-foo + index: .ml-anomalies-foo - do: indices.refresh: diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/get_model_snapshots.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/get_model_snapshots.yaml index 67ef7d11d96..033fb005228 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/get_model_snapshots.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/get_model_snapshots.yaml @@ -1,7 +1,7 @@ setup: - do: indices.create: - index: prelertresults-foo + index: .ml-anomalies-foo body: mappings: model_snapshot: @@ -13,21 +13,21 @@ setup: - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: model_snapshot id: "1" body: { "job_id": "foo", "timestamp": "2016-06-02T00:00:00Z", "restore_priority": "1" } - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: model_snapshot id: "2" body: { "job_id": "foo", "timestamp": "2016-06-01T00:00:00Z", "restore_priority": "2" } - do: indices.refresh: - index: prelertresults-foo + index: .ml-anomalies-foo --- "Test get model snapshots API with no params": diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_crud.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_crud.yaml index 272e67f814b..8c9d196bd11 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_crud.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_crud.yaml @@ -20,7 +20,7 @@ - do: indices.get: - index: "prelertresults-farequote" + index: ".ml-anomalies-farequote" - do: indices.get: @@ -39,7 +39,7 @@ - do: indices.exists: - index: "prelertresults-farequote" + index: ".ml-anomalies-farequote" - is_false: '' --- diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_buckets.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_buckets.yaml index bf04f6bf6a5..aaad63cb413 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_buckets.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_buckets.yaml @@ -1,7 +1,7 @@ setup: - do: indices.create: - index: prelertresults-farequote + index: .ml-anomalies-farequote body: mappings: results: @@ -15,21 +15,21 @@ setup: - do: index: - index: prelertresults-farequote + index: .ml-anomalies-farequote type: result id: "farequote_1464739200000_1" body: { "job_id": "farequote", "result_type": "bucket", "timestamp": "2016-06-01T00:00:00Z", "bucket_span":1 } - do: index: - index: prelertresults-farequote + index: .ml-anomalies-farequote type: result id: "farequote_1464739200000_2" body: { "job_id": "farequote", "result_type": "bucket", "timestamp": "2016-08-01T00:00:00Z", "bucket_span":1 } - do: indices.refresh: - index: prelertresults-farequote + index: .ml-anomalies-farequote --- "Test result buckets api with time range": diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_categories.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_categories.yaml index 09ec5820eca..3542422c21b 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_categories.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_categories.yaml @@ -1,26 +1,26 @@ setup: - do: index: - index: prelertresults-farequote + index: .ml-anomalies-farequote type: category_definition id: 1 body: { "job_id": "farequote", "category_id": 1 } - do: index: - index: prelertresults-farequote + index: .ml-anomalies-farequote type: category_definition id: 2 body: { "job_id": "farequote", "category_id": 2 } - do: index: - index: prelertresults-unrelated + index: .ml-anomalies-unrelated type: category_definition id: 3 body: { "job_id": "unrelated", "category_id": 1 } - do: indices.refresh: - index: prelertresults-farequote + index: .ml-anomalies-farequote --- "Test result categories api": diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_influencers.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_influencers.yaml index 275ab37b6c0..619f7a7eff8 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_influencers.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_influencers.yaml @@ -1,7 +1,7 @@ setup: - do: indices.create: - index: prelertresults-farequote + index: .ml-anomalies-farequote body: mappings: result: @@ -16,7 +16,7 @@ setup: type: keyword - do: index: - index: prelertresults-farequote + index: .ml-anomalies-farequote type: result id: farequote_1464739200000_1_1 body: @@ -33,7 +33,7 @@ setup: - do: index: - index: prelertresults-farequote + index: .ml-anomalies-farequote type: result id: farequote_1464825600000_1_2 body: @@ -49,7 +49,7 @@ setup: } - do: indices.refresh: - index: prelertresults-farequote + index: .ml-anomalies-farequote --- "Test result influencers api": diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_records.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_records.yaml index 095f3481282..bc1f700b8cf 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_records.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_result_records.yaml @@ -1,7 +1,7 @@ setup: - do: indices.create: - index: prelertresults-farequote + index: .ml-anomalies-farequote body: mappings: record: @@ -29,7 +29,7 @@ setup: - do: index: - index: prelertresults-farequote + index: .ml-anomalies-farequote type: result id: farequote_1464739200000_1_1 body: @@ -44,7 +44,7 @@ setup: - do: index: - index: prelertresults-farequote + index: .ml-anomalies-farequote type: result id: farequote_1464825600000_1_2 body: @@ -59,7 +59,7 @@ setup: - do: indices.refresh: - index: prelertresults-farequote + index: .ml-anomalies-farequote --- "Test result records api": diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_stats.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_stats.yaml index 73c44c177ab..2b51c2f7eff 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_stats.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_stats.yaml @@ -52,7 +52,7 @@ setup: - do: index: - index: prelertresults-job-stats-test + index: .ml-anomalies-job-stats-test type: result id: model_size_stats body: { diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/post_data.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/post_data.yaml index c5d8e566626..465c8f3ab05 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/post_data.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/post_data.yaml @@ -56,7 +56,7 @@ setup: - do: get: - index: prelertresults-farequote + index: .ml-anomalies-farequote type: data_counts id: farequote-data-counts diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/put_model_snapshot_description.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/put_model_snapshot_description.yaml index 9a40f4c00c8..170456b6e71 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/put_model_snapshot_description.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/put_model_snapshot_description.yaml @@ -1,7 +1,7 @@ setup: - do: indices.create: - index: prelertresults-foo + index: .ml-anomalies-foo body: mappings: model_snapshot: @@ -13,7 +13,7 @@ setup: - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: model_snapshot id: "1" body: > @@ -26,7 +26,7 @@ setup: - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: model_snapshot id: "2" body: > @@ -40,7 +40,7 @@ setup: - do: indices.refresh: - index: prelertresults-foo + index: .ml-anomalies-foo --- "Test without description": @@ -78,7 +78,7 @@ setup: - do: indices.refresh: - index: prelertresults-foo + index: .ml-anomalies-foo - do: xpack.prelert.get_model_snapshots: diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/revert_model_snapshot.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/revert_model_snapshot.yaml index f2bae60b11b..c858d012280 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/revert_model_snapshot.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/revert_model_snapshot.yaml @@ -26,7 +26,7 @@ setup: - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: model_snapshot id: "1" body: > @@ -42,7 +42,7 @@ setup: - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: model_snapshot id: "2" body: > @@ -58,42 +58,42 @@ setup: - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: result id: "foo_1464825600000_1" body: { "job_id": "foo", "result_type": "bucket", "timestamp": "2016-06-02T00:00:00Z", "bucket_span":1 } - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: result id: "foo_1464782400000_1" body: { "job_id": "foo", "result_type": "bucket", "timestamp": "2016-06-01T12:00:00Z", "bucket_span":1 } - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: result id: "foo_1462060800000_1" body: { "job_id": "foo", "result_type": "bucket", "timestamp": "2016-05-01T00:00:00Z", "bucket_span":1 } - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: result id: "foo_1464825600000_1_1" body: { "job_id": "foo", "result_type": "record", "timestamp": "2016-06-02T00:00:00Z", "bucket_span":1, "sequence_num":1 } - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: result id: "foo_1462060800000_1_2" body: { "job_id": "foo", "result_type": "record", "timestamp": "2016-05-01T00:00:00Z", "bucket_span":1, "sequence_num":2 } - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: result id: "foo_1464825600000_1_3" body: { @@ -109,7 +109,7 @@ setup: - do: index: - index: prelertresults-foo + index: .ml-anomalies-foo type: result id: "foo_1462060800000_1_4" body: @@ -126,7 +126,7 @@ setup: - do: indices.refresh: - index: prelertresults-foo + index: .ml-anomalies-foo - do: indices.refresh: @@ -258,7 +258,7 @@ setup: - do: indices.refresh: - index: prelertresults-foo + index: .ml-anomalies-foo - do: xpack.prelert.get_buckets: