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

Fix flat_object long field error #13259

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix snapshot _status API to return correct status for partial snapshots ([#12812](https://github.com/opensearch-project/OpenSearch/pull/12812))
- Improve the error messages for _stats with closed indices ([#13012](https://github.com/opensearch-project/OpenSearch/pull/13012))
- Ignore BaseRestHandler unconsumed content check as it's always consumed. ([#13290](https://github.com/opensearch-project/OpenSearch/pull/13290))
- Fix mapper_parsing_exception when using flat_object fields with names longer than 11 characters ([#13259](https://github.com/opensearch-project/OpenSearch/pull/13259))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ private void parseToken(StringBuilder path, String currentFieldName) throws IOEx
// skip
} else if (this.parser.currentToken() == Token.START_OBJECT) {
parseToken(path, currentFieldName);
int dotIndex = path.lastIndexOf(DOT_SYMBOL);
if (dotIndex != -1) {
int dotIndex = path.lastIndexOf(DOT_SYMBOL, path.length());

msfroh marked this conversation as resolved.
Show resolved Hide resolved
if (dotIndex != -1 && path.length() > currentFieldName.length()) {
path.setLength(path.length() - currentFieldName.length() - 1);
}
} else {
Expand All @@ -117,8 +118,8 @@ private void parseToken(StringBuilder path, String currentFieldName) throws IOEx
parseValue(parsedFields);
this.valueList.add(parsedFields.toString());
this.valueAndPathList.add(path + EQUAL_SYMBOL + parsedFields);
int dotIndex = path.lastIndexOf(DOT_SYMBOL);
if (dotIndex != -1) {
int dotIndex = path.lastIndexOf(DOT_SYMBOL, path.length());
if (dotIndex != -1 && path.length() > currentFieldName.length()) {
path.setLength(path.length() - currentFieldName.length() - 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,49 @@ 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
Loading