Conditional Execution in Pipelines

Each processor allows for an optional if condition to determine if that processor should be executed or skipped. The value of the if is a Painless script that needs to evaluate to true or false.

For example the following processor will drop the document (i.e. not index it) if the input document has a field named network_name and it is equal to Guest.

  1. PUT _ingest/pipeline/drop_guests_network
  2. {
  3. "processors": [
  4. {
  5. "drop": {
  6. "if": "ctx.network_name == 'Guest'"
  7. }
  8. }
  9. ]
  10. }

Using that pipeline for an index request:

  1. POST test/_doc/1?pipeline=drop_guests_network
  2. {
  3. "network_name" : "Guest"
  4. }

Results in nothing indexed since the conditional evaluated to true.

  1. {
  2. "_index": "test",
  3. "_type": "_doc",
  4. "_id": "1",
  5. "_version": -3,
  6. "result": "noop",
  7. "_shards": {
  8. "total": 0,
  9. "successful": 0,
  10. "failed": 0
  11. }
  12. }