Skip to content

Commit 470afad

Browse files
committed
handle empty array logic in DocumentParser
1 parent b9535e1 commit 470afad

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,12 @@ private static void parseNonDynamicArray(
769769
}
770770
previousToken = token;
771771
}
772-
if (mapper != null && previousToken == XContentParser.Token.START_ARRAY) {
773-
mapper.handleEmptyArray(context);
772+
if (mapper != null
773+
&& mapper.supportStoringArrayOffsets(context)
774+
&& previousToken == XContentParser.Token.START_ARRAY
775+
&& context.isImmediateParentAnArray()
776+
&& context.getRecordedSource() == false) {
777+
context.getOffSetContext().maybeRecordEmptyArray(mapper.getOffsetFieldName());
774778
}
775779
context.setImmediateXContentParent(token);
776780
if (elements <= 1 && canRemoveSingleLeafElement) {

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,9 @@ public boolean supportStoringArrayOffsets(DocumentParserContext context) {
11141114
}
11151115
}
11161116

1117-
public void handleEmptyArray(DocumentParserContext context) {
1118-
if (offsetsFieldName != null && context.isImmediateParentAnArray() && context.getRecordedSource() == false) {
1119-
context.getOffSetContext().maybeRecordEmptyArray(offsetsFieldName);
1120-
}
1117+
@Override
1118+
public String getOffsetFieldName() {
1119+
return offsetsFieldName;
11211120
}
11221121

11231122
protected void parseCreateField(DocumentParserContext context) throws IOException {

server/src/main/java/org/elasticsearch/index/mapper/Mapper.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,18 @@ public static FieldType freezeAndDeduplicateFieldType(FieldType fieldType) {
213213
*/
214214
public abstract int getTotalFieldsCount();
215215

216+
/**
217+
* @return whether this mapper support storing leaf array elements natively when synthetic source is enabled.
218+
*/
216219
public boolean supportStoringArrayOffsets(DocumentParserContext context) {
217220
return false;
218221
}
219222

220-
public void handleEmptyArray(DocumentParserContext context) {}
223+
/**
224+
* @return the offset field name use the store offsets iff {@link #supportStoringArrayOffsets(DocumentParserContext)} returns
225+
* <code>true</code>.
226+
*/
227+
public String getOffsetFieldName() {
228+
return null;
229+
}
221230
}

0 commit comments

Comments
 (0)