|  | 
|  | 1 | +--- | 
|  | 2 | +layout: default | 
|  | 3 | +title: Fail | 
|  | 4 | +parent: Ingest processors | 
|  | 5 | +nav_order: 100 | 
|  | 6 | +--- | 
|  | 7 | + | 
|  | 8 | +# Fail processor | 
|  | 9 | + | 
|  | 10 | +The `fail` processor is useful for performing data transformation and enrichment during the indexing process. The primary use case for the `fail` processor is to fail an indexing operation when certain conditions are met. | 
|  | 11 | + | 
|  | 12 | +The following is the syntax for the `fail` processor: | 
|  | 13 | + | 
|  | 14 | +```json | 
|  | 15 | +"fail": {  | 
|  | 16 | +  "if": "ctx.foo == 'bar'",  | 
|  | 17 | +  "message": "Custom error message"  | 
|  | 18 | +  } | 
|  | 19 | +``` | 
|  | 20 | +{% include copy-curl.html %} | 
|  | 21 | + | 
|  | 22 | +## Configuration parameters | 
|  | 23 | + | 
|  | 24 | +The following table lists the required and optional parameters for the `fail` processor. | 
|  | 25 | + | 
|  | 26 | +Parameter | Required/Optional | Description | | 
|  | 27 | +|-----------|-----------|-----------| | 
|  | 28 | +`message` | Required | A custom error message to be included in the failure response. | 
|  | 29 | +`description`  | Optional  | A brief description of the processor.  |   | 
|  | 30 | +`if` | Optional | A condition for running the processor. |   | 
|  | 31 | +`ignore_failure` | Optional | Specifies whether the processor continues execution even if it encounters an error. If set to `true`, then failures are ignored. Default is `false`. |   | 
|  | 32 | +`on_failure` | Optional | A list of processors to run if the processor fails. |   | 
|  | 33 | +`tag` | Optional | An identifier tag for the processor. Useful for debugging in order to distinguish between processors of the same type. |   | 
|  | 34 | + | 
|  | 35 | +## Using the processor | 
|  | 36 | + | 
|  | 37 | +Follow these steps to use the processor in a pipeline. | 
|  | 38 | + | 
|  | 39 | +### Step 1: Create a pipeline | 
|  | 40 | + | 
|  | 41 | +The following query creates a pipeline, named `fail-log-pipeline`, that uses the `fail` processor to intentionally fail the pipeline execution for log events:  | 
|  | 42 | + | 
|  | 43 | +```json | 
|  | 44 | +PUT _ingest/pipeline/fail-log-pipeline   | 
|  | 45 | +{   | 
|  | 46 | +  "description": "A pipeline to test the fail processor for log events",   | 
|  | 47 | +  "processors": [   | 
|  | 48 | +    {   | 
|  | 49 | +      "fail": {   | 
|  | 50 | +        "if": "ctx.user_info.contains('password') || ctx.user_info.contains('credit card')",   | 
|  | 51 | +        "message": "Document containing personally identifiable information (PII) cannot be indexed!"   | 
|  | 52 | +      }   | 
|  | 53 | +    }   | 
|  | 54 | +  ]   | 
|  | 55 | +} | 
|  | 56 | +``` | 
|  | 57 | +{% include copy-curl.html %} | 
|  | 58 | + | 
|  | 59 | +### Step 2 (Optional): Test the pipeline | 
|  | 60 | + | 
|  | 61 | +It is recommended that you test your pipeline before you ingest documents. | 
|  | 62 | +{: .tip} | 
|  | 63 | + | 
|  | 64 | +To test the pipeline, run the following query: | 
|  | 65 | + | 
|  | 66 | +```json | 
|  | 67 | +POST _ingest/pipeline/fail-log-pipeline/_simulate   | 
|  | 68 | +{   | 
|  | 69 | +  "docs": [   | 
|  | 70 | +    {   | 
|  | 71 | +      "_source": {   | 
|  | 72 | +        "user_info": "Sensitive information including credit card"   | 
|  | 73 | +      }   | 
|  | 74 | +    }   | 
|  | 75 | +  ]   | 
|  | 76 | +}   | 
|  | 77 | +``` | 
|  | 78 | +{% include copy-curl.html %} | 
|  | 79 | + | 
|  | 80 | +#### Response | 
|  | 81 | + | 
|  | 82 | +The following example response confirms that the pipeline is working as expected: | 
|  | 83 | + | 
|  | 84 | +```json | 
|  | 85 | +{ | 
|  | 86 | +  "docs": [ | 
|  | 87 | +    { | 
|  | 88 | +      "error": { | 
|  | 89 | +        "root_cause": [ | 
|  | 90 | +          { | 
|  | 91 | +            "type": "fail_processor_exception", | 
|  | 92 | +            "reason": "Document containing personally identifiable information (PII) cannot be indexed!" | 
|  | 93 | +          } | 
|  | 94 | +        ], | 
|  | 95 | +        "type": "fail_processor_exception", | 
|  | 96 | +        "reason": "Document containing personally identifiable information (PII) cannot be indexed!" | 
|  | 97 | +      } | 
|  | 98 | +    } | 
|  | 99 | +  ] | 
|  | 100 | +} | 
|  | 101 | +``` | 
|  | 102 | +{% include copy-curl.html %} | 
|  | 103 | + | 
|  | 104 | +### Step 3: Ingest a document  | 
|  | 105 | + | 
|  | 106 | +The following query ingests a document into an index named `testindex1`: | 
|  | 107 | + | 
|  | 108 | +```json | 
|  | 109 | +PUT testindex1/_doc/1?pipeline=fail-log-pipeline   | 
|  | 110 | +{   | 
|  | 111 | +  "user_info": "Sensitive information including credit card"   | 
|  | 112 | +}  | 
|  | 113 | +``` | 
|  | 114 | +{% include copy-curl.html %} | 
|  | 115 | + | 
|  | 116 | +#### Response | 
|  | 117 | + | 
|  | 118 | +The request fails to index the log event into the index `testindex1` due to the string `credit card` being present in `user_info`. The following response includes the custom error message specified in the fail processor: | 
|  | 119 | + | 
|  | 120 | +```json | 
|  | 121 | + | 
|  | 122 | +  "error": { | 
|  | 123 | +    "root_cause": [ | 
|  | 124 | +      { | 
|  | 125 | +        "type": "fail_processor_exception", | 
|  | 126 | +        "reason": "Document containing personally identifiable information (PII) cannot be indexed!" | 
|  | 127 | +      } | 
|  | 128 | +    ], | 
|  | 129 | +    "type": "fail_processor_exception", | 
|  | 130 | +    "reason": "Document containing personally identifiable information (PII) cannot be indexed!" | 
|  | 131 | +  }, | 
|  | 132 | +  "status": 500 | 
|  | 133 | +} | 
|  | 134 | +``` | 
|  | 135 | +{% include copy-curl.html %} | 
|  | 136 | + | 
|  | 137 | +### Step 4 (Optional): Retrieve the document | 
|  | 138 | + | 
|  | 139 | +Because the log event was not indexed due to the pipeline failure, attempting to retrieve it results in the document not found error `"found": false`: | 
|  | 140 | + | 
|  | 141 | +```json | 
|  | 142 | +GET testindex1/_doc/1 | 
|  | 143 | +``` | 
|  | 144 | +{% include copy-curl.html %} | 
|  | 145 | + | 
|  | 146 | +#### Document error example | 
|  | 147 | + | 
|  | 148 | +```json | 
|  | 149 | +{   | 
|  | 150 | +  "_index": "testindex1",   | 
|  | 151 | +  "_id": "1",   | 
|  | 152 | +  "found": false   | 
|  | 153 | +}   | 
|  | 154 | +``` | 
0 commit comments