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

Do not throw exception when flat_object field is explicitly null #15375

Merged
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 @@ -67,6 +67,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fixed array field name omission in flat_object function for nested JSON ([#13620](https://github.com/opensearch-project/OpenSearch/pull/13620))
- Fix range aggregation optimization ignoring top level queries ([#15194](https://github.com/opensearch-project/OpenSearch/pull/15194))
- Fix incorrect parameter names in MinHash token filter configuration handling ([#15233](https://github.com/opensearch-project/OpenSearch/pull/15233))
- Fix indexing error when flat_object field is explicitly null ([#15375](https://github.com/opensearch-project/OpenSearch/pull/15375))
- Fix split response processor not included in allowlist ([#15393](https://github.com/opensearch-project/OpenSearch/pull/15393))
- Fix unchecked cast in dynamic action map getter ([#15394](https://github.com/opensearch-project/OpenSearch/pull/15394))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ setup:
} ]
}
}

- do:
msfroh marked this conversation as resolved.
Show resolved Hide resolved
index:
index: test_partial_flat_object
id: 4
body: {
"issue": {
"number": 999,
"labels": null
}
}
- do:
indices.refresh:
index: test_partial_flat_object
Expand Down Expand Up @@ -135,7 +144,7 @@ teardown:
}
}

- length: { hits.hits: 3 }
- length: { hits.hits: 4 }

# Match Query with exact dot path.
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,7 @@ protected void parseCreateField(ParseContext context) throws IOException {
if (context.externalValueSet()) {
String value = context.externalValue().toString();
parseValueAddFields(context, value, fieldType().name());
} else if (context.parser().currentToken() == XContentParser.Token.VALUE_NULL) {
context.parser().nextToken(); // This triggers an exception in DocumentParser.
// We could remove the above nextToken() call to skip the null value, but the existing
// behavior (since 2.7) throws the exception.
} else {
} else if (context.parser().currentToken() != XContentParser.Token.VALUE_NULL) {
JsonToStringXContentParser jsonToStringParser = new JsonToStringXContentParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.IGNORE_DEPRECATIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.StringContains.containsString;

public class FlatObjectFieldMapperTests extends MapperTestCase {
private static final String FIELD_TYPE = "flat_object";
Expand Down Expand Up @@ -133,9 +132,10 @@ public void testDefaults() throws Exception {

public void testNullValue() throws IOException {
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
MapperParsingException e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> b.nullField("field"))));
assertThat(e.getMessage(), containsString("object mapping for [_doc] tried to parse field [field] as object"));

ParsedDocument parsedDocument = mapper.parse(source(b -> b.nullField("field")));
assertEquals(1, parsedDocument.docs().size());
IndexableField[] fields = parsedDocument.rootDoc().getFields("field");
assertEquals(0, fields.length);
}

@Override
Expand Down
Loading