|
| 1 | +[[date-index-name-processor]] |
| 2 | +=== Date Index Name Processor |
| 3 | + |
| 4 | +The purpose of this processor is to point documents to the right time based index based |
| 5 | +on a date or timestamp field in a document by using the <<date-math-index-names, date math index name support>>. |
| 6 | + |
| 7 | +The processor sets the `_index` meta field with a date math index name expression based on the provided index name |
| 8 | +prefix, a date or timestamp field in the documents being processed and the provided date rounding. |
| 9 | + |
| 10 | +First, this processor fetches the date or timestamp from a field in the document being processed. Optionally, |
| 11 | +date formatting can be configured on how the field's value should be parsed into a date. Then this date, |
| 12 | +the provided index name prefix and the provided date rounding get formatted into a date math index name expression. |
| 13 | +Also here optionally date formatting can be specified on how the date should be formatted into a date math index name |
| 14 | +expression. |
| 15 | + |
| 16 | +An example pipeline that points documents to a monthly index that starts with a `myindex-` prefix based on a |
| 17 | +date in the `date1` field: |
| 18 | + |
| 19 | +[source,js] |
| 20 | +-------------------------------------------------- |
| 21 | +PUT _ingest/pipeline/monthlyindex |
| 22 | +{ |
| 23 | + "description": "monthly date-time index naming", |
| 24 | + "processors" : [ |
| 25 | + { |
| 26 | + "date_index_name" : { |
| 27 | + "field" : "date1", |
| 28 | + "index_name_prefix" : "myindex-", |
| 29 | + "date_rounding" : "M" |
| 30 | + } |
| 31 | + } |
| 32 | + ] |
| 33 | +} |
| 34 | +-------------------------------------------------- |
| 35 | +// CONSOLE |
| 36 | + |
| 37 | + |
| 38 | +Using that pipeline for an index request: |
| 39 | + |
| 40 | +[source,js] |
| 41 | +-------------------------------------------------- |
| 42 | +PUT /myindex/_doc/1?pipeline=monthlyindex |
| 43 | +{ |
| 44 | + "date1" : "2016-04-25T12:02:01.789Z" |
| 45 | +} |
| 46 | +-------------------------------------------------- |
| 47 | +// CONSOLE |
| 48 | +// TEST[continued] |
| 49 | + |
| 50 | +[source,js] |
| 51 | +-------------------------------------------------- |
| 52 | +{ |
| 53 | + "_index" : "myindex-2016-04-01", |
| 54 | + "_type" : "_doc", |
| 55 | + "_id" : "1", |
| 56 | + "_version" : 1, |
| 57 | + "result" : "created", |
| 58 | + "_shards" : { |
| 59 | + "total" : 2, |
| 60 | + "successful" : 1, |
| 61 | + "failed" : 0 |
| 62 | + }, |
| 63 | + "_seq_no" : 55, |
| 64 | + "_primary_term" : 1 |
| 65 | +} |
| 66 | +-------------------------------------------------- |
| 67 | +// TESTRESPONSE[s/"_seq_no" : \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/] |
| 68 | + |
| 69 | + |
| 70 | +The above request will not index this document into the `myindex` index, but into the `myindex-2016-04-01` index because |
| 71 | +it was rounded by month. This is because the date-index-name-processor overrides the `_index` property of the document. |
| 72 | + |
| 73 | +To see the date-math value of the index supplied in the actual index request which resulted in the above document being |
| 74 | +indexed into `myindex-2016-04-01` we can inspect the effects of the processor using a simulate request. |
| 75 | + |
| 76 | + |
| 77 | +[source,js] |
| 78 | +-------------------------------------------------- |
| 79 | +POST _ingest/pipeline/_simulate |
| 80 | +{ |
| 81 | + "pipeline" : |
| 82 | + { |
| 83 | + "description": "monthly date-time index naming", |
| 84 | + "processors" : [ |
| 85 | + { |
| 86 | + "date_index_name" : { |
| 87 | + "field" : "date1", |
| 88 | + "index_name_prefix" : "myindex-", |
| 89 | + "date_rounding" : "M" |
| 90 | + } |
| 91 | + } |
| 92 | + ] |
| 93 | + }, |
| 94 | + "docs": [ |
| 95 | + { |
| 96 | + "_source": { |
| 97 | + "date1": "2016-04-25T12:02:01.789Z" |
| 98 | + } |
| 99 | + } |
| 100 | + ] |
| 101 | +} |
| 102 | +-------------------------------------------------- |
| 103 | +// CONSOLE |
| 104 | + |
| 105 | +and the result: |
| 106 | + |
| 107 | +[source,js] |
| 108 | +-------------------------------------------------- |
| 109 | +{ |
| 110 | + "docs" : [ |
| 111 | + { |
| 112 | + "doc" : { |
| 113 | + "_id" : "_id", |
| 114 | + "_index" : "<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>", |
| 115 | + "_type" : "_type", |
| 116 | + "_source" : { |
| 117 | + "date1" : "2016-04-25T12:02:01.789Z" |
| 118 | + }, |
| 119 | + "_ingest" : { |
| 120 | + "timestamp" : "2016-11-08T19:43:03.850+0000" |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + ] |
| 125 | +} |
| 126 | +-------------------------------------------------- |
| 127 | +// TESTRESPONSE[s/2016-11-08T19:43:03.850\+0000/$body.docs.0.doc._ingest.timestamp/] |
| 128 | + |
| 129 | +The above example shows that `_index` was set to `<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>`. Elasticsearch |
| 130 | +understands this to mean `2016-04-01` as is explained in the <<date-math-index-names, date math index name documentation>> |
| 131 | + |
| 132 | +[[date-index-name-options]] |
| 133 | +.Date index name options |
| 134 | +[options="header"] |
| 135 | +|====== |
| 136 | +| Name | Required | Default | Description |
| 137 | +| `field` | yes | - | The field to get the date or timestamp from. |
| 138 | +| `index_name_prefix` | no | - | A prefix of the index name to be prepended before the printed date. Supports <<accessing-template-fields,template snippets>>. |
| 139 | +| `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). Supports <<accessing-template-fields,template snippets>>. |
| 140 | +| `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. |
| 141 | +| `timezone` | no | UTC | The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names. |
| 142 | +| `locale` | no | ENGLISH | The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days. |
| 143 | +| `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. Supports <<accessing-template-fields,template snippets>>. |
| 144 | +include::common-options.asciidoc[] |
| 145 | +|====== |
0 commit comments