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 ClassCastException when using dynamic template with flat_object mapping and dots in field names #13081

Closed
wants to merge 2 commits into from
Closed
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 @@ -138,6 +138,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix bulk API ignores ingest pipeline for upsert ([#12883](https://github.com/opensearch-project/OpenSearch/pull/12883))
- Fix issue with feature flags where default value may not be honored ([#12849](https://github.com/opensearch-project/OpenSearch/pull/12849))
- Fix UOE While building Exists query for nested search_as_you_type field ([#12048](https://github.com/opensearch-project/OpenSearch/pull/12048))
- Fix ClassCastException when using dynamic template with flat_object mapping and dots in field names ([#13081](https://github.com/opensearch-project/OpenSearch/pull/13081))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,13 @@ private static Tuple<Integer, ObjectMapper> getDynamicParentMapper(
context.indexSettings().getSettings(),
context.path()
);
mapper = (ObjectMapper) builder.build(builderContext);
Mapper tmp = builder.build(builderContext);
if (tmp instanceof FlatObjectFieldMapper) {
throw new MapperParsingException(
"It is forbidden to create dynamic flat_object ([" + String.join(".", paths) + "]) with dots in field names"
);
}
mapper = (ObjectMapper) tmp;
if (mapper.nested() != ObjectMapper.Nested.NO) {
throw new MapperParsingException(
"It is forbidden to create dynamic nested objects (["
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,28 @@ public void testDotsWithDynamicNestedMapper() throws Exception {
assertEquals("It is forbidden to create dynamic nested objects ([foo]) through `copy_to` or dots in field names", e.getMessage());
}

public void testDotsWithDynamicFlatObjectMapper() throws Exception {
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
b.startArray("dynamic_templates");
{
b.startObject();
{
b.startObject("nested_object_fields");
{
b.field("match_mapping_type", "object");
b.startObject("mapping").field("type", "flat_object").endObject();
}
b.endObject();
}
b.endObject();
}
b.endArray();
}));

MapperParsingException e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> b.field("foo.bar", 42))));
assertEquals("It is forbidden to create dynamic flat_object ([foo.bar]) with dots in field names", e.getMessage());
}

public void testNestedHaveIdAndTypeFields() throws Exception {

DocumentMapper mapper = createDocumentMapper(mapping(b -> {
Expand Down
Loading