date-index-name.asciidoc 5.6 KB

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