ingest.asciidoc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. [[ingest]]
  2. = Ingest pipelines
  3. Ingest pipelines let you perform common transformations on your data before
  4. indexing. For example, you can use pipelines to remove fields, extract values
  5. from text, and enrich your data.
  6. A pipeline consists of a series of configurable tasks called
  7. <<processors,processors>>. Each processor runs sequentially, making specific
  8. changes to incoming documents. After the processors have run, {es} adds the
  9. transformed documents to your data stream or index.
  10. image::images/ingest/ingest-process.svg[Ingest pipeline diagram,align="center"]
  11. You can create and manage ingest pipelines using {kib}'s **Ingest Pipelines**
  12. feature or the <<ingest-apis,ingest APIs>>. {es} stores pipelines in the
  13. <<cluster-state,cluster state>>.
  14. [discrete]
  15. [[ingest-prerequisites]]
  16. === Prerequisites
  17. * Nodes with the <<node-ingest-node,`ingest`>> node role handle pipeline
  18. processing. To use ingest pipelines, your cluster must have at least one node
  19. with the `ingest` role. For heavy ingest loads, we recommend creating
  20. <<node-ingest-node,dedicated ingest nodes>>.
  21. * If the {es} security features are enabled, you must have the `manage_pipeline`
  22. <<privileges-list-cluster,cluster privilege>> to manage ingest pipelines. To use
  23. {kib}'s **Ingest Pipelines** feature, you also need the
  24. `cluster:monitor/nodes/info` cluster privileges.
  25. * Pipelines including the `enrich` processor require additional setup. See
  26. <<ingest-enriching-data>>.
  27. [discrete]
  28. [[create-manage-ingest-pipelines]]
  29. === Create and manage pipelines
  30. In {kib}, open the main menu and click **Stack Management > Ingest
  31. Pipelines**. From the list view, you can:
  32. * View a list of your pipelines and drill down into details
  33. * Edit or clone existing pipelines
  34. * Delete pipelines
  35. [role="screenshot"]
  36. image::images/ingest/ingest-pipeline-list.png[Kibana's Ingest Pipelines list view,align="center"]
  37. To create a pipeline, click **Create pipeline > New pipeline**. For an example
  38. tutorial, see <<common-log-format-example>>.
  39. TIP: The **New pipeline from CSV** option lets you use a CSV to create an ingest
  40. pipeline that maps custom data to the {ecs-ref}[Elastic Common Schema (ECS)].
  41. Mapping your custom data to ECS makes the data easier to search and lets you
  42. reuse visualizations from other datasets. To get started, check
  43. {ecs-ref}/ecs-converting.html[Map custom data to ECS].
  44. You can also use the <<ingest-apis,ingest APIs>> to create and manage pipelines.
  45. The following <<put-pipeline-api,create pipeline API>> request creates
  46. a pipeline containing two <<set-processor,`set`>> processors followed by a
  47. <<lowercase-processor,`lowercase`>> processor. The processors run sequentially
  48. in the order specified.
  49. [source,console]
  50. ----
  51. PUT _ingest/pipeline/my-pipeline
  52. {
  53. "description": "My optional pipeline description",
  54. "processors": [
  55. {
  56. "set": {
  57. "description": "My optional processor description",
  58. "field": "my-long-field",
  59. "value": 10
  60. }
  61. },
  62. {
  63. "set": {
  64. "description": "Set 'my-boolean-field' to true",
  65. "field": "my-boolean-field",
  66. "value": true
  67. }
  68. },
  69. {
  70. "lowercase": {
  71. "field": "my-keyword-field"
  72. }
  73. }
  74. ]
  75. }
  76. ----
  77. // TESTSETUP
  78. [discrete]
  79. [[manage-pipeline-versions]]
  80. === Manage pipeline versions
  81. When you create or update a pipeline, you can specify an optional `version`
  82. integer. You can use this version number with the
  83. <<put-pipeline-api-query-params,`if_version`>> parameter to conditionally
  84. update the pipeline. When the `if_version` parameter is specified, a successful
  85. update increments the pipeline's version.
  86. [source,console]
  87. ----
  88. PUT _ingest/pipeline/my-pipeline-id
  89. {
  90. "version": 1,
  91. "processors": [ ... ]
  92. }
  93. ----
  94. // TEST[s/\.\.\./{"lowercase": {"field":"my-keyword-field"}}/]
  95. To unset the `version` number using the API, replace or update the pipeline
  96. without specifying the `version` parameter.
  97. [discrete]
  98. [[test-pipeline]]
  99. === Test a pipeline
  100. Before using a pipeline in production, we recommend you test it using sample
  101. documents. When creating or editing a pipeline in {kib}, click **Add
  102. documents**. In the **Documents** tab, provide sample documents and click **Run
  103. the pipeline**.
  104. [role="screenshot"]
  105. image::images/ingest/test-a-pipeline.png[Test a pipeline in Kibana,align="center"]
  106. You can also test pipelines using the <<simulate-pipeline-api,simulate pipeline
  107. API>>. You can specify a configured pipeline in the request path. For example,
  108. the following request tests `my-pipeline`.
  109. [source,console]
  110. ----
  111. POST _ingest/pipeline/my-pipeline/_simulate
  112. {
  113. "docs": [
  114. {
  115. "_source": {
  116. "my-keyword-field": "FOO"
  117. }
  118. },
  119. {
  120. "_source": {
  121. "my-keyword-field": "BAR"
  122. }
  123. }
  124. ]
  125. }
  126. ----
  127. Alternatively, you can specify a pipeline and its processors in the request
  128. body.
  129. [source,console]
  130. ----
  131. POST _ingest/pipeline/_simulate
  132. {
  133. "pipeline": {
  134. "processors": [
  135. {
  136. "lowercase": {
  137. "field": "my-keyword-field"
  138. }
  139. }
  140. ]
  141. },
  142. "docs": [
  143. {
  144. "_source": {
  145. "my-keyword-field": "FOO"
  146. }
  147. },
  148. {
  149. "_source": {
  150. "my-keyword-field": "BAR"
  151. }
  152. }
  153. ]
  154. }
  155. ----
  156. The API returns transformed documents:
  157. [source,console-result]
  158. ----
  159. {
  160. "docs": [
  161. {
  162. "doc": {
  163. "_index": "_index",
  164. "_id": "_id",
  165. "_source": {
  166. "my-keyword-field": "foo"
  167. },
  168. "_ingest": {
  169. "timestamp": "2099-03-07T11:04:03.000Z"
  170. }
  171. }
  172. },
  173. {
  174. "doc": {
  175. "_index": "_index",
  176. "_id": "_id",
  177. "_source": {
  178. "my-keyword-field": "bar"
  179. },
  180. "_ingest": {
  181. "timestamp": "2099-03-07T11:04:04.000Z"
  182. }
  183. }
  184. }
  185. ]
  186. }
  187. ----
  188. // TESTRESPONSE[s/"2099-03-07T11:04:03.000Z"/$body.docs.0.doc._ingest.timestamp/]
  189. // TESTRESPONSE[s/"2099-03-07T11:04:04.000Z"/$body.docs.1.doc._ingest.timestamp/]
  190. [discrete]
  191. [[add-pipeline-to-indexing-request]]
  192. === Add a pipeline to an indexing request
  193. Use the `pipeline` query parameter to apply a pipeline to documents in
  194. <<docs-index_,individual>> or <<docs-bulk,bulk>> indexing requests.
  195. [source,console]
  196. ----
  197. POST my-data-stream/_doc?pipeline=my-pipeline
  198. {
  199. "@timestamp": "2099-03-07T11:04:05.000Z",
  200. "my-keyword-field": "foo"
  201. }
  202. PUT my-data-stream/_bulk?pipeline=my-pipeline
  203. { "create":{ } }
  204. { "@timestamp": "2099-03-07T11:04:06.000Z", "my-keyword-field": "foo" }
  205. { "create":{ } }
  206. { "@timestamp": "2099-03-07T11:04:07.000Z", "my-keyword-field": "bar" }
  207. ----
  208. // TEST[setup:my_data_stream]
  209. // TEST[teardown:data_stream_cleanup]
  210. You can also use the `pipeline` parameter with the <<docs-update-by-query,update
  211. by query>> or <<docs-reindex,reindex>> APIs.
  212. [source,console]
  213. ----
  214. POST my-data-stream/_update_by_query?pipeline=my-pipeline
  215. POST _reindex
  216. {
  217. "source": {
  218. "index": "my-data-stream"
  219. },
  220. "dest": {
  221. "index": "my-new-data-stream",
  222. "op_type": "create",
  223. "pipeline": "my-pipeline"
  224. }
  225. }
  226. ----
  227. // TEST[setup:my_data_stream]
  228. // TEST[teardown:data_stream_cleanup]
  229. [discrete]
  230. [[set-default-pipeline]]
  231. === Set a default pipeline
  232. Use the <<index-default-pipeline,`index.default_pipeline`>> index setting to set
  233. a default pipeline. {es} applies this pipeline to indexing requests if no
  234. `pipeline` parameter is specified.
  235. [discrete]
  236. [[set-final-pipeline]]
  237. === Set a final pipeline
  238. Use the <<index-final-pipeline,`index.final_pipeline`>> index setting to set a
  239. final pipeline. {es} applies this pipeline after the request or default
  240. pipeline, even if neither is specified.
  241. [discrete]
  242. [[pipelines-for-beats]]
  243. === Pipelines for {beats}
  244. To add an ingest pipeline to an Elastic Beat, specify the `pipeline`
  245. parameter under `output.elasticsearch` in `<BEAT_NAME>.yml`. For example,
  246. for {filebeat}, you'd specify `pipeline` in `filebeat.yml`.
  247. [source,yaml]
  248. ----
  249. output.elasticsearch:
  250. hosts: ["localhost:9200"]
  251. pipeline: my-pipeline
  252. ----
  253. [discrete]
  254. [[pipelines-for-fleet-elastic-agent]]
  255. === Pipelines for {fleet} and {agent}
  256. {fleet-guide}/index.html[{fleet}] automatically adds ingest pipelines for its
  257. integrations. {fleet} applies these pipelines using <<index-templates,index
  258. templates>> that include <<set-default-pipeline,pipeline index settings>>. {es}
  259. matches these templates to your {fleet} data streams based on the
  260. {fleet-guide}/data-streams.html#data-streams-naming-scheme[stream's naming
  261. scheme].
  262. WARNING: Do not change {fleet}'s ingest pipelines or use custom pipelines for
  263. your {fleet} integrations. Doing so can break your {fleet} data streams.
  264. {fleet} doesn't provide an ingest pipeline for the **Custom logs** integration.
  265. You can safely specify a pipeline for this integration in one of two ways: an
  266. <<pipeline-custom-logs-index-template,index template>> or a
  267. <<pipeline-custom-logs-configuration,custom configuration>>.
  268. [[pipeline-custom-logs-index-template]]
  269. **Option 1: Index template**
  270. // tag::create-name-custom-logs-pipeline[]
  271. . <<create-manage-ingest-pipelines,Create>> and <<test-pipeline,test>> your
  272. ingest pipeline. Name your pipeline `logs-<dataset-name>-default`. This makes
  273. tracking the pipeline for your integration easier.
  274. +
  275. --
  276. For example, the following request creates a pipeline for the `my-app` dataset.
  277. The pipeline's name is `logs-my_app-default`.
  278. [source,console]
  279. ----
  280. PUT _ingest/pipeline/logs-my_app-default
  281. {
  282. "description": "Pipeline for `my_app` dataset",
  283. "processors": [ ... ]
  284. }
  285. ----
  286. // TEST[s/\.\.\./{"lowercase": {"field":"my-keyword-field"}}/]
  287. --
  288. // end::create-name-custom-logs-pipeline[]
  289. . Create an <<index-templates,index template>> that includes your pipeline in
  290. the <<index-default-pipeline,`index.default_pipeline`>> or
  291. <<index-final-pipeline,`index.final_pipeline`>> index setting. Ensure the
  292. template is <<create-index-template,data stream enabled>>. The
  293. template's index pattern should match `logs-<dataset-name>-*`.
  294. +
  295. --
  296. You can create this template using {kib}'s <<manage-index-templates,**Index
  297. Management**>> feature or the <<indices-put-template,create index template
  298. API>>.
  299. For example, the following request creates a template matching `logs-my_app-*`.
  300. The template uses a component template that contains the
  301. `index.default_pipeline` index setting.
  302. [source,console]
  303. ----
  304. # Creates a component template for index settings
  305. PUT _component_template/logs-my_app-settings
  306. {
  307. "template": {
  308. "settings": {
  309. "index.default_pipeline": "logs-my_app-default",
  310. "index.lifecycle.name": "logs"
  311. }
  312. }
  313. }
  314. # Creates an index template matching `logs-my_app-*`
  315. PUT _index_template/logs-my_app-template
  316. {
  317. "index_patterns": ["logs-my_app-*"],
  318. "data_stream": { },
  319. "priority": 500,
  320. "composed_of": ["logs-my_app-settings", "logs-my_app-mappings"]
  321. }
  322. ----
  323. // TEST[continued]
  324. // TEST[s/, "logs-my_app-mappings"//]
  325. --
  326. // tag::name-custom-logs-dataset[]
  327. . When adding or editing your **Custom logs** integration in {fleet},
  328. click **Configure integration > Custom log file > Advanced options**.
  329. . In **Dataset name**, specify your dataset's name. {fleet} will add new data
  330. for the integration to the resulting `logs-<dataset-name>-default` data stream.
  331. +
  332. For example, if your dataset's name was `my_app`, {fleet} adds new data to the
  333. `logs-my_app-default` data stream.
  334. // end::name-custom-logs-dataset[]
  335. +
  336. [role="screenshot"]
  337. image::images/ingest/custom-logs.png[Set up custom log integration in Fleet,align="center"]
  338. . Use the <<indices-rollover-index,rollover API>> to roll over your data stream.
  339. This ensures {es} applies the index template and its pipeline settings to any
  340. new data for the integration.
  341. +
  342. --
  343. ////
  344. [source,console]
  345. ----
  346. PUT _data_stream/logs-my_app-default
  347. ----
  348. // TEST[continued]
  349. ////
  350. [source,console]
  351. ----
  352. POST logs-my_app-default/_rollover/
  353. ----
  354. // TEST[continued]
  355. ////
  356. [source,console]
  357. ----
  358. DELETE _data_stream/*
  359. DELETE _index_template/*
  360. ----
  361. // TEST[continued]
  362. ////
  363. --
  364. [[pipeline-custom-logs-configuration]]
  365. **Option 2: Custom configuration**
  366. include::ingest.asciidoc[tag=create-name-custom-logs-pipeline]
  367. include::ingest.asciidoc[tag=name-custom-logs-dataset]
  368. . In **Custom Configurations**, specify your pipeline in the `pipeline` policy
  369. setting.
  370. +
  371. [role="screenshot"]
  372. image::images/ingest/custom-logs-pipeline.png[Custom pipeline configuration for custom log integration,align="center"]
  373. **{agent} standalone**
  374. If you run {agent} standalone, you can apply pipelines using an
  375. <<index-templates,index template>> that includes the
  376. <<index-default-pipeline,`index.default_pipeline`>> or
  377. <<index-final-pipeline,`index.final_pipeline`>> index setting. Alternatively,
  378. you can specify the `pipeline` policy setting in your `elastic-agent.yml`
  379. configuration. See {fleet-guide}/install-standalone-elastic-agent.html[Install standalone {agent}s].
  380. [discrete]
  381. [[access-source-fields]]
  382. === Access source fields in a processor
  383. Processors have read and write access to an incoming document's source fields.
  384. To access a field key in a processor, use its field name. The following `set`
  385. processor accesses `my-long-field`.
  386. [source,console]
  387. ----
  388. PUT _ingest/pipeline/my-pipeline
  389. {
  390. "processors": [
  391. {
  392. "set": {
  393. "field": "my-long-field",
  394. "value": 10
  395. }
  396. }
  397. ]
  398. }
  399. ----
  400. You can also prepend the `_source` prefix.
  401. [source,console]
  402. ----
  403. PUT _ingest/pipeline/my-pipeline
  404. {
  405. "processors": [
  406. {
  407. "set": {
  408. "field": "_source.my-long-field",
  409. "value": 10
  410. }
  411. }
  412. ]
  413. }
  414. ----
  415. Use dot notation to access object fields.
  416. IMPORTANT: If your document contains flattened objects, use the
  417. <<dot-expand-processor,`dot_expander`>> processor to expand them first. Other
  418. ingest processors cannot access flattened objects.
  419. [source,console]
  420. ----
  421. PUT _ingest/pipeline/my-pipeline
  422. {
  423. "processors": [
  424. {
  425. "dot_expander": {
  426. "description": "Expand 'my-object-field.my-property'",
  427. "field": "my-object-field.my-property"
  428. }
  429. },
  430. {
  431. "set": {
  432. "description": "Set 'my-object-field.my-property' to 10",
  433. "field": "my-object-field.my-property",
  434. "value": 10
  435. }
  436. }
  437. ]
  438. }
  439. ----
  440. [[template-snippets]]
  441. Several processor parameters support https://mustache.github.io[Mustache]
  442. template snippets. To access field values in a template snippet, enclose the
  443. field name in triple curly brackets:`{{{field-name}}}`. You can use template
  444. snippets to dynamically set field names.
  445. [source,console]
  446. ----
  447. PUT _ingest/pipeline/my-pipeline
  448. {
  449. "processors": [
  450. {
  451. "set": {
  452. "description": "Set dynamic '<service>' field to 'code' value",
  453. "field": "{{{service}}}",
  454. "value": "{{{code}}}"
  455. }
  456. }
  457. ]
  458. }
  459. ----
  460. [discrete]
  461. [[access-metadata-fields]]
  462. === Access metadata fields in a processor
  463. Processors can access the following metadata fields by name:
  464. * `_index`
  465. * `_id`
  466. * `_routing`
  467. * `_dynamic_templates`
  468. [source,console]
  469. ----
  470. PUT _ingest/pipeline/my-pipeline
  471. {
  472. "processors": [
  473. {
  474. "set": {
  475. "description": "Set '_routing' to 'geoip.country_iso_code' value",
  476. "field": "_routing",
  477. "value": "{{{geoip.country_iso_code}}}"
  478. }
  479. }
  480. ]
  481. }
  482. ----
  483. Use a Mustache template snippet to access metadata field values. For example,
  484. `{{{_routing}}}` retrieves a document's routing value.
  485. [source,console]
  486. ----
  487. PUT _ingest/pipeline/my-pipeline
  488. {
  489. "processors": [
  490. {
  491. "set": {
  492. "description": "Use geo_point dynamic template for address field",
  493. "field": "_dynamic_templates",
  494. "value": {
  495. "address": "geo_point"
  496. }
  497. }
  498. }
  499. ]
  500. }
  501. ----
  502. The set processor above tells ES to use the dynamic template named `geo_point`
  503. for the field `address` if this field is not defined in the mapping of the index
  504. yet. This processor overrides the dynamic template for the field `address` if
  505. already defined in the bulk request, but has no effect on other dynamic
  506. templates defined in the bulk request.
  507. WARNING: If you <<create-document-ids-automatically,automatically generate>>
  508. document IDs, you cannot use `{{{_id}}}` in a processor. {es} assigns
  509. auto-generated `_id` values after ingest.
  510. [discrete]
  511. [[access-ingest-metadata]]
  512. === Access ingest metadata in a processor
  513. Ingest processors can add and access ingest metadata using the `_ingest` key.
  514. Unlike source and metadata fields, {es} does not index ingest metadata fields by
  515. default. {es} also allows source fields that start with an `_ingest` key. If
  516. your data includes such source fields, use `_source._ingest` to access them.
  517. Pipelines only create the `_ingest.timestamp` ingest metadata field by default.
  518. This field contains a timestamp of when {es} received the document's indexing
  519. request. To index `_ingest.timestamp` or other ingest metadata fields, use the
  520. `set` processor.
  521. [source,console]
  522. ----
  523. PUT _ingest/pipeline/my-pipeline
  524. {
  525. "processors": [
  526. {
  527. "set": {
  528. "description": "Index the ingest timestamp as 'event.ingested'",
  529. "field": "event.ingested",
  530. "value": "{{{_ingest.timestamp}}}"
  531. }
  532. }
  533. ]
  534. }
  535. ----
  536. [discrete]
  537. [[handling-pipeline-failures]]
  538. === Handling pipeline failures
  539. A pipeline's processors run sequentially. By default, pipeline processing stops
  540. when one of these processors fails or encounters an error.
  541. To ignore a processor failure and run the pipeline's remaining processors, set
  542. `ignore_failure` to `true`.
  543. [source,console]
  544. ----
  545. PUT _ingest/pipeline/my-pipeline
  546. {
  547. "processors": [
  548. {
  549. "rename": {
  550. "description": "Rename 'provider' to 'cloud.provider'",
  551. "field": "provider",
  552. "target_field": "cloud.provider",
  553. "ignore_failure": true
  554. }
  555. }
  556. ]
  557. }
  558. ----
  559. Use the `on_failure` parameter to specify a list of processors to run
  560. immediately after a processor failure. If `on_failure` is specified, {es}
  561. afterward runs the pipeline's remaining processors, even if the `on_failure`
  562. configuration is empty.
  563. [source,console]
  564. ----
  565. PUT _ingest/pipeline/my-pipeline
  566. {
  567. "processors": [
  568. {
  569. "rename": {
  570. "description": "Rename 'provider' to 'cloud.provider'",
  571. "field": "provider",
  572. "target_field": "cloud.provider",
  573. "on_failure": [
  574. {
  575. "set": {
  576. "description": "Set 'error.message'",
  577. "field": "error.message",
  578. "value": "Field 'provider' does not exist. Cannot rename to 'cloud.provider'",
  579. "override": false
  580. }
  581. }
  582. ]
  583. }
  584. }
  585. ]
  586. }
  587. ----
  588. Nest a list of `on_failure` processors for nested error handling.
  589. [source,console]
  590. ----
  591. PUT _ingest/pipeline/my-pipeline
  592. {
  593. "processors": [
  594. {
  595. "rename": {
  596. "description": "Rename 'provider' to 'cloud.provider'",
  597. "field": "provider",
  598. "target_field": "cloud.provider",
  599. "on_failure": [
  600. {
  601. "set": {
  602. "description": "Set 'error.message'",
  603. "field": "error.message",
  604. "value": "Field 'provider' does not exist. Cannot rename to 'cloud.provider'",
  605. "override": false,
  606. "on_failure": [
  607. {
  608. "set": {
  609. "description": "Set 'error.message.multi'",
  610. "field": "error.message.multi",
  611. "value": "Document encountered multiple ingest errors",
  612. "override": true
  613. }
  614. }
  615. ]
  616. }
  617. }
  618. ]
  619. }
  620. }
  621. ]
  622. }
  623. ----
  624. You can also specify `on_failure` for a pipeline. If a processor without an
  625. `on_failure` value fails, {es} uses this pipeline-level parameter as a fallback.
  626. {es} will not attempt to run the pipeline's remaining processors.
  627. [source,console]
  628. ----
  629. PUT _ingest/pipeline/my-pipeline
  630. {
  631. "processors": [ ... ],
  632. "on_failure": [
  633. {
  634. "set": {
  635. "description": "Index document to 'failed-<index>'",
  636. "field": "_index",
  637. "value": "failed-{{{ _index }}}"
  638. }
  639. }
  640. ]
  641. }
  642. ----
  643. // TEST[s/\.\.\./{"lowercase": {"field":"my-keyword-field"}}/]
  644. Additional information about the pipeline failure may be available in the
  645. document metadata fields `on_failure_message`, `on_failure_processor_type`,
  646. `on_failure_processor_tag`, and `on_failure_pipeline`. These fields are
  647. accessible only from within an `on_failure` block.
  648. The following example uses the metadata fields to include information about
  649. pipeline failures in documents.
  650. [source,console]
  651. ----
  652. PUT _ingest/pipeline/my-pipeline
  653. {
  654. "processors": [ ... ],
  655. "on_failure": [
  656. {
  657. "set": {
  658. "description": "Record error information",
  659. "field": "error_information",
  660. "value": "Processor {{ _ingest.on_failure_processor_type }} with tag {{ _ingest.on_failure_processor_tag }} in pipeline {{ _ingest.on_failure_pipeline }} failed with message {{ _ingest.on_failure_message }}"
  661. }
  662. }
  663. ]
  664. }
  665. ----
  666. // TEST[s/\.\.\./{"lowercase": {"field":"my-keyword-field"}}/]
  667. [discrete]
  668. [[conditionally-run-processor]]
  669. === Conditionally run a processor
  670. Each processor supports an optional `if` condition, written as a
  671. {painless}/painless-guide.html[Painless script]. If provided, the processor only
  672. runs when the `if` condition is `true`.
  673. IMPORTANT: `if` condition scripts run in Painless's
  674. {painless}/painless-ingest-processor-context.html[ingest processor context]. In
  675. `if` conditions, `ctx` values are read-only.
  676. [source,console]
  677. ----
  678. PUT _ingest/pipeline/my-pipeline
  679. {
  680. "processors": [
  681. {
  682. "drop": {
  683. "description": "Drop documents with 'network.name' of 'Guest'",
  684. "if": "ctx?.network?.name == 'Guest'"
  685. }
  686. }
  687. ]
  688. }
  689. ----
  690. If the <<script-painless-regex-enabled,`script.painless.regex.enabled`>> cluster
  691. setting is enabled, you can use regular expressions in your `if` condition
  692. scripts. For supported syntax, see {painless}/painless-regexes.html[Painless
  693. regular expressions].
  694. TIP: If possible, avoid using regular expressions. Expensive regular expressions
  695. can slow indexing speeds.
  696. [source,console]
  697. ----
  698. PUT _ingest/pipeline/my-pipeline
  699. {
  700. "processors": [
  701. {
  702. "set": {
  703. "description": "If 'url.scheme' is 'http', set 'url.insecure' to true",
  704. "if": "ctx.url?.scheme =~ /^http[^s]/",
  705. "field": "url.insecure",
  706. "value": true
  707. }
  708. }
  709. ]
  710. }
  711. ----
  712. You must specify `if` conditions as valid JSON on a single line. However, you
  713. can use the {kibana-ref}/console-kibana.html#configuring-console[{kib}
  714. console]'s triple quote syntax to write and debug larger scripts.
  715. TIP: If possible, avoid using complex or expensive `if` condition scripts.
  716. Expensive condition scripts can slow indexing speeds.
  717. [source,console]
  718. ----
  719. PUT _ingest/pipeline/my-pipeline
  720. {
  721. "processors": [
  722. {
  723. "drop": {
  724. "description": "Drop documents that don't contain 'prod' tag",
  725. "if": """
  726. Collection tags = ctx.tags;
  727. if(tags != null){
  728. for (String tag : tags) {
  729. if (tag.toLowerCase().contains('prod')) {
  730. return false;
  731. }
  732. }
  733. }
  734. return true;
  735. """
  736. }
  737. }
  738. ]
  739. }
  740. ----
  741. You can also specify a <<modules-scripting-stored-scripts,stored script>> as the
  742. `if` condition.
  743. [source,console]
  744. ----
  745. PUT _scripts/my-prod-tag-script
  746. {
  747. "script": {
  748. "lang": "painless",
  749. "source": """
  750. Collection tags = ctx.tags;
  751. if(tags != null){
  752. for (String tag : tags) {
  753. if (tag.toLowerCase().contains('prod')) {
  754. return false;
  755. }
  756. }
  757. }
  758. return true;
  759. """
  760. }
  761. }
  762. PUT _ingest/pipeline/my-pipeline
  763. {
  764. "processors": [
  765. {
  766. "drop": {
  767. "description": "Drop documents that don't contain 'prod' tag",
  768. "if": { "id": "my-prod-tag-script" }
  769. }
  770. }
  771. ]
  772. }
  773. ----
  774. ////
  775. [source,console]
  776. ----
  777. DELETE _scripts/my-prod-tag-script
  778. DELETE _ingest/pipeline/my-pipeline
  779. ----
  780. // TEST[continued]
  781. ////
  782. Incoming documents often contain object fields. If a processor script attempts
  783. to access a field whose parent object does not exist, {es} returns a
  784. `NullPointerException`. To avoid these exceptions, use
  785. {painless}/painless-operators-reference.html#null-safe-operator[null safe
  786. operators], such as `?.`, and write your scripts to be null safe.
  787. For example, `ctx.network?.name.equalsIgnoreCase('Guest')` is not null safe.
  788. `ctx.network?.name` can return null. Rewrite the script as
  789. `'Guest'.equalsIgnoreCase(ctx.network?.name)`, which is null safe because
  790. `Guest` is always non-null.
  791. If you can't rewrite a script to be null safe, include an explicit null check.
  792. [source,console]
  793. ----
  794. PUT _ingest/pipeline/my-pipeline
  795. {
  796. "processors": [
  797. {
  798. "drop": {
  799. "description": "Drop documents that contain 'network.name' of 'Guest'",
  800. "if": "ctx.network?.name != null && ctx.network.name.contains('Guest')"
  801. }
  802. }
  803. ]
  804. }
  805. ----
  806. [discrete]
  807. [[conditionally-apply-pipelines]]
  808. === Conditionally apply pipelines
  809. Combine an `if` condition with the <<pipeline-processor,`pipeline`>> processor
  810. to apply other pipelines to documents based on your criteria. You can use this
  811. pipeline as the <<set-default-pipeline,default pipeline>> in an
  812. <<index-templates,index template>> used to configure multiple data streams or
  813. indices.
  814. [source,console]
  815. ----
  816. PUT _ingest/pipeline/one-pipeline-to-rule-them-all
  817. {
  818. "processors": [
  819. {
  820. "pipeline": {
  821. "description": "If 'service.name' is 'apache_httpd', use 'httpd_pipeline'",
  822. "if": "ctx.service?.name == 'apache_httpd'",
  823. "name": "httpd_pipeline"
  824. }
  825. },
  826. {
  827. "pipeline": {
  828. "description": "If 'service.name' is 'syslog', use 'syslog_pipeline'",
  829. "if": "ctx.service?.name == 'syslog'",
  830. "name": "syslog_pipeline"
  831. }
  832. },
  833. {
  834. "fail": {
  835. "description": "If 'service.name' is not 'apache_httpd' or 'syslog', return a failure message",
  836. "if": "ctx.service?.name != 'apache_httpd' && ctx.service?.name != 'syslog'",
  837. "message": "This pipeline requires service.name to be either `syslog` or `apache_httpd`"
  838. }
  839. }
  840. ]
  841. }
  842. ----
  843. [discrete]
  844. [[get-pipeline-usage-stats]]
  845. === Get pipeline usage statistics
  846. Use the <<cluster-nodes-stats,node stats>> API to get global and per-pipeline
  847. ingest statistics. Use these stats to determine which pipelines run most
  848. frequently or spend the most time processing.
  849. [source,console]
  850. ----
  851. GET _nodes/stats/ingest?filter_path=nodes.*.ingest
  852. ----
  853. include::ingest/common-log-format-example.asciidoc[]
  854. include::ingest/enrich.asciidoc[]
  855. include::ingest/processors.asciidoc[]