From 65400629bdfbfa9242336518557968d70131f74a Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 4 Aug 2022 12:31:36 +0100 Subject: [PATCH 1/4] Don't modify source map when parsing composite runtime field --- .../111_search_time_composite.yml | 36 +++++++++++++++++++ .../index/mapper/CompositeRuntimeField.java | 4 ++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 modules/runtime-fields-common/src/yamlRestTest/resources/rest-api-spec/test/runtime_fields/111_search_time_composite.yml diff --git a/modules/runtime-fields-common/src/yamlRestTest/resources/rest-api-spec/test/runtime_fields/111_search_time_composite.yml b/modules/runtime-fields-common/src/yamlRestTest/resources/rest-api-spec/test/runtime_fields/111_search_time_composite.yml new file mode 100644 index 0000000000000..dc10d16c26ca3 --- /dev/null +++ b/modules/runtime-fields-common/src/yamlRestTest/resources/rest-api-spec/test/runtime_fields/111_search_time_composite.yml @@ -0,0 +1,36 @@ +--- +setup: + - do: + indices.create: + index: test + body: + settings: + number_of_shards: 2 + number_of_replicas: 0 + - do: + bulk: + index: test + refresh: true + body: | + {"index":{}} + {"A":2} + +--- +"search-time composite across multiple shards": + - do: + search: + index: test + body: + query: + term: + "r.shouldReturn" : true + runtime_mappings: + r: + type: composite + fields: + shouldReturn: + type: boolean + script: + source: "emit('shouldReturn',true)" + + - match: {hits.total.value: 1} diff --git a/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java b/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java index a8e9b487160de..c6d5b00fae1f8 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -85,7 +86,8 @@ protected RuntimeField createRuntimeField(MappingParserContext parserContext) { name, lookup -> factory.newFactory(name, script.get().getParams(), lookup) ); - Map runtimeFields = RuntimeField.parseRuntimeFields(fields.getValue(), parserContext, builder, false); + Map runtimeFields + = RuntimeField.parseRuntimeFields(new HashMap<>(fields.getValue()), parserContext, builder, false); return new CompositeRuntimeField(name, getParameters(), runtimeFields.values()); } }); From 328b48ae14fa8c2f608f65e47199fbe2d1f0bfe7 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 4 Aug 2022 12:41:07 +0100 Subject: [PATCH 2/4] Update docs/changelog/89114.yaml --- docs/changelog/89114.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/89114.yaml diff --git a/docs/changelog/89114.yaml b/docs/changelog/89114.yaml new file mode 100644 index 0000000000000..c363437586249 --- /dev/null +++ b/docs/changelog/89114.yaml @@ -0,0 +1,5 @@ +pr: 89114 +summary: Don't modify source map when parsing composite runtime field +area: Mapping +type: bug +issues: [] From 54787e3079f00d287df37fe666390b367dc48bc9 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 4 Aug 2022 14:40:47 +0100 Subject: [PATCH 3/4] don't output fields twice, duh --- .../elasticsearch/index/mapper/CompositeRuntimeField.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java b/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java index c6d5b00fae1f8..5f32323849340 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java @@ -120,11 +120,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws for (FieldMapper.Parameter parameter : parameters) { parameter.toXContent(builder, includeDefaults); } - builder.startObject("fields"); - for (RuntimeField subfield : subfields) { - subfield.toXContent(builder, params); - } - builder.endObject(); builder.endObject(); return builder; } From 25c8c3e6d63416cf2d1bc9f93e17f97b343905ff Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 4 Aug 2022 14:41:34 +0100 Subject: [PATCH 4/4] spotless --- .../elasticsearch/index/mapper/CompositeRuntimeField.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java b/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java index 5f32323849340..ea8fbb0dcd60b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompositeRuntimeField.java @@ -86,8 +86,12 @@ protected RuntimeField createRuntimeField(MappingParserContext parserContext) { name, lookup -> factory.newFactory(name, script.get().getParams(), lookup) ); - Map runtimeFields - = RuntimeField.parseRuntimeFields(new HashMap<>(fields.getValue()), parserContext, builder, false); + Map runtimeFields = RuntimeField.parseRuntimeFields( + new HashMap<>(fields.getValue()), + parserContext, + builder, + false + ); return new CompositeRuntimeField(name, getParameters(), runtimeFields.values()); } });