Skip to content

Commit c699bfd

Browse files
committed
updates from review
1 parent 2ac1c55 commit c699bfd

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

server/src/main/java/org/elasticsearch/index/mapper/flattened/FlattenedFieldSyntheticWriterHelper.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,6 @@ private static Prefix diff(final List<String> a, final List<String> b) {
9999
}
100100
return new Prefix(diff);
101101
}
102-
103-
@Override
104-
public int hashCode() {
105-
return Objects.hash(this.parts);
106-
}
107-
108-
@Override
109-
public boolean equals(Object obj) {
110-
if (obj == null) {
111-
return false;
112-
}
113-
if (getClass() != obj.getClass()) {
114-
return false;
115-
}
116-
Prefix other = (Prefix) obj;
117-
return Objects.equals(this.parts, other.parts);
118-
}
119102
}
120103

121104
private static class KeyValue {
@@ -208,9 +191,13 @@ public void write(final XContentBuilder b) throws IOException {
208191

209192
var startPrefix = curr.prefix.diff(openObjects);
210193
if (startPrefix.parts.isEmpty() == false && startPrefix.parts.getFirst().equals(lastScalarSingleLeaf)) {
211-
// In the open object, there is a leaf with a scalar value, which is also the first
212-
// part of the current path. Instead of traversing down into the path and building objects,
213-
// combine the path into a single leaf and add it as a field.
194+
// In the currently open object, a previous key with a scalar value is a prefix of the current path. Instead of traversing
195+
// the path and building nested objects, we concatenate the path into a single key and add it as a field. For example:
196+
// Assume the current object contains "foo": 10 and "foo.bar": 20. Since key-value pairs are sorted, "foo" is processed
197+
// first. When writing the field "foo", `lastScalarSingleLeaf` is set to "foo" because it has a scalar value. Next, when
198+
// processing "foo.bar", we check if `lastScalarSingleLeaf` ("foo") is a prefix of "foo.bar". Since it is, this indicates a
199+
// conflict: a scalar value and an object share the same key ("foo"). To disambiguate, we create a flat key "foo.bar"
200+
// with the value 20 in the current object, rather than creating a nested object as usual.
214201
if (curr.pathEquals(next) == false) {
215202
String combinedPath = concatPath(startPrefix, curr.leaf());
216203
writeField(b, values, combinedPath);

0 commit comments

Comments
 (0)