Skip to content

Commit d1561ed

Browse files
committed
fix text structure NPE when fields have null value
1 parent 509c112 commit d1561ed

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

x-pack/plugin/text-structure/src/main/java/org/elasticsearch/xpack/textstructure/structurefinder/TextStructureUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,10 @@ static Tuple<Map<String, String>, FieldStats> guessMappingAndCalculateFieldStats
425425
);
426426
}
427427

428-
Collection<String> fieldValuesAsStrings = fieldValues.stream().map(Object::toString).collect(Collectors.toList());
428+
Collection<String> fieldValuesAsStrings = fieldValues.stream()
429+
.filter(value -> value != null)
430+
.map(Object::toString)
431+
.collect(Collectors.toList());
429432
Map<String, String> mapping = guessScalarMapping(
430433
explanation,
431434
fieldName,

x-pack/plugin/text-structure/src/test/java/org/elasticsearch/xpack/textstructure/structurefinder/TextStructureUtilsTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,16 @@ public void testGuessGeoShape() {
11061106
}
11071107
}
11081108

1109+
public void testGuessMappingWithNullValue() {
1110+
Map<String, String> expected = Collections.singletonMap(TextStructureUtils.MAPPING_TYPE_SETTING, "keyword");
1111+
1112+
Consumer<Boolean> testGuessMappingGivenEcsCompatibility = (ecsCompatibility) -> {
1113+
assertEquals(expected, guessMapping(explanation, "foo", Arrays.asList("ERROR", null, "DEBUG"), ecsCompatibility));
1114+
};
1115+
1116+
ecsCompatibilityModes.forEach(testGuessMappingGivenEcsCompatibility);
1117+
}
1118+
11091119
private Map<String, String> guessMapping(
11101120
List<String> explanation,
11111121
String fieldName,

0 commit comments

Comments
 (0)