ingest-node.asciidoc 43 KB

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