date-index-name.asciidoc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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,console]
  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. Using that pipeline for an index request:
  31. [source,console]
  32. --------------------------------------------------
  33. PUT /myindex/_doc/1?pipeline=monthlyindex
  34. {
  35. "date1" : "2016-04-25T12:02:01.789Z"
  36. }
  37. --------------------------------------------------
  38. // TEST[continued]
  39. [source,console-result]
  40. --------------------------------------------------
  41. {
  42. "_index" : "myindex-2016-04-01",
  43. "_type" : "_doc",
  44. "_id" : "1",
  45. "_version" : 1,
  46. "result" : "created",
  47. "_shards" : {
  48. "total" : 2,
  49. "successful" : 1,
  50. "failed" : 0
  51. },
  52. "_seq_no" : 55,
  53. "_primary_term" : 1
  54. }
  55. --------------------------------------------------
  56. // TESTRESPONSE[s/"_seq_no" : \d+/"_seq_no" : $body._seq_no/ s/"_primary_term" : 1/"_primary_term" : $body._primary_term/]
  57. The above request will not index this document into the `myindex` index, but into the `myindex-2016-04-01` index because
  58. it was rounded by month. This is because the date-index-name-processor overrides the `_index` property of the document.
  59. To see the date-math value of the index supplied in the actual index request which resulted in the above document being
  60. indexed into `myindex-2016-04-01` we can inspect the effects of the processor using a simulate request.
  61. [source,console]
  62. --------------------------------------------------
  63. POST _ingest/pipeline/_simulate
  64. {
  65. "pipeline" :
  66. {
  67. "description": "monthly date-time index naming",
  68. "processors" : [
  69. {
  70. "date_index_name" : {
  71. "field" : "date1",
  72. "index_name_prefix" : "myindex-",
  73. "date_rounding" : "M"
  74. }
  75. }
  76. ]
  77. },
  78. "docs": [
  79. {
  80. "_source": {
  81. "date1": "2016-04-25T12:02:01.789Z"
  82. }
  83. }
  84. ]
  85. }
  86. --------------------------------------------------
  87. and the result:
  88. [source,console-result]
  89. --------------------------------------------------
  90. {
  91. "docs" : [
  92. {
  93. "doc" : {
  94. "_id" : "_id",
  95. "_index" : "<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>",
  96. "_type" : "_doc",
  97. "_source" : {
  98. "date1" : "2016-04-25T12:02:01.789Z"
  99. },
  100. "_ingest" : {
  101. "timestamp" : "2016-11-08T19:43:03.850+0000"
  102. }
  103. }
  104. }
  105. ]
  106. }
  107. --------------------------------------------------
  108. // TESTRESPONSE[s/2016-11-08T19:43:03.850\+0000/$body.docs.0.doc._ingest.timestamp/]
  109. The above example shows that `_index` was set to `<myindex-{2016-04-25||/M{yyyy-MM-dd|UTC}}>`. Elasticsearch
  110. understands this to mean `2016-04-01` as is explained in the <<date-math-index-names, date math index name documentation>>
  111. [[date-index-name-options]]
  112. .Date index name options
  113. [options="header"]
  114. |======
  115. | Name | Required | Default | Description
  116. | `field` | yes | - | The field to get the date or timestamp from.
  117. | `index_name_prefix` | no | - | A prefix of the index name to be prepended before the printed date. Supports <<accessing-template-fields,template snippets>>.
  118. | `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>>.
  119. | `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.
  120. | `timezone` | no | UTC | The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names.
  121. | `locale` | no | ENGLISH | The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days.
  122. | `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 <<accessing-template-fields,template snippets>>.
  123. include::common-options.asciidoc[]
  124. |======