ingest-node.asciidoc 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  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. The `description` is a special field to store a helpful description of
  14. what the pipeline does.
  15. The `processors` parameter defines a list of processors to be executed in
  16. order.
  17. [[ingest-apis]]
  18. == Ingest APIs
  19. The following ingest APIs are available for managing pipelines:
  20. * <<put-pipeline-api>> to add or update a pipeline
  21. * <<get-pipeline-api>> to return a specific pipeline
  22. * <<delete-pipeline-api>> to delete a pipeline
  23. * <<simulate-pipeline-api>> to simulate a call to a pipeline
  24. [[put-pipeline-api]]
  25. === Put Pipeline API
  26. The put pipeline API adds pipelines and updates existing pipelines in the cluster.
  27. [source,js]
  28. --------------------------------------------------
  29. PUT _ingest/pipeline/my-pipeline-id
  30. {
  31. "description" : "describe pipeline",
  32. "processors" : [
  33. {
  34. "set" : {
  35. "field": "foo",
  36. "value": "bar"
  37. }
  38. }
  39. ]
  40. }
  41. --------------------------------------------------
  42. // CONSOLE
  43. NOTE: The put pipeline API also instructs all ingest nodes to reload their in-memory representation of pipelines, so that
  44. pipeline changes take effect immediately.
  45. [[get-pipeline-api]]
  46. === Get Pipeline API
  47. The get pipeline API returns pipelines based on ID. This API always returns a local reference of the pipeline.
  48. [source,js]
  49. --------------------------------------------------
  50. GET _ingest/pipeline/my-pipeline-id
  51. --------------------------------------------------
  52. // CONSOLE
  53. // TEST[continued]
  54. Example response:
  55. [source,js]
  56. --------------------------------------------------
  57. {
  58. "pipelines": [ {
  59. "id": "my-pipeline-id",
  60. "config": {
  61. "description": "describe pipeline",
  62. "processors": [
  63. {
  64. "set" : {
  65. "field": "foo",
  66. "value": "bar"
  67. }
  68. }
  69. ]
  70. }
  71. } ]
  72. }
  73. --------------------------------------------------
  74. // TESTRESPONSE
  75. For each returned pipeline, the source and the version are returned.
  76. The version is useful for knowing which version of the pipeline the node has.
  77. You can specify multiple IDs to return more than one pipeline. Wildcards are also supported.
  78. [[delete-pipeline-api]]
  79. === Delete Pipeline API
  80. The delete pipeline API deletes pipelines by ID.
  81. [source,js]
  82. --------------------------------------------------
  83. DELETE _ingest/pipeline/my-pipeline-id
  84. --------------------------------------------------
  85. // CONSOLE
  86. // TEST[continued]
  87. [[simulate-pipeline-api]]
  88. === Simulate Pipeline API
  89. The simulate pipeline API executes a specific pipeline against
  90. the set of documents provided in the body of the request.
  91. You can either specify an existing pipeline to execute
  92. against the provided documents, or supply a pipeline definition in
  93. the body of the request.
  94. Here is the structure of a simulate request with a pipeline definition provided
  95. in the body of the request:
  96. [source,js]
  97. --------------------------------------------------
  98. POST _ingest/pipeline/_simulate
  99. {
  100. "pipeline" : {
  101. // pipeline definition here
  102. },
  103. "docs" : [
  104. { /** first document **/ },
  105. { /** second document **/ },
  106. // ...
  107. ]
  108. }
  109. --------------------------------------------------
  110. Here is the structure of a simulate request against an existing pipeline:
  111. [source,js]
  112. --------------------------------------------------
  113. POST _ingest/pipeline/my-pipeline-id/_simulate
  114. {
  115. "docs" : [
  116. { /** first document **/ },
  117. { /** second document **/ },
  118. // ...
  119. ]
  120. }
  121. --------------------------------------------------
  122. Here is an example of a simulate request with a pipeline defined in the request
  123. and its response:
  124. [source,js]
  125. --------------------------------------------------
  126. POST _ingest/pipeline/_simulate
  127. {
  128. "pipeline" :
  129. {
  130. "description": "_description",
  131. "processors": [
  132. {
  133. "set" : {
  134. "field" : "field2",
  135. "value" : "_value"
  136. }
  137. }
  138. ]
  139. },
  140. "docs": [
  141. {
  142. "_index": "index",
  143. "_type": "type",
  144. "_id": "id",
  145. "_source": {
  146. "foo": "bar"
  147. }
  148. },
  149. {
  150. "_index": "index",
  151. "_type": "type",
  152. "_id": "id",
  153. "_source": {
  154. "foo": "rab"
  155. }
  156. }
  157. ]
  158. }
  159. --------------------------------------------------
  160. // CONSOLE
  161. Response:
  162. [source,js]
  163. --------------------------------------------------
  164. {
  165. "docs": [
  166. {
  167. "doc": {
  168. "_id": "id",
  169. "_ttl": null,
  170. "_parent": null,
  171. "_index": "index",
  172. "_routing": null,
  173. "_type": "type",
  174. "_timestamp": null,
  175. "_source": {
  176. "field2": "_value",
  177. "foo": "bar"
  178. },
  179. "_ingest": {
  180. "timestamp": "2016-01-04T23:53:27.186+0000"
  181. }
  182. }
  183. },
  184. {
  185. "doc": {
  186. "_id": "id",
  187. "_ttl": null,
  188. "_parent": null,
  189. "_index": "index",
  190. "_routing": null,
  191. "_type": "type",
  192. "_timestamp": null,
  193. "_source": {
  194. "field2": "_value",
  195. "foo": "rab"
  196. },
  197. "_ingest": {
  198. "timestamp": "2016-01-04T23:53:27.186+0000"
  199. }
  200. }
  201. }
  202. ]
  203. }
  204. --------------------------------------------------
  205. [[ingest-verbose-param]]
  206. ==== Viewing Verbose Results
  207. You can use the simulate pipeline API to see how each processor affects the ingest document
  208. as it passes through the pipeline. To see the intermediate results of
  209. each processor in the simulate request, you can add the `verbose` parameter
  210. to the request.
  211. Here is an example of a verbose request and its response:
  212. [source,js]
  213. --------------------------------------------------
  214. POST _ingest/pipeline/_simulate?verbose
  215. {
  216. "pipeline" :
  217. {
  218. "description": "_description",
  219. "processors": [
  220. {
  221. "set" : {
  222. "field" : "field2",
  223. "value" : "_value2"
  224. }
  225. },
  226. {
  227. "set" : {
  228. "field" : "field3",
  229. "value" : "_value3"
  230. }
  231. }
  232. ]
  233. },
  234. "docs": [
  235. {
  236. "_index": "index",
  237. "_type": "type",
  238. "_id": "id",
  239. "_source": {
  240. "foo": "bar"
  241. }
  242. },
  243. {
  244. "_index": "index",
  245. "_type": "type",
  246. "_id": "id",
  247. "_source": {
  248. "foo": "rab"
  249. }
  250. }
  251. ]
  252. }
  253. --------------------------------------------------
  254. // CONSOLE
  255. Response:
  256. [source,js]
  257. --------------------------------------------------
  258. {
  259. "docs": [
  260. {
  261. "processor_results": [
  262. {
  263. "tag": "processor[set]-0",
  264. "doc": {
  265. "_id": "id",
  266. "_ttl": null,
  267. "_parent": null,
  268. "_index": "index",
  269. "_routing": null,
  270. "_type": "type",
  271. "_timestamp": null,
  272. "_source": {
  273. "field2": "_value2",
  274. "foo": "bar"
  275. },
  276. "_ingest": {
  277. "timestamp": "2016-01-05T00:02:51.383+0000"
  278. }
  279. }
  280. },
  281. {
  282. "tag": "processor[set]-1",
  283. "doc": {
  284. "_id": "id",
  285. "_ttl": null,
  286. "_parent": null,
  287. "_index": "index",
  288. "_routing": null,
  289. "_type": "type",
  290. "_timestamp": null,
  291. "_source": {
  292. "field3": "_value3",
  293. "field2": "_value2",
  294. "foo": "bar"
  295. },
  296. "_ingest": {
  297. "timestamp": "2016-01-05T00:02:51.383+0000"
  298. }
  299. }
  300. }
  301. ]
  302. },
  303. {
  304. "processor_results": [
  305. {
  306. "tag": "processor[set]-0",
  307. "doc": {
  308. "_id": "id",
  309. "_ttl": null,
  310. "_parent": null,
  311. "_index": "index",
  312. "_routing": null,
  313. "_type": "type",
  314. "_timestamp": null,
  315. "_source": {
  316. "field2": "_value2",
  317. "foo": "rab"
  318. },
  319. "_ingest": {
  320. "timestamp": "2016-01-05T00:02:51.384+0000"
  321. }
  322. }
  323. },
  324. {
  325. "tag": "processor[set]-1",
  326. "doc": {
  327. "_id": "id",
  328. "_ttl": null,
  329. "_parent": null,
  330. "_index": "index",
  331. "_routing": null,
  332. "_type": "type",
  333. "_timestamp": null,
  334. "_source": {
  335. "field3": "_value3",
  336. "field2": "_value2",
  337. "foo": "rab"
  338. },
  339. "_ingest": {
  340. "timestamp": "2016-01-05T00:02:51.384+0000"
  341. }
  342. }
  343. }
  344. ]
  345. }
  346. ]
  347. }
  348. --------------------------------------------------
  349. [[accessing-data-in-pipelines]]
  350. == Accessing Data in Pipelines
  351. The processors in a pipeline have read and write access to documents that pass through the pipeline.
  352. The processors can access fields in the source of a document and the document's metadata fields.
  353. [float]
  354. [[accessing-source-fields]]
  355. === Accessing Fields in the Source
  356. Accessing a field in the source is straightforward. You simply refer to fields by
  357. their name. For example:
  358. [source,js]
  359. --------------------------------------------------
  360. {
  361. "set": {
  362. "field": "my_field"
  363. "value": 582.1
  364. }
  365. }
  366. --------------------------------------------------
  367. On top of this, fields from the source are always accessible via the `_source` prefix:
  368. [source,js]
  369. --------------------------------------------------
  370. {
  371. "set": {
  372. "field": "_source.my_field"
  373. "value": 582.1
  374. }
  375. }
  376. --------------------------------------------------
  377. [float]
  378. [[accessing-metadata-fields]]
  379. === Accessing Metadata Fields
  380. You can access metadata fields in the same way that you access fields in the source. This
  381. is possible because Elasticsearch doesn't allow fields in the source that have the
  382. same name as metadata fields.
  383. The following example sets the `_id` metadata field of a document to `1`:
  384. [source,js]
  385. --------------------------------------------------
  386. {
  387. "set": {
  388. "field": "_id"
  389. "value": "1"
  390. }
  391. }
  392. --------------------------------------------------
  393. The following metadata fields are accessible by a processor: `_index`, `_type`, `_id`, `_routing`, `_parent`.
  394. [float]
  395. [[accessing-ingest-metadata]]
  396. === Accessing Ingest Metadata Fields
  397. Beyond metadata fields and source fields, ingest also adds ingest metadata to the documents that it processes.
  398. These metadata properties are accessible under the `_ingest` key. Currently ingest adds the ingest timestamp
  399. under the `_ingest.timestamp` key of the ingest metadata. The ingest timestamp is the time when Elasticsearch
  400. received the index or bulk request to pre-process the document.
  401. Any processor can add ingest-related metadata during document processing. Ingest metadata is transient
  402. and is lost after a document has been processed by the pipeline. Therefore, ingest metadata won't be indexed.
  403. The following example adds a field with the name `received`. The value is the ingest timestamp:
  404. [source,js]
  405. --------------------------------------------------
  406. {
  407. "set": {
  408. "field": "received"
  409. "value": "{{_ingest.timestamp}}"
  410. }
  411. }
  412. --------------------------------------------------
  413. Unlike Elasticsearch metadata fields, the ingest metadata field name `_ingest` can be used as a valid field name
  414. in the source of a document. Use `_source._ingest` to refer to the field in the source document. Otherwise, `_ingest`
  415. will be interpreted as an ingest metadata field.
  416. [float]
  417. [[accessing-template-fields]]
  418. === Accessing Fields and Metafields in Templates
  419. A number of processor settings also support templating. Settings that support templating can have zero or more
  420. template snippets. A template snippet begins with `{{` and ends with `}}`.
  421. Accessing fields and metafields in templates is exactly the same as via regular processor field settings.
  422. The following example adds a field named `field_c`. Its value is a concatenation of
  423. the values of `field_a` and `field_b`.
  424. [source,js]
  425. --------------------------------------------------
  426. {
  427. "set": {
  428. "field": "field_c"
  429. "value": "{{field_a}} {{field_b}}"
  430. }
  431. }
  432. --------------------------------------------------
  433. The following example uses the value of the `geoip.country_iso_code` field in the source
  434. to set the index that the document will be indexed into:
  435. [source,js]
  436. --------------------------------------------------
  437. {
  438. "set": {
  439. "field": "_index"
  440. "value": "{{geoip.country_iso_code}}"
  441. }
  442. }
  443. --------------------------------------------------
  444. [[handling-failure-in-pipelines]]
  445. == Handling Failures in Pipelines
  446. In its simplest use case, a pipeline defines a list of processors that
  447. are executed sequentially, and processing halts at the first exception. This
  448. behavior may not be desirable when failures are expected. For example, you may have logs
  449. that don't match the specified grok expression. Instead of halting execution, you may
  450. want to index such documents into a separate index.
  451. To enable this behavior, you can use the `on_failure` parameter. The `on_failure` parameter
  452. defines a list of processors to be executed immediately following the failed processor.
  453. You can specify this parameter at the pipeline level, as well as at the processor
  454. level. If a processor specifies an `on_failure` configuration, whether
  455. it is empty or not, any exceptions that are thrown by the processor are caught, and the
  456. pipeline continues executing the remaining processors. Because you can define further processors
  457. within the scope of an `on_failure` statement, you can nest failure handling.
  458. The following example defines a pipeline that renames the `foo` field in
  459. the processed document to `bar`. If the document does not contain the `foo` field, the processor
  460. attaches an error message to the document for later analysis within
  461. Elasticsearch.
  462. [source,js]
  463. --------------------------------------------------
  464. {
  465. "description" : "my first pipeline with handled exceptions",
  466. "processors" : [
  467. {
  468. "rename" : {
  469. "field" : "foo",
  470. "target_field" : "bar",
  471. "on_failure" : [
  472. {
  473. "set" : {
  474. "field" : "error",
  475. "value" : "field \"foo\" does not exist, cannot rename to \"bar\""
  476. }
  477. }
  478. ]
  479. }
  480. }
  481. ]
  482. }
  483. --------------------------------------------------
  484. The following example defines an `on_failure` block on a whole pipeline to change
  485. the index to which failed documents get sent.
  486. [source,js]
  487. --------------------------------------------------
  488. {
  489. "description" : "my first pipeline with handled exceptions",
  490. "processors" : [ ... ],
  491. "on_failure" : [
  492. {
  493. "set" : {
  494. "field" : "_index",
  495. "value" : "failed-{{ _index }}"
  496. }
  497. }
  498. ]
  499. }
  500. --------------------------------------------------
  501. Alternatively instead of defining behaviour in case of processor failure, it is also possible
  502. to ignore a failure and continue with the next processor by specifying the `ignore_failure` setting.
  503. In case in the example below the field `foo` doesn't exist the failure will be caught and the pipeline
  504. continues to execute, which in this case means that the pipeline does nothing.
  505. [source,js]
  506. --------------------------------------------------
  507. {
  508. "description" : "my first pipeline with handled exceptions",
  509. "processors" : [
  510. {
  511. "rename" : {
  512. "field" : "foo",
  513. "target_field" : "bar",
  514. "ignore_failure" : true
  515. }
  516. }
  517. ]
  518. }
  519. --------------------------------------------------
  520. The `ignore_failure` can be set on any processor and defaults to `false`.
  521. [float]
  522. [[accessing-error-metadata]]
  523. === Accessing Error Metadata From Processors Handling Exceptions
  524. You may want to retrieve the actual error message that was thrown
  525. by a failed processor. To do so you can access metadata fields called
  526. `on_failure_message`, `on_failure_processor_type`, and `on_failure_processor_tag`. These fields are only accessible
  527. from within the context of an `on_failure` block.
  528. Here is an updated version of the example that you
  529. saw earlier. But instead of setting the error message manually, the example leverages the `on_failure_message`
  530. metadata field to provide the error message.
  531. [source,js]
  532. --------------------------------------------------
  533. {
  534. "description" : "my first pipeline with handled exceptions",
  535. "processors" : [
  536. {
  537. "rename" : {
  538. "field" : "foo",
  539. "to" : "bar",
  540. "on_failure" : [
  541. {
  542. "set" : {
  543. "field" : "error",
  544. "value" : "{{ _ingest.on_failure_message }}"
  545. }
  546. }
  547. ]
  548. }
  549. }
  550. ]
  551. }
  552. --------------------------------------------------
  553. [[ingest-processors]]
  554. == Processors
  555. All processors are defined in the following way within a pipeline definition:
  556. [source,js]
  557. --------------------------------------------------
  558. {
  559. "PROCESSOR_NAME" : {
  560. ... processor configuration options ...
  561. }
  562. }
  563. --------------------------------------------------
  564. Each processor defines its own configuration parameters, but all processors have
  565. the ability to declare `tag` and `on_failure` fields. These fields are optional.
  566. A `tag` is simply a string identifier of the specific instantiation of a certain
  567. processor in a pipeline. The `tag` field does not affect the processor's behavior,
  568. but is very useful for bookkeeping and tracing errors to specific processors.
  569. See <<handling-failure-in-pipelines>> to learn more about the `on_failure` field and error handling in pipelines.
  570. The <<ingest-info,node info API>> can be used to figure out what processors are available in a cluster.
  571. The <<ingest-info,node info API>> will provide a per node list of what processors are available.
  572. Custom processors must be installed on all nodes. The put pipeline API will fail if a processor specified in a pipeline
  573. doesn't exist on all nodes. If you rely on custom processor plugins make sure to mark these plugins as mandatory by adding
  574. `plugin.mandatory` setting to the `config/elasticsearch.yml` file, for example:
  575. [source,yaml]
  576. --------------------------------------------------
  577. plugin.mandatory: ingest-attachment,ingest-geoip
  578. --------------------------------------------------
  579. A node will not start if either of these plugins are not available.
  580. The <<ingest-stats,node stats API>> can be used to fetch ingest usage statistics, globally and on a per
  581. pipeline basis. Useful to find out which pipelines are used the most or spent the most time on preprocessing.
  582. [[append-procesesor]]
  583. === Append Processor
  584. Appends one or more values to an existing array if the field already exists and it is an array.
  585. Converts a scalar to an array and appends one or more values to it if the field exists and it is a scalar.
  586. Creates an array containing the provided values if the field doesn't exist.
  587. Accepts a single value or an array of values.
  588. [[append-options]]
  589. .Append Options
  590. [options="header"]
  591. |======
  592. | Name | Required | Default | Description
  593. | `field` | yes | - | The field to be appended to
  594. | `value` | yes | - | The value to be appended
  595. |======
  596. [source,js]
  597. --------------------------------------------------
  598. {
  599. "append": {
  600. "field": "field1"
  601. "value": ["item2", "item3", "item4"]
  602. }
  603. }
  604. --------------------------------------------------
  605. [[convert-processor]]
  606. === Convert Processor
  607. Converts an existing field's value to a different type, such as converting a string to an integer.
  608. If the field value is an array, all members will be converted.
  609. The supported types include: `integer`, `float`, `string`, `boolean`, and `auto`.
  610. Specifying `boolean` will set the field to true if its string value is equal to `true` (ignore case), to
  611. false if its string value is equal to `false` (ignore case), or it will throw an exception otherwise.
  612. Specifying `auto` will attempt to convert the string-valued `field` into the closest non-string type.
  613. For example, a field whose value is `"true"` will be converted to its respective boolean type: `true`. And
  614. a value of `"242.15"` will "automatically" be converted to `242.15` of type `float`. If a provided field cannot
  615. be appropriately converted, the Convert Processor will still process successfully and leave the field value as-is. In
  616. such a case, `target_field` will still be updated with the unconverted field value.
  617. [[convert-options]]
  618. .Convert Options
  619. [options="header"]
  620. |======
  621. | Name | Required | Default | Description
  622. | `field` | yes | - | The field whose value is to be converted
  623. | `target_field` | no | `field` | The field to assign the converted value to, by default `field` is updated in-place
  624. | `type` | yes | - | The type to convert the existing value to
  625. |======
  626. [source,js]
  627. --------------------------------------------------
  628. {
  629. "convert": {
  630. "field" : "foo"
  631. "type": "integer"
  632. }
  633. }
  634. --------------------------------------------------
  635. [[date-processor]]
  636. === Date Processor
  637. Parses dates from fields, and then uses the date or timestamp as the timestamp for the document.
  638. By default, the date processor adds the parsed date as a new field called `@timestamp`. You can specify a
  639. different field by setting the `target_field` configuration parameter. Multiple date formats are supported
  640. as part of the same date processor definition. They will be used sequentially to attempt parsing the date field,
  641. in the same order they were defined as part of the processor definition.
  642. [[date-options]]
  643. .Date options
  644. [options="header"]
  645. |======
  646. | Name | Required | Default | Description
  647. | `field` | yes | - | The field to get the date from.
  648. | `target_field` | no | @timestamp | The field that will hold the parsed date.
  649. | `formats` | yes | - | An array of the expected date formats. Can be a Joda pattern or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N.
  650. | `timezone` | no | UTC | The timezone to use when parsing the date.
  651. | `locale` | no | ENGLISH | The locale to use when parsing the date, relevant when parsing month names or week days.
  652. |======
  653. Here is an example that adds the parsed date to the `timestamp` field based on the `initial_date` field:
  654. [source,js]
  655. --------------------------------------------------
  656. {
  657. "description" : "...",
  658. "processors" : [
  659. {
  660. "date" : {
  661. "field" : "initial_date",
  662. "target_field" : "timestamp",
  663. "formats" : ["dd/MM/yyyy hh:mm:ss"],
  664. "timezone" : "Europe/Amsterdam"
  665. }
  666. }
  667. ]
  668. }
  669. --------------------------------------------------
  670. [[date-index-name-processor]]
  671. === Date Index Name Processor
  672. The purpose of this processor is to point documents to the right time based index based
  673. on a date or timestamp field in a document by using the <<date-math-index-names, date math index name support>>.
  674. The processor sets the `_index` meta field with a date math index name expression based on the provided index name
  675. prefix, a date or timestamp field in the documents being processed and the provided date rounding.
  676. First this processor fetches the date or timestamp from a field in the document being processed. Optionally
  677. date formatting can be configured on how the field's value should be parsed into a date. Then this date,
  678. the provided index name prefix and the provided date rounding get formatted into a date math index name expression.
  679. Also here optionally date formatting can be specified on how the date should be formatted into a date math index name
  680. expression.
  681. An example pipeline that points documents to a monthly index that starts with a `myindex-` prefix based on a
  682. date in the `date1` field:
  683. [source,js]
  684. --------------------------------------------------
  685. PUT _ingest/pipeline/1
  686. {
  687. "processors" : [
  688. {
  689. "date_index_name" : {
  690. "field" : "date1",
  691. "index_name_prefix" : "myindex-",
  692. "date_rounding" : "m"
  693. }
  694. }
  695. ]
  696. }
  697. --------------------------------------------------
  698. Using that pipeline for an index request:
  699. [source,js]
  700. --------------------------------------------------
  701. PUT /myindex/type/1?pipeline=1
  702. {
  703. "date1" : "2016-04-25T12:02:01.789Z"
  704. }
  705. --------------------------------------------------
  706. The above request will not index this document into the `myindex` index, but into the `myindex-2016-04-01` index.
  707. This is because the date is being rounded by month.
  708. [[date-index-name-options]]
  709. .Date index name options
  710. [options="header"]
  711. |======
  712. | Name | Required | Default | Description
  713. | `field` | yes | - | The field to get the date or timestamp from.
  714. | `index_name_prefix` | no | - | A prefix of the index name to be prepended before the printed date.
  715. | `date_rounding` | yes | - | How to round the date when formatting the date into the index name. Valid values are: `y` (year), `M` (month), `w` (week), `d` (day), `h` (hour), `m` (minute) and `s` (second).
  716. | `date_formats ` | no | yyyy-MM-dd'T'HH:mm:ss.SSSZ | An array of the expected date formats for parsing dates / timestamps in the document being preprocessed. Can be a Joda pattern or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N.
  717. | `timezone` | no | UTC | The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names.
  718. | `locale` | no | ENGLISH | The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days.
  719. | `index_name_format` | no | yyyy-MM-dd | The format to be used when printing the parsed date into the index name. An valid Joda pattern is expected here.
  720. |======
  721. [[fail-processor]]
  722. === Fail Processor
  723. Raises an exception. This is useful for when
  724. you expect a pipeline to fail and want to relay a specific message
  725. to the requester.
  726. [[fail-options]]
  727. .Fail Options
  728. [options="header"]
  729. |======
  730. | Name | Required | Default | Description
  731. | `message` | yes | - | The error message of the `FailException` thrown by the processor
  732. |======
  733. [source,js]
  734. --------------------------------------------------
  735. {
  736. "fail": {
  737. "message": "an error message"
  738. }
  739. }
  740. --------------------------------------------------
  741. [[foreach-processor]]
  742. === Foreach Processor
  743. Processes elements in an array of unknown length.
  744. All processors can operate on elements inside an array, but if all elements of an array need to
  745. be processed in the same way, defining a processor for each element becomes cumbersome and tricky
  746. because it is likely that the number of elements in an array is unknown. For this reason the `foreach`
  747. processor exists. By specifying the field holding array elements and a processor that
  748. defines what should happen to each element, array fields can easily be preprocessed.
  749. A processor inside the foreach processor works in the array element context and puts that in the ingest metadata
  750. under the `_ingest._value` key. If the array element is a json object it holds all immediate fields of that json object.
  751. and if the nested object is a value is `_ingest._value` just holds that value. Note that if a processor prior to the
  752. `foreach` processor used `_ingest._value` key then the specified value will not be available to the processor inside
  753. the `foreach` processor. The `foreach` processor does restore the original value, so that value is available to processors
  754. after the `foreach` processor.
  755. Note that any other field from the document are accessible and modifiable like with all other processors. This processor
  756. just puts the current array element being read into `_ingest._value` ingest metadata attribute, so that it may be
  757. pre-processed.
  758. If the `foreach` processor fails to process an element inside the array, and no `on_failure` processor has been specified,
  759. then it aborts the execution and leaves the array unmodified.
  760. [[foreach-options]]
  761. .Foreach Options
  762. [options="header"]
  763. |======
  764. | Name | Required | Default | Description
  765. | `field` | yes | - | The array field
  766. | `processor` | yes | - | The processor to execute against each field
  767. |======
  768. Assume the following document:
  769. [source,js]
  770. --------------------------------------------------
  771. {
  772. "values" : ["foo", "bar", "baz"]
  773. }
  774. --------------------------------------------------
  775. When this `foreach` processor operates on this sample document:
  776. [source,js]
  777. --------------------------------------------------
  778. {
  779. "foreach" : {
  780. "field" : "values",
  781. "processor" : {
  782. "uppercase" : {
  783. "field" : "_ingest._value"
  784. }
  785. }
  786. }
  787. }
  788. --------------------------------------------------
  789. Then the document will look like this after preprocessing:
  790. [source,js]
  791. --------------------------------------------------
  792. {
  793. "values" : ["FOO", "BAR", "BAZ"]
  794. }
  795. --------------------------------------------------
  796. Let's take a look at another example:
  797. [source,js]
  798. --------------------------------------------------
  799. {
  800. "persons" : [
  801. {
  802. "id" : "1",
  803. "name" : "John Doe"
  804. },
  805. {
  806. "id" : "2",
  807. "name" : "Jane Doe"
  808. }
  809. ]
  810. }
  811. --------------------------------------------------
  812. In this case, the `id` field needs to be removed,
  813. so the following `foreach` processor is used:
  814. [source,js]
  815. --------------------------------------------------
  816. {
  817. "foreach" : {
  818. "field" : "persons",
  819. "processor" : {
  820. "remove" : {
  821. "field" : "_ingest._value.id"
  822. }
  823. }
  824. }
  825. }
  826. --------------------------------------------------
  827. After preprocessing the result is:
  828. [source,js]
  829. --------------------------------------------------
  830. {
  831. "persons" : [
  832. {
  833. "name" : "John Doe"
  834. },
  835. {
  836. "name" : "Jane Doe"
  837. }
  838. ]
  839. }
  840. --------------------------------------------------
  841. The wrapped processor can have a `on_failure` definition.
  842. For example, the `id` field may not exist on all person objects.
  843. Instead of failing the index request, you can use an `on_failure`
  844. block to send the document to the 'failure_index' index for later inspection:
  845. [source,js]
  846. --------------------------------------------------
  847. {
  848. "foreach" : {
  849. "field" : "persons",
  850. "processor" : {
  851. "remove" : {
  852. "field" : "_value.id",
  853. "on_failure" : [
  854. {
  855. "set" : {
  856. "field", "_index",
  857. "value", "failure_index"
  858. }
  859. }
  860. ]
  861. }
  862. }
  863. }
  864. }
  865. --------------------------------------------------
  866. In this example, if the `remove` processor does fail, then
  867. the array elements that have been processed thus far will
  868. be updated.
  869. [[grok-processor]]
  870. === Grok Processor
  871. Extracts structured fields out of a single text field within a document. You choose which field to
  872. extract matched fields from, as well as the grok pattern you expect will match. A grok pattern is like a regular
  873. expression that supports aliased expressions that can be reused.
  874. This tool is perfect for syslog logs, apache and other webserver logs, mysql logs, and in general, any log format
  875. that is generally written for humans and not computer consumption.
  876. This processor comes packaged with over
  877. https://github.com/elastic/elasticsearch/tree/master/modules/ingest-common/src/main/resources/patterns[120 reusable patterns].
  878. If you need help building patterns to match your logs, you will find the <http://grokdebug.herokuapp.com> and
  879. <http://grokconstructor.appspot.com/> applications quite useful!
  880. [[grok-basics]]
  881. ==== Grok Basics
  882. Grok sits on top of regular expressions, so any regular expressions are valid in grok as well.
  883. The regular expression library is Oniguruma, and you can see the full supported regexp syntax
  884. https://github.com/kkos/oniguruma/blob/master/doc/RE[on the Onigiruma site].
  885. Grok works by leveraging this regular expression language to allow naming existing patterns and combining them into more
  886. complex patterns that match your fields.
  887. The syntax for reusing a grok pattern comes in three forms: `%{SYNTAX:SEMANTIC}`, `%{SYNTAX}`, `%{SYNTAX:SEMANTIC:TYPE}`.
  888. The `SYNTAX` is the name of the pattern that will match your text. For example, `3.44` will be matched by the `NUMBER`
  889. pattern and `55.3.244.1` will be matched by the `IP` pattern. The syntax is how you match. `NUMBER` and `IP` are both
  890. patterns that are provided within the default patterns set.
  891. The `SEMANTIC` is the identifier you give to the piece of text being matched. For example, `3.44` could be the
  892. duration of an event, so you could call it simply `duration`. Further, a string `55.3.244.1` might identify
  893. the `client` making a request.
  894. The `TYPE` is the type you wish to cast your named field. `int` and `float` are currently the only types supported for coercion.
  895. For example, you might want to match the following text:
  896. [source,js]
  897. --------------------------------------------------
  898. 3.44 55.3.244.1
  899. --------------------------------------------------
  900. You may know that the message in the example is a number followed by an IP address. You can match this text by using the following
  901. Grok expression.
  902. [source,js]
  903. --------------------------------------------------
  904. %{NUMBER:duration} %{IP:client}
  905. --------------------------------------------------
  906. [[using-grok]]
  907. ==== Using the Grok Processor in a Pipeline
  908. [[grok-options]]
  909. .Grok Options
  910. [options="header"]
  911. |======
  912. | Name | Required | Default | Description
  913. | `field` | yes | - | The field to use for grok expression parsing
  914. | `patterns` | yes | - | An ordered list of grok expression to match and extract named captures with. Returns on the first expression in the list that matches.
  915. | `pattern_definitions` | no | - | A map of pattern-name and pattern tuples defining custom patterns to be used by the current processor. Patterns matching existing names will override the pre-existing definition.
  916. | `trace_match` | no | false | when true, `_ingest._grok_match_index` will be inserted into your matched document's metadata with the index into the pattern found in `patterns` that matched.
  917. |======
  918. Here is an example of using the provided patterns to extract out and name structured fields from a string field in
  919. a document.
  920. [source,js]
  921. --------------------------------------------------
  922. {
  923. "message": "55.3.244.1 GET /index.html 15824 0.043"
  924. }
  925. --------------------------------------------------
  926. The pattern for this could be:
  927. [source,js]
  928. --------------------------------------------------
  929. %{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}
  930. --------------------------------------------------
  931. Here is an example pipeline for processing the above document by using Grok:
  932. [source,js]
  933. --------------------------------------------------
  934. {
  935. "description" : "...",
  936. "processors": [
  937. {
  938. "grok": {
  939. "field": "message",
  940. "patterns": ["%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}"]
  941. }
  942. }
  943. ]
  944. }
  945. --------------------------------------------------
  946. This pipeline will insert these named captures as new fields within the document, like so:
  947. [source,js]
  948. --------------------------------------------------
  949. {
  950. "message": "55.3.244.1 GET /index.html 15824 0.043",
  951. "client": "55.3.244.1",
  952. "method": "GET",
  953. "request": "/index.html",
  954. "bytes": 15824,
  955. "duration": "0.043"
  956. }
  957. --------------------------------------------------
  958. [[custom-patterns]]
  959. ==== Custom Patterns and Pattern Files
  960. The Grok processor comes pre-packaged with a base set of pattern. These patterns may not always have
  961. what you are looking for. Pattern have a very basic format. Each entry describes has a name and the pattern itself.
  962. You can add your own patterns to a processor definition under the `pattern_definitions` option.
  963. Here is an example of a pipeline specifying custom pattern definitions:
  964. [source,js]
  965. --------------------------------------------------
  966. {
  967. "description" : "...",
  968. "processors": [
  969. {
  970. "grok": {
  971. "field": "message",
  972. "patterns": ["my %{FAVORITE_DOG:dog} is colored %{RGB:color}"]
  973. "pattern_definitions" : {
  974. "FAVORITE_DOG" : "beagle",
  975. "RGB" : "RED|GREEN|BLUE"
  976. }
  977. }
  978. }
  979. ]
  980. }
  981. --------------------------------------------------
  982. [[gsub-processor]]
  983. === Gsub Processor
  984. Converts a string field by applying a regular expression and a replacement.
  985. If the field is not a string, the processor will throw an exception.
  986. [[gsub-options]]
  987. .Gsub Options
  988. [options="header"]
  989. |======
  990. | Name | Required | Default | Description
  991. | `field` | yes | - | The field to apply the replacement to
  992. | `pattern` | yes | - | The pattern to be replaced
  993. | `replacement` | yes | - | The string to replace the matching patterns with
  994. |======
  995. [source,js]
  996. --------------------------------------------------
  997. {
  998. "gsub": {
  999. "field": "field1",
  1000. "pattern": "\.",
  1001. "replacement": "-"
  1002. }
  1003. }
  1004. --------------------------------------------------
  1005. [[join-processor]]
  1006. === Join Processor
  1007. Joins each element of an array into a single string using a separator character between each element.
  1008. Throws an error when the field is not an array.
  1009. [[join-options]]
  1010. .Join Options
  1011. [options="header"]
  1012. |======
  1013. | Name | Required | Default | Description
  1014. | `field` | yes | - | The field to be separated
  1015. | `separator` | yes | - | The separator character
  1016. |======
  1017. [source,js]
  1018. --------------------------------------------------
  1019. {
  1020. "join": {
  1021. "field": "joined_array_field",
  1022. "separator": "-"
  1023. }
  1024. }
  1025. --------------------------------------------------
  1026. [[lowercase-processor]]
  1027. === Lowercase Processor
  1028. Converts a string to its lowercase equivalent.
  1029. [[lowercase-options]]
  1030. .Lowercase Options
  1031. [options="header"]
  1032. |======
  1033. | Name | Required | Default | Description
  1034. | `field` | yes | - | The field to make lowercase
  1035. |======
  1036. [source,js]
  1037. --------------------------------------------------
  1038. {
  1039. "lowercase": {
  1040. "field": "foo"
  1041. }
  1042. }
  1043. --------------------------------------------------
  1044. [[remove-processor]]
  1045. === Remove Processor
  1046. Removes an existing field. If the field doesn't exist, an exception will be thrown.
  1047. [[remove-options]]
  1048. .Remove Options
  1049. [options="header"]
  1050. |======
  1051. | Name | Required | Default | Description
  1052. | `field` | yes | - | The field to be removed
  1053. |======
  1054. [source,js]
  1055. --------------------------------------------------
  1056. {
  1057. "remove": {
  1058. "field": "foo"
  1059. }
  1060. }
  1061. --------------------------------------------------
  1062. [[rename-processor]]
  1063. === Rename Processor
  1064. Renames an existing field. If the field doesn't exist or the new name is already used, an exception will be thrown.
  1065. [[rename-options]]
  1066. .Rename Options
  1067. [options="header"]
  1068. |======
  1069. | Name | Required | Default | Description
  1070. | `field` | yes | - | The field to be renamed
  1071. | `target_field` | yes | - | The new name of the field
  1072. |======
  1073. [source,js]
  1074. --------------------------------------------------
  1075. {
  1076. "rename": {
  1077. "field": "foo",
  1078. "target_field": "foobar"
  1079. }
  1080. }
  1081. --------------------------------------------------
  1082. [[script-processor]]
  1083. === Script Processor
  1084. Allows inline, stored, and file scripts to be executed within ingest pipelines.
  1085. See <<modules-scripting-using, How to use scripts>> to learn more about writing scripts. The Script Processor
  1086. leverages caching of compiled scripts for improved performance. Since the
  1087. script specified within the processor is potentially re-compiled per document, it is important
  1088. to understand how script caching works. To learn more about
  1089. caching see <<modules-scripting-using-caching, Script Caching>>.
  1090. [[script-options]]
  1091. .Script Options
  1092. [options="header"]
  1093. |======
  1094. | Name | Required | Default | Description
  1095. | `field` | yes | - | The field to set
  1096. | `lang` | no | - | The scripting language
  1097. | `file` | no | - | The script file to refer to
  1098. | `id` | no | - | The stored script id to refer to
  1099. | `inline` | no | - | An inline script to be executed
  1100. |======
  1101. You can access the current ingest document from within the script context by using the `ctx` variable.
  1102. The following example sets a new field called `field_a_plus_b` to be the sum of two existing
  1103. numeric fields `field_a` and `field_b`:
  1104. [source,js]
  1105. --------------------------------------------------
  1106. {
  1107. "script": {
  1108. "field": "field_a_plus_b",
  1109. "lang": "painless",
  1110. "inline": "return ctx.field_a + ctx.field_b"
  1111. }
  1112. }
  1113. --------------------------------------------------
  1114. [[set-processor]]
  1115. === Set Processor
  1116. Sets one field and associates it with the specified value. If the field already exists,
  1117. its value will be replaced with the provided one.
  1118. [[set-options]]
  1119. .Set Options
  1120. [options="header"]
  1121. |======
  1122. | Name | Required | Default | Description
  1123. | `field` | yes | - | The field to insert, upsert, or update
  1124. | `value` | yes | - | The value to be set for the field
  1125. | `override`| no | true | If processor will update fields with pre-existing non-null-valued field. When set to `false`, such fields will not be touched.
  1126. |======
  1127. [source,js]
  1128. --------------------------------------------------
  1129. {
  1130. "set": {
  1131. "field": "field1",
  1132. "value": 582.1
  1133. }
  1134. }
  1135. --------------------------------------------------
  1136. [[split-processor]]
  1137. === Split Processor
  1138. Splits a field into an array using a separator character. Only works on string fields.
  1139. [[split-options]]
  1140. .Split Options
  1141. [options="header"]
  1142. |======
  1143. | Name | Required | Default | Description
  1144. | `field` | yes | - | The field to split
  1145. | `separator` | yes | - | A regex which matches the separator, eg `,` or `\s+`
  1146. |======
  1147. [source,js]
  1148. --------------------------------------------------
  1149. {
  1150. "split": {
  1151. "field": "my_field",
  1152. "separator": "\\s+" <1>
  1153. }
  1154. }
  1155. --------------------------------------------------
  1156. <1> Treat all consecutive whitespace characters as a single separator
  1157. [[sort-processor]]
  1158. === Sort Processor
  1159. Sorts the elements of an array ascending or descending. Homogeneous arrays of numbers will be sorted
  1160. numerically, while arrays of strings or heterogeneous arrays of strings + numbers will be sorted lexicographically.
  1161. Throws an error when the field is not an array.
  1162. [[sort-options]]
  1163. .Sort Options
  1164. [options="header"]
  1165. |======
  1166. | Name | Required | Default | Description
  1167. | `field` | yes | - | The field to be sorted
  1168. | `order` | no | `"asc"` | The sort order to use. Accepts `"asc"` or `"desc"`.
  1169. |======
  1170. [source,js]
  1171. --------------------------------------------------
  1172. {
  1173. "sort": {
  1174. "field": "field_to_sort",
  1175. "order": "desc"
  1176. }
  1177. }
  1178. --------------------------------------------------
  1179. [[trim-processor]]
  1180. === Trim Processor
  1181. Trims whitespace from field.
  1182. NOTE: This only works on leading and trailing whitespace.
  1183. [[trim-options]]
  1184. .Trim Options
  1185. [options="header"]
  1186. |======
  1187. | Name | Required | Default | Description
  1188. | `field` | yes | - | The string-valued field to trim whitespace from
  1189. |======
  1190. [source,js]
  1191. --------------------------------------------------
  1192. {
  1193. "trim": {
  1194. "field": "foo"
  1195. }
  1196. }
  1197. --------------------------------------------------
  1198. [[uppercase-processor]]
  1199. === Uppercase Processor
  1200. Converts a string to its uppercase equivalent.
  1201. [[uppercase-options]]
  1202. .Uppercase Options
  1203. [options="header"]
  1204. |======
  1205. | Name | Required | Default | Description
  1206. | `field` | yes | - | The field to make uppercase
  1207. |======
  1208. [source,js]
  1209. --------------------------------------------------
  1210. {
  1211. "uppercase": {
  1212. "field": "foo"
  1213. }
  1214. }
  1215. --------------------------------------------------