Skip to content

Commit

Permalink
Fix flat_object long field error
Browse files Browse the repository at this point in the history
Signed-off-by: naomichi-y <[email protected]>
  • Loading branch information
naomichi-y committed Apr 17, 2024
1 parent 1c208d5 commit 5aa3812
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void parseToken(StringBuilder path, String currentFieldName) throws IOEx
parseToken(path, currentFieldName);
int dotIndex = path.lastIndexOf(DOT_SYMBOL);
if (dotIndex != -1) {
path.setLength(path.length() - currentFieldName.length() - 1);
path.setLength(Math.max(0, path.length() - currentFieldName.length() - 1));
}
} else {
if (!path.toString().contains(currentFieldName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,46 @@ public void testDocValue() throws Exception {
assertEquals(1, valueReaders.size());
}

public void testLongFieldNameWithHashArray() throws Exception {
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("test")
.startObject("properties")
.startObject("field")
.field("type", FIELD_TYPE)
.endObject()
.endObject()
.endObject()
.endObject()
.toString();
final DocumentMapper mapper = mapperService.documentMapperParser().parse("test", new CompressedXContent(mapping));

XContentBuilder json = XContentFactory.jsonBuilder()
.startObject()
.startObject("field")
.startObject("detail")
.startArray("fooooooooooo")
.startObject().field("name", "baz").endObject()
.startObject().field("name", "baz").endObject()
.endArray()
.endObject()
.endObject()
.endObject();

ParsedDocument d = mapper.parse(new SourceToParse("test", "1", BytesReference.bytes(json), MediaTypeRegistry.JSON));
writer.addDocument(d.rootDoc());
writer.commit();

IndexFieldData<?> fieldData = getForField("field");
List<LeafReaderContext> readers = refreshReader();
assertEquals(1, readers.size());

IndexFieldData<?> valueFieldData = getForField("field._value");
List<LeafReaderContext> valueReaders = refreshReader();
assertEquals(1, valueReaders.size());
}


@Override
protected String getFieldDataType() {
return FIELD_TYPE;
Expand Down

0 comments on commit 5aa3812

Please sign in to comment.