Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrik-es committed Oct 5, 2024
1 parent b1d84d3 commit 31efafe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ private static void parseNonDynamicArray(
}
boolean copyToFieldHasValuesInDocument = context.isWithinCopyTo() == false && context.isCopyToDestinationField(fullPath);

canRemoveSingleLeafElement = mode == Mapper.SourceKeepMode.ARRAYS
&& mapper instanceof NestedObjectMapper == false
canRemoveSingleLeafElement = mapper instanceof FieldMapper
&& mode == Mapper.SourceKeepMode.ARRAYS
&& fieldWithFallbackSyntheticSource == false
&& copyToFieldHasValuesInDocument == false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public void testIndexStoredArraySourceRootValueArrayDisabled() throws IOExceptio
{"bool_value":true,"int_value":[10,20,30]}""", syntheticSource);
}

public void testIndexStoredArraySourceSingleElement() throws IOException {
public void testIndexStoredArraySourceSingleLeafElement() throws IOException {
DocumentMapper documentMapper = createMapperServiceWithStoredArraySource(syntheticSourceMapping(b -> {
b.startObject("int_value").field("type", "integer").endObject();
})).documentMapper();
Expand All @@ -542,6 +542,20 @@ public void testIndexStoredArraySourceSingleElement() throws IOException {
assertNull(doc.rootDoc().getField("_ignored_source"));
}

public void testIndexStoredArraySourceSingleObjectElement() throws IOException {
DocumentMapper documentMapper = createMapperServiceWithStoredArraySource(syntheticSourceMapping(b -> {
b.startObject("path").startObject("properties");
{
b.startObject("int_value").field("type", "integer").endObject();
}
b.endObject().endObject();
})).documentMapper();
var syntheticSource = syntheticSource(documentMapper, b -> {
b.startArray("path").startObject().field("int_value", 10).endObject().endArray();
});
assertEquals("{\"path\":[{\"int_value\":10}]}", syntheticSource);
}

public void testFieldStoredArraySourceRootValueArray() throws IOException {
DocumentMapper documentMapper = createMapperService(syntheticSourceMapping(b -> {
b.startObject("int_value").field("type", "integer").field(Mapper.SYNTHETIC_SOURCE_KEEP_PARAM, "arrays").endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,11 @@ public void testSyntheticSourceKeepArrays() throws IOException {
buildInput.accept(builder);
builder.endObject();
String expected = Strings.toString(builder);
assertThat(syntheticSource(mapperAll, buildInput), equalTo(expected));
String actual = syntheticSource(mapperAll, buildInput);
// Check for single-element array, the array source is not stored in this case.
if (expected.replace("[","").replace("]", "").equals(actual) == false) {
assertThat(actual, equalTo(expected));
}
}

@Override
Expand Down

0 comments on commit 31efafe

Please sign in to comment.