Skip to content

Commit c73cf80

Browse files
droberts195davidkyle
authored andcommitted
[ML] Switch to typeless APIs in ML native multi-node tests (elastic#39574)
Following elastic#39256 some of these tests were generating errors when indexing documents. For consistency it's best that all of them use typeless APIs.
1 parent 2726736 commit c73cf80

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/CategorizationIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.List;
2727
import java.util.Locale;
2828

29+
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
2930
import static org.hamcrest.Matchers.equalTo;
3031
import static org.hamcrest.Matchers.is;
3132

@@ -35,38 +36,37 @@
3536
public class CategorizationIT extends MlNativeAutodetectIntegTestCase {
3637

3738
private static final String DATA_INDEX = "log-data";
38-
private static final String DATA_TYPE = "log";
3939

4040
private long nowMillis;
4141

4242
@Before
4343
public void setUpData() {
4444
client().admin().indices().prepareCreate(DATA_INDEX)
45-
.addMapping(DATA_TYPE, "time", "type=date,format=epoch_millis",
45+
.addMapping(SINGLE_MAPPING_NAME, "time", "type=date,format=epoch_millis",
4646
"msg", "type=text")
4747
.get();
4848

4949
nowMillis = System.currentTimeMillis();
5050

5151
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
52-
IndexRequest indexRequest = new IndexRequest(DATA_INDEX, DATA_TYPE);
52+
IndexRequest indexRequest = new IndexRequest(DATA_INDEX);
5353
indexRequest.source("time", nowMillis - TimeValue.timeValueHours(2).millis(),
5454
"msg", "Node 1 started");
5555
bulkRequestBuilder.add(indexRequest);
56-
indexRequest = new IndexRequest(DATA_INDEX, DATA_TYPE);
56+
indexRequest = new IndexRequest(DATA_INDEX);
5757
indexRequest.source("time", nowMillis - TimeValue.timeValueHours(2).millis() + 1,
5858
"msg", "Failed to shutdown [error org.aaaa.bbbb.Cccc line 54 caused " +
5959
"by foo exception]");
6060
bulkRequestBuilder.add(indexRequest);
61-
indexRequest = new IndexRequest(DATA_INDEX, DATA_TYPE);
61+
indexRequest = new IndexRequest(DATA_INDEX);
6262
indexRequest.source("time", nowMillis - TimeValue.timeValueHours(1).millis(),
6363
"msg", "Node 2 started");
6464
bulkRequestBuilder.add(indexRequest);
65-
indexRequest = new IndexRequest(DATA_INDEX, DATA_TYPE);
65+
indexRequest = new IndexRequest(DATA_INDEX);
6666
indexRequest.source("time", nowMillis - TimeValue.timeValueHours(1).millis() + 1,
6767
"msg", "Failed to shutdown [error but this time completely different]");
6868
bulkRequestBuilder.add(indexRequest);
69-
indexRequest = new IndexRequest(DATA_INDEX, DATA_TYPE);
69+
indexRequest = new IndexRequest(DATA_INDEX);
7070
indexRequest.source("time", nowMillis, "msg", "Node 3 started");
7171
bulkRequestBuilder.add(indexRequest);
7272

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public void testLookbackOnlyWithNestedFields() throws Exception {
308308
client().performRequest(createJobRequest);
309309

310310
String datafeedId = jobId + "-datafeed";
311-
new DatafeedBuilder(datafeedId, jobId, "nested-data", "response").build();
311+
new DatafeedBuilder(datafeedId, jobId, "nested-data").build();
312312
openJob(client(), jobId);
313313

314314
startDatafeedAndWaitUntilStopped(datafeedId);
@@ -351,7 +351,7 @@ public void testInsufficientSearchPrivilegesOnPut() throws Exception {
351351
// create a datafeed they DON'T have permission to search the index the datafeed is
352352
// configured to read
353353
ResponseException e = expectThrows(ResponseException.class, () ->
354-
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs", "response")
354+
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs")
355355
.setAuthHeader(BASIC_AUTH_VALUE_ML_ADMIN)
356356
.build());
357357

@@ -419,7 +419,7 @@ public void testInsufficientSearchPrivilegesOnPutWithRollup() throws Exception {
419419

420420

421421
ResponseException e = expectThrows(ResponseException.class, () ->
422-
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs-rollup", "doc")
422+
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs-rollup")
423423
.setAggregations(aggregations)
424424
.setAuthHeader(BASIC_AUTH_VALUE_ML_ADMIN_WITH_SOME_DATA_ACCESS) //want to search, but no admin access
425425
.build());
@@ -449,7 +449,7 @@ public void testInsufficientSearchPrivilegesOnPreview() throws Exception {
449449
client().performRequest(createJobRequest);
450450

451451
String datafeedId = "datafeed-" + jobId;
452-
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs", "response").build();
452+
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs").build();
453453

454454
// This should be disallowed, because ml_admin is trying to preview a datafeed created by
455455
// by another user (x_pack_rest_user in this case) that will reveal the content of an index they
@@ -490,7 +490,7 @@ public void testLookbackOnlyGivenAggregationsWithHistogram() throws Exception {
490490
+ "\"time stamp\":{\"max\":{\"field\":\"time stamp\"}},"
491491
+ "\"airline\":{\"terms\":{\"field\":\"airline\",\"size\":10},"
492492
+ " \"aggregations\":{\"responsetime\":{\"avg\":{\"field\":\"responsetime\"}}}}}}}";
493-
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs", "response").setAggregations(aggregations).build();
493+
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs").setAggregations(aggregations).build();
494494
openJob(client(), jobId);
495495

496496
startDatafeedAndWaitUntilStopped(datafeedId);
@@ -529,7 +529,7 @@ public void testLookbackOnlyGivenAggregationsWithDateHistogram() throws Exceptio
529529
+ "\"time stamp\":{\"max\":{\"field\":\"time stamp\"}},"
530530
+ "\"airline\":{\"terms\":{\"field\":\"airline\",\"size\":10},"
531531
+ " \"aggregations\":{\"responsetime\":{\"avg\":{\"field\":\"responsetime\"}}}}}}}";
532-
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs", "response").setAggregations(aggregations).build();
532+
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs").setAggregations(aggregations).build();
533533
openJob(client(), jobId);
534534

535535
startDatafeedAndWaitUntilStopped(datafeedId);
@@ -568,7 +568,7 @@ public void testLookbackUsingDerivativeAggWithLargerHistogramBucketThanDataRate(
568568
+ "\"aggs\": {\"timestamp\":{\"max\":{\"field\":\"timestamp\"}},"
569569
+ "\"bytes-delta\":{\"derivative\":{\"buckets_path\":\"avg_bytes_out\"}},"
570570
+ "\"avg_bytes_out\":{\"avg\":{\"field\":\"network_bytes_out\"}} }}}}}";
571-
new DatafeedBuilder(datafeedId, jobId, "network-data", "doc")
571+
new DatafeedBuilder(datafeedId, jobId, "network-data")
572572
.setAggregations(aggregations)
573573
.setChunkingTimespan("300s")
574574
.build();
@@ -614,7 +614,7 @@ public void testLookbackUsingDerivativeAggWithSmallerHistogramBucketThanDataRate
614614
+ "\"aggs\": {\"timestamp\":{\"max\":{\"field\":\"timestamp\"}},"
615615
+ "\"bytes-delta\":{\"derivative\":{\"buckets_path\":\"avg_bytes_out\"}},"
616616
+ "\"avg_bytes_out\":{\"avg\":{\"field\":\"network_bytes_out\"}} }}}}}";
617-
new DatafeedBuilder(datafeedId, jobId, "network-data", "doc")
617+
new DatafeedBuilder(datafeedId, jobId, "network-data")
618618
.setAggregations(aggregations)
619619
.setChunkingTimespan("300s")
620620
.build();
@@ -658,7 +658,7 @@ public void testLookbackWithoutPermissions() throws Exception {
658658
+ "\"avg_bytes_out\":{\"avg\":{\"field\":\"network_bytes_out\"}} }}}}}";
659659

660660
// At the time we create the datafeed the user can access the network-data index that we have access to
661-
new DatafeedBuilder(datafeedId, jobId, "network-data", "doc")
661+
new DatafeedBuilder(datafeedId, jobId, "network-data")
662662
.setAggregations(aggregations)
663663
.setChunkingTimespan("300s")
664664
.setAuthHeader(BASIC_AUTH_VALUE_ML_ADMIN_WITH_SOME_DATA_ACCESS)
@@ -712,7 +712,7 @@ public void testLookbackWithPipelineBucketAgg() throws Exception {
712712
+ "\"airlines\":{\"terms\":{\"field\":\"airline.keyword\",\"size\":10}},"
713713
+ "\"percentile95_airlines_count\":{\"percentiles_bucket\":" +
714714
"{\"buckets_path\":\"airlines._count\", \"percents\": [95]}}}}}";
715-
new DatafeedBuilder(datafeedId, jobId, "airline-data", "response").setAggregations(aggregations).build();
715+
new DatafeedBuilder(datafeedId, jobId, "airline-data").setAggregations(aggregations).build();
716716

717717
openJob(client(), jobId);
718718

@@ -801,7 +801,7 @@ public void testLookbackOnlyGivenAggregationsWithHistogramAndRollupIndex() throw
801801
+ "\"aggregations\":{"
802802
+ "\"time stamp\":{\"max\":{\"field\":\"time stamp\"}},"
803803
+ "\"responsetime\":{\"avg\":{\"field\":\"responsetime\"}}}}}";
804-
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs-rollup", "response").setAggregations(aggregations).build();
804+
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs-rollup").setAggregations(aggregations).build();
805805
openJob(client(), jobId);
806806

807807
startDatafeedAndWaitUntilStopped(datafeedId);
@@ -872,7 +872,7 @@ public void testLookbackWithoutPermissionsAndRollup() throws Exception {
872872

873873

874874
// At the time we create the datafeed the user can access the network-data index that we have access to
875-
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs-rollup", "doc")
875+
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs-rollup")
876876
.setAggregations(aggregations)
877877
.setChunkingTimespan("300s")
878878
.setAuthHeader(BASIC_AUTH_VALUE_ML_ADMIN_WITH_SOME_DATA_ACCESS)
@@ -919,7 +919,7 @@ public void testLookbackWithSingleBucketAgg() throws Exception {
919919
+ "\"time stamp\":{\"max\":{\"field\":\"time stamp\"}},"
920920
+ "\"airlineFilter\":{\"filter\":{\"term\": {\"airline\":\"AAA\"}},"
921921
+ " \"aggregations\":{\"responsetime\":{\"avg\":{\"field\":\"responsetime\"}}}}}}}";
922-
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs", "response").setAggregations(aggregations).build();
922+
new DatafeedBuilder(datafeedId, jobId, "airline-data-aggs").setAggregations(aggregations).build();
923923
openJob(client(), jobId);
924924

925925
startDatafeedAndWaitUntilStopped(datafeedId);
@@ -936,7 +936,7 @@ public void testRealtime() throws Exception {
936936
String jobId = "job-realtime-1";
937937
createJob(jobId, "airline");
938938
String datafeedId = jobId + "-datafeed";
939-
new DatafeedBuilder(datafeedId, jobId, "airline-data", "response").build();
939+
new DatafeedBuilder(datafeedId, jobId, "airline-data").build();
940940
openJob(client(), jobId);
941941

942942
Request startRequest = new Request("POST", MachineLearning.BASE_PATH + "datafeeds/" + datafeedId + "/_start");
@@ -994,7 +994,7 @@ public void testForceDeleteWhileDatafeedIsRunning() throws Exception {
994994
String jobId = "job-realtime-2";
995995
createJob(jobId, "airline");
996996
String datafeedId = jobId + "-datafeed";
997-
new DatafeedBuilder(datafeedId, jobId, "airline-data", "response").build();
997+
new DatafeedBuilder(datafeedId, jobId, "airline-data").build();
998998
openJob(client(), jobId);
999999

10001000
Request startRequest = new Request("POST", MachineLearning.BASE_PATH + "datafeeds/" + datafeedId + "/_start");
@@ -1059,7 +1059,7 @@ public LookbackOnlyTestHelper setShouldSucceedProcessing(boolean value) {
10591059
public void execute() throws Exception {
10601060
createJob(jobId, airlineVariant);
10611061
String datafeedId = "datafeed-" + jobId;
1062-
new DatafeedBuilder(datafeedId, jobId, dataIndex, "response")
1062+
new DatafeedBuilder(datafeedId, jobId, dataIndex)
10631063
.setScriptedFields(addScriptedFields ?
10641064
"{\"airline\":{\"script\":{\"lang\":\"painless\",\"inline\":\"doc['airline'].value\"}}}" : null)
10651065
.build();
@@ -1159,18 +1159,16 @@ private static class DatafeedBuilder {
11591159
String datafeedId;
11601160
String jobId;
11611161
String index;
1162-
String type;
11631162
boolean source;
11641163
String scriptedFields;
11651164
String aggregations;
11661165
String authHeader = BASIC_AUTH_VALUE_SUPER_USER;
11671166
String chunkingTimespan;
11681167

1169-
DatafeedBuilder(String datafeedId, String jobId, String index, String type) {
1168+
DatafeedBuilder(String datafeedId, String jobId, String index) {
11701169
this.datafeedId = datafeedId;
11711170
this.jobId = jobId;
11721171
this.index = index;
1173-
this.type = type;
11741172
}
11751173

11761174
DatafeedBuilder setSource(boolean enableSource) {

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DeleteExpiredDataIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.List;
4141
import java.util.concurrent.TimeUnit;
4242

43+
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
4344
import static org.hamcrest.Matchers.equalTo;
4445
import static org.hamcrest.Matchers.greaterThan;
4546
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -49,12 +50,11 @@
4950
public class DeleteExpiredDataIT extends MlNativeAutodetectIntegTestCase {
5051

5152
private static final String DATA_INDEX = "delete-expired-data-test-data";
52-
private static final String DATA_TYPE = "_doc";
5353

5454
@Before
5555
public void setUpData() throws IOException {
5656
client().admin().indices().prepareCreate(DATA_INDEX)
57-
.addMapping(DATA_TYPE, "time", "type=date,format=epoch_millis")
57+
.addMapping(SINGLE_MAPPING_NAME, "time", "type=date,format=epoch_millis")
5858
.get();
5959

6060
// We are going to create data for last 2 days

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ModelPlotsIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Set;
2929
import java.util.stream.Collectors;
3030

31+
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
3132
import static org.hamcrest.Matchers.containsInAnyOrder;
3233
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3334
import static org.hamcrest.Matchers.is;
@@ -36,12 +37,11 @@
3637
public class ModelPlotsIT extends MlNativeAutodetectIntegTestCase {
3738

3839
private static final String DATA_INDEX = "model-plots-test-data";
39-
private static final String DATA_TYPE = "doc";
4040

4141
@Before
4242
public void setUpData() {
4343
client().admin().indices().prepareCreate(DATA_INDEX)
44-
.addMapping(DATA_TYPE, "time", "type=date,format=epoch_millis", "user", "type=keyword")
44+
.addMapping(SINGLE_MAPPING_NAME, "time", "type=date,format=epoch_millis", "user", "type=keyword")
4545
.get();
4646

4747
List<String> users = Arrays.asList("user_1", "user_2", "user_3");
@@ -53,7 +53,7 @@ public void setUpData() {
5353
for (int bucket = 0; bucket < totalBuckets; bucket++) {
5454
long timestamp = nowMillis - TimeValue.timeValueHours(totalBuckets - bucket).getMillis();
5555
for (String user : users) {
56-
IndexRequest indexRequest = new IndexRequest(DATA_INDEX, DATA_TYPE);
56+
IndexRequest indexRequest = new IndexRequest(DATA_INDEX);
5757
indexRequest.source("time", timestamp, "user", user);
5858
bulkRequestBuilder.add(indexRequest);
5959
}

0 commit comments

Comments
 (0)