Data Streams: fix bwc test (#59528) (#59534)

(cherry picked from commit ed1a5c00abed8c63ad395ea93df7a303da7b7a65)
Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
This commit is contained in:
Andrei Dan 2020-07-14 15:17:20 +01:00 committed by GitHub
parent b357c1b77a
commit d477aa14ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 19 deletions

View File

@ -14,15 +14,12 @@ import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ObjectPath;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
@ -55,7 +52,6 @@ import java.util.stream.Collectors;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.upgrades.FullClusterRestartIT.assertNumHits;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsInAnyOrder;
@ -877,15 +873,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
public void testDataStreams() throws Exception {
assumeTrue("no data streams in versions before " + Version.V_7_9_0, getOldClusterVersion().onOrAfter(Version.V_7_9_0));
if (isRunningAgainstOldCluster()) {
String mapping = "{\n" +
" \"properties\": {\n" +
" \"@timestamp\": {\n" +
" \"type\": \"date\"\n" +
" }\n" +
" }\n" +
" }";
Template template = new Template(null, new CompressedXContent(mapping), null);
createComposableTemplate(client(), "dst", "ds", template);
createComposableTemplate(client(), "dst", "ds");
Request indexRequest = new Request("POST", "/ds/_doc/1?op_type=create&refresh");
XContentBuilder builder = JsonXContent.contentBuilder().startObject()
@ -909,16 +897,13 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
assertNumHits("ds", 1, 1);
}
private static void createComposableTemplate(RestClient client, String templateName, String indexPattern, Template template)
private static void createComposableTemplate(RestClient client, String templateName, String indexPattern)
throws IOException {
XContentBuilder builder = jsonBuilder();
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
StringEntity templateJSON = new StringEntity(
String.format(Locale.ROOT, "{\n" +
" \"index_patterns\": \"%s\",\n" +
" \"data_stream\": { \"timestamp_field\": \"@timestamp\" },\n" +
" \"template\": %s\n" +
"}", indexPattern, Strings.toString(builder)),
" \"data_stream\": {}\n" +
"}", indexPattern),
ContentType.APPLICATION_JSON);
Request createIndexTemplateRequest = new Request("PUT", "_index_template/" + templateName);
createIndexTemplateRequest.setEntity(templateJSON);