|
8 | 8 |
|
9 | 9 | import org.apache.http.util.EntityUtils; |
10 | 10 | import org.elasticsearch.Build; |
| 11 | +import org.elasticsearch.TransportVersions; |
11 | 12 | import org.elasticsearch.Version; |
12 | 13 | import org.elasticsearch.client.Node; |
13 | 14 | import org.elasticsearch.client.Request; |
| 15 | +import org.elasticsearch.client.RequestOptions; |
14 | 16 | import org.elasticsearch.client.Response; |
15 | 17 | import org.elasticsearch.client.RestClient; |
16 | 18 | import org.elasticsearch.client.RestClientBuilder; |
| 19 | +import org.elasticsearch.client.WarningsHandler; |
17 | 20 | import org.elasticsearch.cluster.metadata.DataStream; |
18 | 21 | import org.elasticsearch.cluster.metadata.DataStreamTestHelper; |
19 | 22 | import org.elasticsearch.common.settings.SecureString; |
@@ -418,8 +421,27 @@ private void createDataStreamFromNonDataStreamIndices(String dataStreamFromNonDa |
418 | 421 | putIndexTemplateRequest.setJsonEntity( |
419 | 422 | indexTemplate.replace("$TEMPLATE", templateWithNoTimestamp).replace("$PATTERN", dataStreamFromNonDataStreamIndices + "-*") |
420 | 423 | ); |
421 | | - assertOK(client().performRequest(putIndexTemplateRequest)); |
422 | 424 | String indexName = dataStreamFromNonDataStreamIndices + "-01"; |
| 425 | + if (minimumTransportVersion().before(TransportVersions.V_8_0_0)) { |
| 426 | + /* |
| 427 | + * It is not possible to create a 7.x index template with a type. And you can't create an empty index with a type. But you can |
| 428 | + * create the index with a type by posting a document to an index with a type. We do that here so that we test that the type is |
| 429 | + * removed when we reindex into 8.x. |
| 430 | + */ |
| 431 | + String typeName = "test-type"; |
| 432 | + Request createIndexRequest = new Request("POST", indexName + "/" + typeName); |
| 433 | + createIndexRequest.setJsonEntity(""" |
| 434 | + { |
| 435 | + "@timestamp": "2099-11-15T13:12:00", |
| 436 | + "message": "GET /search HTTP/1.1 200 1070000", |
| 437 | + "user": { |
| 438 | + "id": "kimchy" |
| 439 | + } |
| 440 | + }"""); |
| 441 | + createIndexRequest.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE).build()); |
| 442 | + assertOK(client().performRequest(createIndexRequest)); |
| 443 | + } |
| 444 | + assertOK(client().performRequest(putIndexTemplateRequest)); |
423 | 445 | bulkLoadDataMissingTimestamp(indexName); |
424 | 446 | /* |
425 | 447 | * Next, we will change the index's mapping to include a @timestamp field since we are going to convert it to a data stream. But |
|
0 commit comments