ingest-node.asciidoc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. [[pipeline]]
  2. == Pipeline Definition
  3. A pipeline is a definition of a series of <<ingest-processors, processors>> that are to be executed
  4. in the same order as they are declared. A pipeline consists of two main fields: a `description`
  5. and a list of `processors`:
  6. [source,js]
  7. --------------------------------------------------
  8. {
  9. "description" : "...",
  10. "processors" : [ ... ]
  11. }
  12. --------------------------------------------------
  13. // NOTCONSOLE
  14. The `description` is a special field to store a helpful description of
  15. what the pipeline does.
  16. The `processors` parameter defines a list of processors to be executed in
  17. order.
  18. [[ingest-apis]]
  19. == Ingest APIs
  20. The following ingest APIs are available for managing pipelines:
  21. * <<put-pipeline-api>> to add or update a pipeline
  22. * <<get-pipeline-api>> to return a specific pipeline
  23. * <<delete-pipeline-api>> to delete a pipeline
  24. * <<simulate-pipeline-api>> to simulate a call to a pipeline
  25. include::apis/put-pipeline.asciidoc[]
  26. include::apis/get-pipeline.asciidoc[]
  27. include::apis/delete-pipeline.asciidoc[]
  28. include::apis/simulate-pipeline.asciidoc[]
  29. [[accessing-data-in-pipelines]]
  30. == Accessing Data in Pipelines
  31. The processors in a pipeline have read and write access to documents that pass through the pipeline.
  32. The processors can access fields in the source of a document and the document's metadata fields.
  33. [float]
  34. [[accessing-source-fields]]
  35. === Accessing Fields in the Source
  36. Accessing a field in the source is straightforward. You simply refer to fields by
  37. their name. For example:
  38. [source,js]
  39. --------------------------------------------------
  40. {
  41. "set": {
  42. "field": "my_field",
  43. "value": 582.1
  44. }
  45. }
  46. --------------------------------------------------
  47. // NOTCONSOLE
  48. On top of this, fields from the source are always accessible via the `_source` prefix:
  49. [source,js]
  50. --------------------------------------------------
  51. {
  52. "set": {
  53. "field": "_source.my_field",
  54. "value": 582.1
  55. }
  56. }
  57. --------------------------------------------------
  58. // NOTCONSOLE
  59. [float]
  60. [[accessing-metadata-fields]]
  61. === Accessing Metadata Fields
  62. You can access metadata fields in the same way that you access fields in the source. This
  63. is possible because Elasticsearch doesn't allow fields in the source that have the
  64. same name as metadata fields.
  65. The following example sets the `_id` metadata field of a document to `1`:
  66. [source,js]
  67. --------------------------------------------------
  68. {
  69. "set": {
  70. "field": "_id",
  71. "value": "1"
  72. }
  73. }
  74. --------------------------------------------------
  75. // NOTCONSOLE
  76. The following metadata fields are accessible by a processor: `_index`, `_type`, `_id`, `_routing`.
  77. [float]
  78. [[accessing-ingest-metadata]]
  79. === Accessing Ingest Metadata Fields
  80. Beyond metadata fields and source fields, ingest also adds ingest metadata to the documents that it processes.
  81. These metadata properties are accessible under the `_ingest` key. Currently ingest adds the ingest timestamp
  82. under the `_ingest.timestamp` key of the ingest metadata. The ingest timestamp is the time when Elasticsearch
  83. received the index or bulk request to pre-process the document.
  84. Any processor can add ingest-related metadata during document processing. Ingest metadata is transient
  85. and is lost after a document has been processed by the pipeline. Therefore, ingest metadata won't be indexed.
  86. The following example adds a field with the name `received`. The value is the ingest timestamp:
  87. [source,js]
  88. --------------------------------------------------
  89. {
  90. "set": {
  91. "field": "received",
  92. "value": "{{_ingest.timestamp}}"
  93. }
  94. }
  95. --------------------------------------------------
  96. // NOTCONSOLE
  97. Unlike Elasticsearch metadata fields, the ingest metadata field name `_ingest` can be used as a valid field name
  98. in the source of a document. Use `_source._ingest` to refer to the field in the source document. Otherwise, `_ingest`
  99. will be interpreted as an ingest metadata field.
  100. [float]
  101. [[accessing-template-fields]]
  102. === Accessing Fields and Metafields in Templates
  103. A number of processor settings also support templating. Settings that support templating can have zero or more
  104. template snippets. A template snippet begins with `{{` and ends with `}}`.
  105. Accessing fields and metafields in templates is exactly the same as via regular processor field settings.
  106. The following example adds a field named `field_c`. Its value is a concatenation of
  107. the values of `field_a` and `field_b`.
  108. [source,js]
  109. --------------------------------------------------
  110. {
  111. "set": {
  112. "field": "field_c",
  113. "value": "{{field_a}} {{field_b}}"
  114. }
  115. }
  116. --------------------------------------------------
  117. // NOTCONSOLE
  118. The following example uses the value of the `geoip.country_iso_code` field in the source
  119. to set the index that the document will be indexed into:
  120. [source,js]
  121. --------------------------------------------------
  122. {
  123. "set": {
  124. "field": "_index",
  125. "value": "{{geoip.country_iso_code}}"
  126. }
  127. }
  128. --------------------------------------------------
  129. // NOTCONSOLE
  130. Dynamic field names are also supported. This example sets the field named after the
  131. value of `service` to the value of the field `code`:
  132. [source,js]
  133. --------------------------------------------------
  134. {
  135. "set": {
  136. "field": "{{service}}",
  137. "value": "{{code}}"
  138. }
  139. }
  140. --------------------------------------------------
  141. // NOTCONSOLE
  142. [[ingest-conditionals]]
  143. == Conditional Execution in Pipelines
  144. Each processor allows for an optional `if` condition to determine if that
  145. processor should be executed or skipped. The value of the `if` is a
  146. <<modules-scripting-painless, Painless>> script that needs to evaluate
  147. to `true` or `false`.
  148. For example the following processor will <<drop-processor,drop>> the document
  149. (i.e. not index it) if the input document has a field named `network_name`
  150. and it is equal to `Guest`.
  151. [source,js]
  152. --------------------------------------------------
  153. PUT _ingest/pipeline/drop_guests_network
  154. {
  155. "processors": [
  156. {
  157. "drop": {
  158. "if": "ctx.network_name == 'Guest'"
  159. }
  160. }
  161. ]
  162. }
  163. --------------------------------------------------
  164. // CONSOLE
  165. Using that pipeline for an index request:
  166. [source,js]
  167. --------------------------------------------------
  168. POST test/_doc/1?pipeline=drop_guests_network
  169. {
  170. "network_name" : "Guest"
  171. }
  172. --------------------------------------------------
  173. // CONSOLE
  174. // TEST[continued]
  175. Results in nothing indexed since the conditional evaluated to `true`.
  176. [source,js]
  177. --------------------------------------------------
  178. {
  179. "_index": "test",
  180. "_type": "_doc",
  181. "_id": "1",
  182. "_version": -3,
  183. "result": "noop",
  184. "_shards": {
  185. "total": 0,
  186. "successful": 0,
  187. "failed": 0
  188. }
  189. }
  190. --------------------------------------------------
  191. // TESTRESPONSE
  192. [[ingest-conditional-nullcheck]]
  193. === Handling Nested Fields in Conditionals
  194. Source documents often contain nested fields. Care should be taken
  195. to avoid NullPointerExceptions if the parent object does not exist
  196. in the document. For example `ctx.a.b.c` can throw an NullPointerExceptions
  197. if the source document does not have top level `a` object, or a second
  198. level `b` object.
  199. To help protect against NullPointerExceptions, null safe operations should be used.
  200. Fortunately, Painless makes {painless}/painless-operators-reference.html#null-safe-operator[null safe]
  201. operations easy with the `?.` operator.
  202. [source,js]
  203. --------------------------------------------------
  204. PUT _ingest/pipeline/drop_guests_network
  205. {
  206. "processors": [
  207. {
  208. "drop": {
  209. "if": "ctx.network?.name == 'Guest'"
  210. }
  211. }
  212. ]
  213. }
  214. --------------------------------------------------
  215. // CONSOLE
  216. The following document will get <<drop-processor,dropped>> correctly:
  217. [source,js]
  218. --------------------------------------------------
  219. POST test/_doc/1?pipeline=drop_guests_network
  220. {
  221. "network": {
  222. "name": "Guest"
  223. }
  224. }
  225. --------------------------------------------------
  226. // CONSOLE
  227. // TEST[continued]
  228. Thanks to the `?.` operator the following document will not throw an error.
  229. If the pipeline used a `.` the following document would throw a NullPointerException
  230. since the `network` object is not part of the source document.
  231. [source,js]
  232. --------------------------------------------------
  233. POST test/_doc/2?pipeline=drop_guests_network
  234. {
  235. "foo" : "bar"
  236. }
  237. --------------------------------------------------
  238. // CONSOLE
  239. // TEST[continued]
  240. ////
  241. Hidden example assertion:
  242. [source,js]
  243. --------------------------------------------------
  244. GET test/_doc/2
  245. --------------------------------------------------
  246. // CONSOLE
  247. // TEST[continued]
  248. [source,js]
  249. --------------------------------------------------
  250. {
  251. "_index": "test",
  252. "_type": "_doc",
  253. "_id": "2",
  254. "_version": 1,
  255. "_seq_no": 22,
  256. "_primary_term": 1,
  257. "found": true,
  258. "_source": {
  259. "foo": "bar"
  260. }
  261. }
  262. --------------------------------------------------
  263. // TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term": 1/"_primary_term" : $body._primary_term/]
  264. ////
  265. The source document can also use dot delimited fields to represent nested fields.
  266. For example instead the source document defining the fields nested:
  267. [source,js]
  268. --------------------------------------------------
  269. {
  270. "network": {
  271. "name": "Guest"
  272. }
  273. }
  274. --------------------------------------------------
  275. // NOTCONSOLE
  276. The source document may have the nested fields flattened as such:
  277. [source,js]
  278. --------------------------------------------------
  279. {
  280. "network.name": "Guest"
  281. }
  282. --------------------------------------------------
  283. // NOTCONSOLE
  284. If this is the case, use the <<dot-expand-processor, Dot Expand Processor>>
  285. so that the nested fields may be used in a conditional.
  286. [source,js]
  287. --------------------------------------------------
  288. PUT _ingest/pipeline/drop_guests_network
  289. {
  290. "processors": [
  291. {
  292. "dot_expander": {
  293. "field": "network.name"
  294. }
  295. },
  296. {
  297. "drop": {
  298. "if": "ctx.network?.name == 'Guest'"
  299. }
  300. }
  301. ]
  302. }
  303. --------------------------------------------------
  304. // CONSOLE
  305. Now the following input document can be used with a conditional in the pipeline.
  306. [source,js]
  307. --------------------------------------------------
  308. POST test/_doc/3?pipeline=drop_guests_network
  309. {
  310. "network.name": "Guest"
  311. }
  312. --------------------------------------------------
  313. // CONSOLE
  314. // TEST[continued]
  315. The `?.` operators works well for use in the `if` conditional
  316. because the {painless}/painless-operators-reference.html#null-safe-operator[null safe operator]
  317. returns null if the object is null and `==` is null safe (as well as many other
  318. {painless}/painless-operators.html[painless operators]).
  319. However, calling a method such as `.equalsIgnoreCase` is not null safe
  320. and can result in a NullPointerException.
  321. Some situations allow for the same functionality but done so in a null safe manner.
  322. For example: `'Guest'.equalsIgnoreCase(ctx.network?.name)` is null safe because
  323. `Guest` is always non null, but `ctx.network?.name.equalsIgnoreCase('Guest')` is not null safe
  324. since `ctx.network?.name` can return null.
  325. Some situations require an explicit null check. In the following example there
  326. is not null safe alternative, so an explicit null check is needed.
  327. [source,js]
  328. --------------------------------------------------
  329. {
  330. "drop": {
  331. "if": "ctx.network?.name != null && ctx.network.name.contains('Guest')"
  332. }
  333. }
  334. --------------------------------------------------
  335. // NOTCONSOLE
  336. [[ingest-conditional-complex]]
  337. === Complex Conditionals
  338. The `if` condition can be more then a simple equality check.
  339. The full power of the <<modules-scripting-painless, Painless Scripting Language>> is available and
  340. running in the {painless}/painless-ingest-processor-context.html[ingest processor context].
  341. IMPORTANT: The value of ctx is read-only in `if` conditions.
  342. A more complex `if` condition that drops the document (i.e. not index it)
  343. unless it has a multi-valued tag field with at least one value that contains the characters
  344. `prod` (case insensitive).
  345. [source,js]
  346. --------------------------------------------------
  347. PUT _ingest/pipeline/not_prod_dropper
  348. {
  349. "processors": [
  350. {
  351. "drop": {
  352. "if": "Collection tags = ctx.tags;if(tags != null){for (String tag : tags) {if (tag.toLowerCase().contains('prod')) { return false;}}} return true;"
  353. }
  354. }
  355. ]
  356. }
  357. --------------------------------------------------
  358. // CONSOLE
  359. The conditional needs to be all on one line since JSON does not
  360. support new line characters. However, Kibana's console supports
  361. a triple quote syntax to help with writing and debugging
  362. scripts like these.
  363. [source,js]
  364. --------------------------------------------------
  365. PUT _ingest/pipeline/not_prod_dropper
  366. {
  367. "processors": [
  368. {
  369. "drop": {
  370. "if": """
  371. Collection tags = ctx.tags;
  372. if(tags != null){
  373. for (String tag : tags) {
  374. if (tag.toLowerCase().contains('prod')) {
  375. return false;
  376. }
  377. }
  378. }
  379. return true;
  380. """
  381. }
  382. }
  383. ]
  384. }
  385. --------------------------------------------------
  386. // NOTCONSOLE
  387. // TEST[continued]
  388. [source,js]
  389. --------------------------------------------------
  390. POST test/_doc/1?pipeline=not_prod_dropper
  391. {
  392. "tags": ["application:myapp", "env:Stage"]
  393. }
  394. --------------------------------------------------
  395. // CONSOLE
  396. // TEST[continued]
  397. The document is <<drop-processor,dropped>> since `prod` (case insensitive)
  398. is not found in the tags.
  399. The following document is indexed (i.e. not dropped) since
  400. `prod` (case insensitive) is found in the tags.
  401. [source,js]
  402. --------------------------------------------------
  403. POST test/_doc/2?pipeline=not_prod_dropper
  404. {
  405. "tags": ["application:myapp", "env:Production"]
  406. }
  407. --------------------------------------------------
  408. // CONSOLE
  409. // TEST[continued]
  410. ////
  411. Hidden example assertion:
  412. [source,js]
  413. --------------------------------------------------
  414. GET test/_doc/2
  415. --------------------------------------------------
  416. // CONSOLE
  417. // TEST[continued]
  418. [source,js]
  419. --------------------------------------------------
  420. {
  421. "_index": "test",
  422. "_type": "_doc",
  423. "_id": "2",
  424. "_version": 1,
  425. "_seq_no": 34,
  426. "_primary_term": 1,
  427. "found": true,
  428. "_source": {
  429. "tags": [
  430. "application:myapp",
  431. "env:Production"
  432. ]
  433. }
  434. }
  435. --------------------------------------------------
  436. // TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
  437. ////
  438. The <<simulate-pipeline-api>> with verbose can be used to help build out
  439. complex conditionals. If the conditional evaluates to false it will be
  440. omitted from the verbose results of the simulation since the document will not change.
  441. Care should be taken to avoid overly complex or expensive conditional checks
  442. since the condition needs to be checked for each and every document.
  443. [[conditionals-with-multiple-pipelines]]
  444. === Conditionals with the Pipeline Processor
  445. The combination of the `if` conditional and the <<pipeline-processor>> can result in a simple,
  446. yet powerful means to process heterogeneous input. For example, you can define a single pipeline
  447. that delegates to other pipelines based on some criteria.
  448. [source,js]
  449. --------------------------------------------------
  450. PUT _ingest/pipeline/logs_pipeline
  451. {
  452. "description": "A pipeline of pipelines for log files",
  453. "version": 1,
  454. "processors": [
  455. {
  456. "pipeline": {
  457. "if": "ctx.service?.name == 'apache_httpd'",
  458. "name": "httpd_pipeline"
  459. }
  460. },
  461. {
  462. "pipeline": {
  463. "if": "ctx.service?.name == 'syslog'",
  464. "name": "syslog_pipeline"
  465. }
  466. },
  467. {
  468. "fail": {
  469. "message": "This pipeline requires service.name to be either `syslog` or `apache_httpd`"
  470. }
  471. }
  472. ]
  473. }
  474. --------------------------------------------------
  475. // CONSOLE
  476. The above example allows consumers to point to a single pipeline for all log based index requests.
  477. Based on the conditional, the correct pipeline will be called to process that type of data.
  478. This pattern works well with a <<dynamic-index-settings, default pipeline>> defined in an index mapping
  479. template for all indexes that hold data that needs pre-index processing.
  480. [[conditionals-with-regex]]
  481. === Conditionals with the Regular Expressions
  482. The `if` conditional is implemented as a Painless script, which requires
  483. {painless}//painless-regexes.html[explicit support for regular expressions].
  484. `script.painless.regex.enabled: true` must be set in `elasticsearch.yml` to use regular
  485. expressions in the `if` condition.
  486. If regular expressions are enabled, operators such as `=~` can be used against a `/pattern/` for conditions.
  487. For example:
  488. [source,js]
  489. --------------------------------------------------
  490. PUT _ingest/pipeline/check_url
  491. {
  492. "processors": [
  493. {
  494. "set": {
  495. "if": "ctx.href?.url =~ /^http[^s]/",
  496. "field": "href.insecure",
  497. "value": true
  498. }
  499. }
  500. ]
  501. }
  502. --------------------------------------------------
  503. // CONSOLE
  504. [source,js]
  505. --------------------------------------------------
  506. POST test/_doc/1?pipeline=check_url
  507. {
  508. "href": {
  509. "url": "http://www.elastic.co/"
  510. }
  511. }
  512. --------------------------------------------------
  513. // CONSOLE
  514. // TEST[continued]
  515. Results in:
  516. ////
  517. Hidden example assertion:
  518. [source,js]
  519. --------------------------------------------------
  520. GET test/_doc/1
  521. --------------------------------------------------
  522. // CONSOLE
  523. // TEST[continued]
  524. ////
  525. [source,js]
  526. --------------------------------------------------
  527. {
  528. "_index": "test",
  529. "_type": "_doc",
  530. "_id": "1",
  531. "_version": 1,
  532. "_seq_no": 60,
  533. "_primary_term": 1,
  534. "found": true,
  535. "_source": {
  536. "href": {
  537. "insecure": true,
  538. "url": "http://www.elastic.co/"
  539. }
  540. }
  541. }
  542. --------------------------------------------------
  543. // TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
  544. Regular expressions can be expensive and should be avoided if viable
  545. alternatives exist.
  546. For example in this case `startsWith` can be used to get the same result
  547. without using a regular expression:
  548. [source,js]
  549. --------------------------------------------------
  550. PUT _ingest/pipeline/check_url
  551. {
  552. "processors": [
  553. {
  554. "set": {
  555. "if": "ctx.href?.url != null && ctx.href.url.startsWith('http://')",
  556. "field": "href.insecure",
  557. "value": true
  558. }
  559. }
  560. ]
  561. }
  562. --------------------------------------------------
  563. // CONSOLE
  564. [[handling-failure-in-pipelines]]
  565. == Handling Failures in Pipelines
  566. In its simplest use case, a pipeline defines a list of processors that
  567. are executed sequentially, and processing halts at the first exception. This
  568. behavior may not be desirable when failures are expected. For example, you may have logs
  569. that don't match the specified grok expression. Instead of halting execution, you may
  570. want to index such documents into a separate index.
  571. To enable this behavior, you can use the `on_failure` parameter. The `on_failure` parameter
  572. defines a list of processors to be executed immediately following the failed processor.
  573. You can specify this parameter at the pipeline level, as well as at the processor
  574. level. If a processor specifies an `on_failure` configuration, whether
  575. it is empty or not, any exceptions that are thrown by the processor are caught, and the
  576. pipeline continues executing the remaining processors. Because you can define further processors
  577. within the scope of an `on_failure` statement, you can nest failure handling.
  578. The following example defines a pipeline that renames the `foo` field in
  579. the processed document to `bar`. If the document does not contain the `foo` field, the processor
  580. attaches an error message to the document for later analysis within
  581. Elasticsearch.
  582. [source,js]
  583. --------------------------------------------------
  584. {
  585. "description" : "my first pipeline with handled exceptions",
  586. "processors" : [
  587. {
  588. "rename" : {
  589. "field" : "foo",
  590. "target_field" : "bar",
  591. "on_failure" : [
  592. {
  593. "set" : {
  594. "field" : "error",
  595. "value" : "field \"foo\" does not exist, cannot rename to \"bar\""
  596. }
  597. }
  598. ]
  599. }
  600. }
  601. ]
  602. }
  603. --------------------------------------------------
  604. // NOTCONSOLE
  605. The following example defines an `on_failure` block on a whole pipeline to change
  606. the index to which failed documents get sent.
  607. [source,js]
  608. --------------------------------------------------
  609. {
  610. "description" : "my first pipeline with handled exceptions",
  611. "processors" : [ ... ],
  612. "on_failure" : [
  613. {
  614. "set" : {
  615. "field" : "_index",
  616. "value" : "failed-{{ _index }}"
  617. }
  618. }
  619. ]
  620. }
  621. --------------------------------------------------
  622. // NOTCONSOLE
  623. Alternatively instead of defining behaviour in case of processor failure, it is also possible
  624. to ignore a failure and continue with the next processor by specifying the `ignore_failure` setting.
  625. In case in the example below the field `foo` doesn't exist the failure will be caught and the pipeline
  626. continues to execute, which in this case means that the pipeline does nothing.
  627. [source,js]
  628. --------------------------------------------------
  629. {
  630. "description" : "my first pipeline with handled exceptions",
  631. "processors" : [
  632. {
  633. "rename" : {
  634. "field" : "foo",
  635. "target_field" : "bar",
  636. "ignore_failure" : true
  637. }
  638. }
  639. ]
  640. }
  641. --------------------------------------------------
  642. // NOTCONSOLE
  643. The `ignore_failure` can be set on any processor and defaults to `false`.
  644. [float]
  645. [[accessing-error-metadata]]
  646. === Accessing Error Metadata From Processors Handling Exceptions
  647. You may want to retrieve the actual error message that was thrown
  648. by a failed processor. To do so you can access metadata fields called
  649. `on_failure_message`, `on_failure_processor_type`, and `on_failure_processor_tag`. These fields are only accessible
  650. from within the context of an `on_failure` block.
  651. Here is an updated version of the example that you
  652. saw earlier. But instead of setting the error message manually, the example leverages the `on_failure_message`
  653. metadata field to provide the error message.
  654. [source,js]
  655. --------------------------------------------------
  656. {
  657. "description" : "my first pipeline with handled exceptions",
  658. "processors" : [
  659. {
  660. "rename" : {
  661. "field" : "foo",
  662. "to" : "bar",
  663. "on_failure" : [
  664. {
  665. "set" : {
  666. "field" : "error",
  667. "value" : "{{ _ingest.on_failure_message }}"
  668. }
  669. }
  670. ]
  671. }
  672. }
  673. ]
  674. }
  675. --------------------------------------------------
  676. // NOTCONSOLE
  677. [[ingest-processors]]
  678. == Processors
  679. All processors are defined in the following way within a pipeline definition:
  680. [source,js]
  681. --------------------------------------------------
  682. {
  683. "PROCESSOR_NAME" : {
  684. ... processor configuration options ...
  685. }
  686. }
  687. --------------------------------------------------
  688. // NOTCONSOLE
  689. Each processor defines its own configuration parameters, but all processors have
  690. the ability to declare `tag`, `on_failure` and `if` fields. These fields are optional.
  691. A `tag` is simply a string identifier of the specific instantiation of a certain
  692. processor in a pipeline. The `tag` field does not affect the processor's behavior,
  693. but is very useful for bookkeeping and tracing errors to specific processors.
  694. The `if` field must contain a script that returns a boolean value. If the script evaluates to `true`
  695. then the processor will be executed for the given document otherwise it will be skipped.
  696. The `if` field takes an object with the script fields defined in <<script-processor, script-options>>
  697. and accesses a read only version of the document via the same `ctx` variable used by scripts in the
  698. <<script-processor>>.
  699. [source,js]
  700. --------------------------------------------------
  701. {
  702. "set": {
  703. "if": "ctx.foo == 'someValue'",
  704. "field": "found",
  705. "value": true
  706. }
  707. }
  708. --------------------------------------------------
  709. // NOTCONSOLE
  710. See <<ingest-conditionals>> to learn more about the `if` field and conditional execution.
  711. See <<handling-failure-in-pipelines>> to learn more about the `on_failure` field and error handling in pipelines.
  712. The <<ingest-info,node info API>> can be used to figure out what processors are available in a cluster.
  713. The <<ingest-info,node info API>> will provide a per node list of what processors are available.
  714. Custom processors must be installed on all nodes. The put pipeline API will fail if a processor specified in a pipeline
  715. doesn't exist on all nodes. If you rely on custom processor plugins make sure to mark these plugins as mandatory by adding
  716. `plugin.mandatory` setting to the `config/elasticsearch.yml` file, for example:
  717. [source,yaml]
  718. --------------------------------------------------
  719. plugin.mandatory: ingest-attachment
  720. --------------------------------------------------
  721. A node will not start if this plugin is not available.
  722. The <<ingest-stats,node stats API>> can be used to fetch ingest usage statistics, globally and on a per
  723. pipeline basis. Useful to find out which pipelines are used the most or spent the most time on preprocessing.
  724. [float]
  725. === Ingest Processor Plugins
  726. Additional ingest processors can be implemented and installed as Elasticsearch {plugins}/intro.html[plugins].
  727. See {plugins}/ingest.html[Ingest plugins] for information about the available ingest plugins.
  728. include::processors/append.asciidoc[]
  729. include::processors/bytes.asciidoc[]
  730. include::processors/convert.asciidoc[]
  731. include::processors/date.asciidoc[]
  732. include::processors/date-index-name.asciidoc[]
  733. include::processors/dissect.asciidoc[]
  734. include::processors/dot-expand.asciidoc[]
  735. include::processors/drop.asciidoc[]
  736. include::processors/fail.asciidoc[]
  737. include::processors/foreach.asciidoc[]
  738. include::processors/geoip.asciidoc[]
  739. include::processors/grok.asciidoc[]
  740. include::processors/gsub.asciidoc[]
  741. include::processors/html_strip.asciidoc[]
  742. include::processors/join.asciidoc[]
  743. include::processors/json.asciidoc[]
  744. include::processors/kv.asciidoc[]
  745. include::processors/pipeline.asciidoc[]
  746. include::processors/remove.asciidoc[]
  747. include::processors/rename.asciidoc[]
  748. include::processors/script.asciidoc[]
  749. include::processors/set.asciidoc[]
  750. include::processors/set-security-user.asciidoc[]
  751. include::processors/split.asciidoc[]
  752. include::processors/sort.asciidoc[]
  753. include::processors/trim.asciidoc[]
  754. include::processors/uppercase.asciidoc[]
  755. include::processors/url-decode.asciidoc[]
  756. include::processors/user-agent.asciidoc[]