date-index-name.asciidoc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. [[date-index-name-processor]]
  2. === Date Index Name Processor
  3. The purpose of this processor is to point documents to the right time based index based
  4. on a date or timestamp field in a document by using the <<date-math-index-names, date math index name support>>.
  5. The processor sets the `_index` meta field with a date math index name expression based on the provided index name
  6. prefix, a date or timestamp field in the documents being processed and the provided date rounding.
  7. First, this processor fetches the date or timestamp from a field in the document being processed. Optionally,
  8. date formatting can be configured on how the field's value should be parsed into a date. Then this date,
  9. the provided index name prefix and the provided date rounding get formatted into a date math index name expression.
  10. Also here optionally date formatting can be specified on how the date should be formatted into a date math index name
  11. expression.
  12. An example pipeline that points documents to a monthly index that starts with a `myindex-` prefix based on a
  13. date in the `date1` field:
  14. [source,js]
  15. --------------------------------------------------
  16. PUT _ingest/pipeline/monthlyindex
  17. {
  18. "description": "monthly date-time index naming",
  19. "processors" : [
  20. {
  21. "date_index_name" : {
  22. "field" : "date1",
  23. "index_name_prefix" : "myindex-",
  24. "date_rounding" : "M"
  25. }
  26. }
  27. ]
  28. }
  29. --------------------------------------------------
  30. // CONSOLE
  31. Using that pipeline for an index request:
  32. [source,js]
  33. --------------------------------------------------
  34. PUT /myindex/_doc/1?pipeline=monthlyindex
  35. {
  36. "date1" : "2016-04-25T12:02:01.789Z"
  37. }
  38. --------------------------------------------------
  39. // CONSOLE
  40. // TEST[continued]
  41. [source,js]
  42. --------------------------------------------------
  43. {
  44. "_index" : "myindex-2016-04-01",
  45. "_type" : "_doc",
  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 `myindex` index, but into the `myindex-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 `myindex-2016-04-01` we can inspect the effects of the processor using a simulate request.
  63. [source,js]
  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" : "myindex-",
  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. // CONSOLE
  90. and the result:
  91. [source,js]
  92. --------------------------------------------------
  93. {
  94. "docs" : [
  95. {
  96. "doc" : {
  97. "_id" : "_id",
  98. "_index" : "<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>",
  99. "_type" : "_type",
  100. "_source" : {
  101. "date1" : "2016-04-25T12:02:01.789Z"
  102. },
  103. "_ingest" : {
  104. "timestamp" : "2016-11-08T19:43:03.850+0000"
  105. }
  106. }
  107. }
  108. ]
  109. }
  110. --------------------------------------------------
  111. // TESTRESPONSE[s/2016-11-08T19:43:03.850\+0000/$body.docs.0.doc._ingest.timestamp/]
  112. The above example shows that `_index` was set to `<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>`. Elasticsearch
  113. understands this to mean `2016-04-01` as is explained in the <<date-math-index-names, date math index name documentation>>
  114. [[date-index-name-options]]
  115. .Date index name options
  116. [options="header"]
  117. |======
  118. | Name | Required | Default | Description
  119. | `field` | yes | - | The field to get the date or timestamp from.
  120. | `index_name_prefix` | no | - | A prefix of the index name to be prepended before the printed date. Supports <<accessing-template-fields,template snippets>>.
  121. | `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>>.
  122. | `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.
  123. | `timezone` | no | UTC | The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names.
  124. | `locale` | no | ENGLISH | The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days.
  125. | `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>>.
  126. include::common-options.asciidoc[]
  127. |======