Handling null in foreach with on_failure

I have a pipeline where I split a field and then hand that off to a foreach processor. Sometimes the field is null. It appears that foreach throws an exception here regardless of whether I specify on_failure:

POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "split": {
          "field": "foo",
          "separator": """(\s+)?,(\s+)?""",
          "ignore_missing": true
        }
      },
      {
        "foreach": {
          "field": "foo",
          "processor": {
            "uppercase": {
              "field": "_ingest._value",
              "on_failure": [
                {
                  "set": {
                    "field": "_ingest._value",
                    "value": "empty"
                  }
                }
              ]
            }
          }
        }
      }
    ]
  },
  "docs": [
    {
      "_index": "index",
      "_type": "type",
      "_id": "id",
      "_source": {
        "foo": null
      }
    }
  ]
}

This gives the error:

  "docs": [
    {
      "error": {
        "root_cause": [
          {
            "type": "exception",
            "reason": "java.lang.IllegalArgumentException: java.lang.NullPointerException",
            "header": {
              "processor_type": "foreach"
            }
          }
        ],
        "type": "exception",
        "reason": "java.lang.IllegalArgumentException: java.lang.NullPointerException",
        "caused_by": {
          "type": "illegal_argument_exception",
          "reason": "java.lang.NullPointerException",
          "caused_by": {
            "type": "null_pointer_exception",
            "reason": null
          }
        },
        "header": {
          "processor_type": "foreach"
        }
      }
    }
  ]
}```

If that is expected behavior, can someone suggest a workaround?

Ah, ignore_failure works:

POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "split": {
          "field": "foo",
          "separator": """(\s+)?,(\s+)?""",
          "ignore_missing": true
        }
      },
      {
        "foreach": {
          "field": "foo",
          "processor": {
            "uppercase": {
              "field": "_ingest._value"
            }
          },
          "ignore_failure": true
        }
      }
    ]
  },
  "docs": [
    {
      "_index": "index",
      "_type": "type",
      "_id": "id",
      "_source": {
        "foo": null
      }
    }
  ]
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.