Skip to content

Commit bea6446

Browse files
committed
Rewrite another setFieldValue arity, too
This one is a bit trickier, so I've lampshaded the surprising part with a comment, and also there's a newly added test on main via
1 parent 661766e commit bea6446

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

server/src/main/java/org/elasticsearch/ingest/IngestDocument.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -716,16 +716,17 @@ public void setFieldValue(String path, ValueSource valueSource) {
716716
*/
717717
public void setFieldValue(String path, ValueSource valueSource, boolean ignoreEmptyValue) {
718718
Object value = valueSource.copyAndResolve(templateModel);
719-
if (ignoreEmptyValue && valueSource instanceof ValueSource.TemplatedValue) {
720-
if (value == null) {
721-
return;
722-
}
723-
String valueStr = (String) value;
724-
if (valueStr.isEmpty()) {
725-
return;
719+
if (valueSource instanceof ValueSource.TemplatedValue) {
720+
if (ignoreEmptyValue == false || valueNotEmpty(value)) {
721+
setFieldValue(path, value);
726722
}
723+
} else {
724+
// it may seem a little surprising to not bother checking ignoreEmptyValue value here.
725+
// but this corresponds to the case of, e.g., a set processor with a literal value.
726+
// so if you have `"value": ""` and `"ignore_empty_value": true` right next to each other
727+
// in your processor definition, then, well, that's on you for being a bit silly. ;)
728+
setFieldValue(path, value);
727729
}
728-
setFieldValue(path, value);
729730
}
730731

731732
/**

0 commit comments

Comments
 (0)