diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/TermsGroupSourceTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/TermsGroupSourceTests.java index c143fa9abf3f0..0ceda5815c9f0 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/TermsGroupSourceTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/TermsGroupSourceTests.java @@ -28,6 +28,11 @@ public static TermsGroupSource randomTermsGroupSource(Version version) { return new TermsGroupSource(field, scriptConfig, missingBucket); } + public static TermsGroupSource randomTermsGroupSourceNoScript() { + String field = randomAlphaOfLengthBetween(1, 20); + return new TermsGroupSource(field, null, randomBoolean()); + } + @Override protected TermsGroupSource doParseInstance(XContentParser parser) throws IOException { return TermsGroupSource.fromXContent(parser, false); @@ -43,4 +48,9 @@ protected Reader instanceReader() { return TermsGroupSource::new; } + public void testSupportsIncrementalBucketUpdate() { + TermsGroupSource terms = randomTermsGroupSource(); + assertEquals(terms.getScriptConfig() == null, terms.supportsIncrementalBucketUpdate()); + } + } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollector.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollector.java index 1aea4f0d4576d..6abf7c94f747e 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollector.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollector.java @@ -536,6 +536,11 @@ static Map createFieldCollectors(Map fieldCollectors = new HashMap<>(); for (Entry entry : groups.entrySet()) { + // skip any fields that use scripts + if (entry.getValue().getScriptConfig() != null) { + continue; + } + switch (entry.getValue().getType()) { case TERMS: fieldCollectors.put( diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollectorTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollectorTests.java index a09cc2a4a75d3..4942993dcaf8d 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollectorTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollectorTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.xpack.core.transform.transforms.pivot.GroupConfig; import org.elasticsearch.xpack.core.transform.transforms.pivot.GroupConfigTests; import org.elasticsearch.xpack.core.transform.transforms.pivot.HistogramGroupSourceTests; +import org.elasticsearch.xpack.core.transform.transforms.pivot.ScriptConfigTests; import org.elasticsearch.xpack.core.transform.transforms.pivot.SingleGroupSource; import org.elasticsearch.xpack.core.transform.transforms.pivot.TermsGroupSource; import org.elasticsearch.xpack.core.transform.transforms.pivot.TermsGroupSourceTests; @@ -80,7 +81,7 @@ public void testPageSize() throws IOException { assertEquals(10, getCompositeAggregationBuilder(collector.buildChangesQuery(new SearchSourceBuilder(), null, 10)).size()); // a terms group_by is limited by terms query - SingleGroupSource termsGroupBy = TermsGroupSourceTests.randomTermsGroupSource(); + SingleGroupSource termsGroupBy = TermsGroupSourceTests.randomTermsGroupSourceNoScript(); groups.put("terms", termsGroupBy); collector = CompositeBucketsChangeCollector.buildChangeCollector(getCompositeAggregation(groups), groups, null); @@ -196,6 +197,24 @@ public void testDateHistogramFieldCollector() throws IOException { assertNull(queryBuilder); } + public void testNoTermsFieldCollectorForScripts() throws IOException { + Map groups = new LinkedHashMap<>(); + + // terms with value script + SingleGroupSource termsGroupBy = new TermsGroupSource("id", ScriptConfigTests.randomScriptConfig(), false); + groups.put("id", termsGroupBy); + + Map fieldCollectors = CompositeBucketsChangeCollector.createFieldCollectors(groups, null); + assertTrue(fieldCollectors.isEmpty()); + + // terms with only a script + termsGroupBy = new TermsGroupSource(null, ScriptConfigTests.randomScriptConfig(), false); + groups.put("id", termsGroupBy); + + fieldCollectors = CompositeBucketsChangeCollector.createFieldCollectors(groups, null); + assertTrue(fieldCollectors.isEmpty()); + } + private static CompositeAggregationBuilder getCompositeAggregation(Map groups) throws IOException { CompositeAggregationBuilder compositeAggregation; try (XContentBuilder builder = jsonBuilder()) {