mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 09:28:55 -04:00
Check prefixes when constructing synthetic source for flattened fields (#129580)
* Check prefixes when constructing synthetic source for flattened fields * Update docs/changelog/129580.yaml
This commit is contained in:
parent
9e40bb3845
commit
b25d7b9471
3 changed files with 24 additions and 1 deletions
6
docs/changelog/129580.yaml
Normal file
6
docs/changelog/129580.yaml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
pr: 129580
|
||||||
|
summary: Check prefixes when constructing synthetic source for flattened fields
|
||||||
|
area: Mapping
|
||||||
|
type: bug
|
||||||
|
issues:
|
||||||
|
- 129508
|
|
@ -261,7 +261,7 @@ public class FlattenedFieldSyntheticWriterHelper {
|
||||||
final List<String> values
|
final List<String> values
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
startObject(b, startPrefix.prefix);
|
startObject(b, startPrefix.prefix);
|
||||||
if (currKeyValue.suffix.equals(nextKeyValue.suffix) == false) {
|
if (currKeyValue.prefix.equals(nextKeyValue.prefix) == false || currKeyValue.suffix.equals(nextKeyValue.suffix) == false) {
|
||||||
writeNestedObject(b, values, currKeyValue.suffix().suffix);
|
writeNestedObject(b, values, currKeyValue.suffix().suffix);
|
||||||
}
|
}
|
||||||
endObject(b, endPrefix.prefix);
|
endObject(b, endPrefix.prefix);
|
||||||
|
|
|
@ -851,6 +851,23 @@ public class FlattenedFieldMapperTests extends MapperTestCase {
|
||||||
assertThat(syntheticSource, equalTo("{\"field\":{\"key1\":\"val1\",\"obj1\":{\"key2\":\"val2\",\"key3\":[\"val3\",\"val4\"]}}}"));
|
assertThat(syntheticSource, equalTo("{\"field\":{\"key1\":\"val1\",\"obj1\":{\"key2\":\"val2\",\"key3\":[\"val3\",\"val4\"]}}}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSyntheticSourceWithCommonLeafField() throws IOException {
|
||||||
|
DocumentMapper mapper = createSytheticSourceMapperService(
|
||||||
|
mapping(b -> { b.startObject("field").field("type", "flattened").endObject(); })
|
||||||
|
).documentMapper();
|
||||||
|
|
||||||
|
var syntheticSource = syntheticSource(mapper, b -> {
|
||||||
|
b.startObject("field");
|
||||||
|
{
|
||||||
|
b.startObject("obj1").field("key", "foo").endObject();
|
||||||
|
b.startObject("obj2").field("key", "bar").endObject();
|
||||||
|
}
|
||||||
|
b.endObject();
|
||||||
|
});
|
||||||
|
assertThat(syntheticSource, equalTo("""
|
||||||
|
{"field":{"obj1":{"key":"foo"},"obj2":{"key":"bar"}}}"""));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean supportsCopyTo() {
|
protected boolean supportsCopyTo() {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue