Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't modify source map when parsing composite runtime field #89114

Merged
merged 6 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/89114.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 89114
summary: Don't modify source map when parsing composite runtime field
area: Mapping
type: bug
issues: []
Original file line number Diff line number Diff line change
@@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,7 +86,12 @@ protected RuntimeField createRuntimeField(MappingParserContext parserContext) {
name,
lookup -> factory.newFactory(name, script.get().getParams(), lookup)
);
Map<String, RuntimeField> runtimeFields = RuntimeField.parseRuntimeFields(fields.getValue(), parserContext, builder, false);
Map<String, RuntimeField> runtimeFields = RuntimeField.parseRuntimeFields(
new HashMap<>(fields.getValue()),
parserContext,
builder,
false
);
return new CompositeRuntimeField(name, getParameters(), runtimeFields.values());
}
});
Expand Down Expand Up @@ -118,11 +124,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();
javanna marked this conversation as resolved.
Show resolved Hide resolved
builder.endObject();
return builder;
}
Expand Down