ingest-node.asciidoc 26 KB

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