ingest-node.asciidoc 27 KB

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