From 50d742320d34bc2ab533428695aeb48216f7713b Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Fri, 8 Mar 2019 12:15:09 +0100 Subject: [PATCH] store the doc type in the internal index (#39824) store the doc type in the internal data frame index --- .../xpack/core/dataframe/DataFrameField.java | 1 + .../transforms/DataFrameTransformConfig.java | 20 ++++++++++++------- .../DataFrameTransformConfigTests.java | 18 +++++++++++++++++ .../persistence/DataFrameInternalIndex.java | 5 +---- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/DataFrameField.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/DataFrameField.java index 93280fc457f..73bdca2e59e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/DataFrameField.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/DataFrameField.java @@ -23,6 +23,7 @@ public final class DataFrameField { public static final ParseField TIMEOUT = new ParseField("timeout"); public static final ParseField WAIT_FOR_COMPLETION = new ParseField("wait_for_completion"); public static final ParseField STATS_FIELD = new ParseField("stats"); + public static final ParseField INDEX_DOC_TYPE = new ParseField("doc_type"); // common strings public static final String TASK_NAME = "data_frame/transforms"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransformConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransformConfig.java index 894961c869c..e1c7dad8e13 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransformConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransformConfig.java @@ -36,7 +36,7 @@ import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optiona */ public class DataFrameTransformConfig extends AbstractDiffable implements Writeable, ToXContentObject { - private static final String NAME = "data_frame_transform"; + private static final String NAME = "data_frame_transform_config"; public static final ParseField HEADERS = new ParseField("headers"); public static final ParseField SOURCE = new ParseField("source"); public static final ParseField DESTINATION = new ParseField("dest"); @@ -75,24 +75,26 @@ public class DataFrameTransformConfig extends AbstractDiffable headers = (Map) args[3]; + Map headers = (Map) args[4]; // default handling: if the user does not specify a query, we default to match_all QueryConfig queryConfig = null; - if (args[4] == null) { + if (args[5] == null) { queryConfig = new QueryConfig(Collections.singletonMap(MatchAllQueryBuilder.NAME, Collections.emptyMap()), new MatchAllQueryBuilder()); } else { - queryConfig = (QueryConfig) args[4]; + queryConfig = (QueryConfig) args[5]; } - PivotConfig pivotConfig = (PivotConfig) args[5]; + PivotConfig pivotConfig = (PivotConfig) args[6]; return new DataFrameTransformConfig(id, source, dest, headers, queryConfig, pivotConfig); }); @@ -100,6 +102,7 @@ public class DataFrameTransformConfig extends AbstractDiffable p.mapStrings(), HEADERS); parser.declareObject(optionalConstructorArg(), (p, c) -> QueryConfig.fromXContent(p, lenient), QUERY); parser.declareObject(optionalConstructorArg(), (p, c) -> PivotConfig.fromXContent(p, lenient), PIVOT_TRANSFORM); @@ -108,7 +111,7 @@ public class DataFrameTransformConfig extends AbstractDiffable createDataFrameTransformConfigFromString(pivotTransform, "test_header_injection")); } + public void testXContentForInternalStorage() throws IOException { + DataFrameTransformConfig dataFrameTransformConfig = randomDataFrameTransformConfig(); + + try (XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()) { + XContentBuilder content = dataFrameTransformConfig.toXContent(xContentBuilder, getToXContentParams()); + String doc = Strings.toString(content); + + assertThat(doc, matchesPattern(".*\"doc_type\"\\s*:\\s*\"data_frame_transform_config\".*")); + } + + try (XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()) { + XContentBuilder content = dataFrameTransformConfig.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); + String doc = Strings.toString(content); + + assertFalse(doc.contains("doc_type")); + } + } + public void testSetIdInBody() throws IOException { String pivotTransform = "{" + " \"id\" : \"body_id\"," diff --git a/x-pack/plugin/data-frame/src/main/java/org/elasticsearch/xpack/dataframe/persistence/DataFrameInternalIndex.java b/x-pack/plugin/data-frame/src/main/java/org/elasticsearch/xpack/dataframe/persistence/DataFrameInternalIndex.java index d9e0471e0a3..9f89ebb8553 100644 --- a/x-pack/plugin/data-frame/src/main/java/org/elasticsearch/xpack/dataframe/persistence/DataFrameInternalIndex.java +++ b/x-pack/plugin/data-frame/src/main/java/org/elasticsearch/xpack/dataframe/persistence/DataFrameInternalIndex.java @@ -38,9 +38,6 @@ public final class DataFrameInternalIndex { public static final String DOUBLE = "double"; public static final String KEYWORD = "keyword"; - // internal document types, e.g. "transform_config" - public static final String DOC_TYPE = "doc_type"; - public static IndexTemplateMetaData getIndexTemplateMetaData() throws IOException { IndexTemplateMetaData dataFrameTemplate = IndexTemplateMetaData.builder(INDEX_TEMPLATE_NAME) .patterns(Collections.singletonList(INDEX_TEMPLATE_NAME)) @@ -69,7 +66,7 @@ public final class DataFrameInternalIndex { // the schema definitions builder.startObject(PROPERTIES); // overall doc type - builder.startObject(DOC_TYPE).field(TYPE, KEYWORD).endObject(); + builder.startObject(DataFrameField.INDEX_DOC_TYPE.getPreferredName()).field(TYPE, KEYWORD).endObject(); // add the schema for transform configurations addDataFrameTransformsConfigMappings(builder);