From 3aa6a5766629516e6ffcc8c90b03935903c1f396 Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Wed, 6 Dec 2023 15:31:37 -0500 Subject: [PATCH] Ensure dynamicMapping updates are handled in insertion order (#103047) (#103083) The switch to holding dynamic fields in a hashmap effectively randomizes their iteration order. This can be troublesome when building the mapping update required by these updates. When iterating in an unknown order, recursing to the leaf mapper can occur many times `O(n^2)`. However, starting with insertion order, it will occur only `O(n)` times. closes: https://github.com/elastic/elasticsearch/issues/103011 --- docs/changelog/103047.yaml | 5 +++++ .../elasticsearch/index/mapper/DocumentParserContext.java | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/103047.yaml diff --git a/docs/changelog/103047.yaml b/docs/changelog/103047.yaml new file mode 100644 index 0000000000000..59f86d679b55f --- /dev/null +++ b/docs/changelog/103047.yaml @@ -0,0 +1,5 @@ +pr: 103047 +summary: Ensure `dynamicMapping` updates are handled in insertion order +area: Mapping +type: bug +issues: [] diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocumentParserContext.java b/server/src/main/java/org/elasticsearch/index/mapper/DocumentParserContext.java index f47b392115f81..9d5cb374a9a89 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocumentParserContext.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocumentParserContext.java @@ -22,8 +22,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -166,9 +166,9 @@ protected DocumentParserContext( mappingParserContext, source, new HashSet<>(), - new HashMap<>(), + new LinkedHashMap<>(), new HashSet<>(), - new HashMap<>(), + new LinkedHashMap<>(), new ArrayList<>(), null, null,