原文地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/ingest-conditionals.html, 原文档版权归 www.elastic.co 所有

Conditional Execution in Pipelinesedit

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.

PUT _ingest/pipeline/drop_guests_network
{
  "processors": [
    {
      "drop": {
        "if": "ctx.network_name == 'Guest'"
      }
    }
  ]
}

Using that pipeline for an index request:

POST test/_doc/1?pipeline=drop_guests_network
{
  "network_name" : "Guest"
}

Results in nothing indexed since the conditional evaluated to true.

{
  "_index": "test",
  "_type": "_doc",
  "_id": "1",
  "_version": -3,
  "result": "noop",
  "_shards": {
    "total": 0,
    "successful": 0,
    "failed": 0
  }
}