Date index name processor

The date_index_name processor is used to point documents to the correct time-based index based on the date or timestamp field within the document. The processor sets the _index metadata field to a date math index name expression. Then the processor fetches the date or timestamp from the field field in the document being processed and formats it into a date math index name expression. The extracted date, index_name_prefix value, and date_rounding value are then combined to create the date math index expression. For example, if the field field contains the value 2023-10-30T12:43:29.000Z and index_name_prefix is set to week_index- and date_rounding is set to w, then the date math index name expression is week_index-2023-10-30. You can use the date_formats field to specify how the date in the date math index expression should be formatted.

The following is the syntax for the date_index_name processor:

  1. {
  2. "date_index_name": {
  3. "field": "your_date_field or your_timestamp_field",
  4. "date_rounding": "rounding_value"
  5. }
  6. }

copy

Configuration parameters

The following table lists the required and optional parameters for the date_index_name processor.

ParameterRequired/OptionalDescription 
fieldRequiredThe date or timestamp field in the incoming document. Supports template snippets. 
date_roundingRequiredThe rounded date format within the index name . Valid values are y (year), M (month), w (week), d (day), h (hour), m (minute), and s (second). 
date_formatsOptionalAn array of date formats used to parse the date or timestamp field. Valid options include a java time pattern or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N. Default is yyyy-MM-dd’T’HH:mm:ss.SSSXX. 
index_name_formatOptionalThe date format. Default is yyyy-MM-dd. Supports template snippets. 
index_name_prefixOptionalThe index name prefix to append before the date. Supports template snippets. 
descriptionOptionalA brief description of the processor. 
ifOptionalA condition for running this processor. 
ignore_failureOptionalIf set to true, failures are ignored. Default is false. 
localelocaleOptionalThe locale to use when parsing the month name and week day of the date. Default is ENGLISH. Supports template snippets.
on_failureOptionalA list of processors to run if the processor fails. 
tagOptionalAn identifier tag for the processor. Useful for debugging to distinguish between processors of the same type. 
timezoneOptionalThe time zone to use when parsing the date. Default is UTC. 

Using the processor

Follow these steps to use the processor in a pipeline.

Step 1: Create a pipeline.

The following query creates a pipeline, named date-index-name1, that uses the date_index_name processor to index logs into monthly indexes:

  1. PUT /_ingest/pipeline/date-index-name1
  2. {
  3. "description": "Create weekly index pipeline",
  4. "processors": [
  5. {
  6. "date_index_name": {
  7. "field": "date_field",
  8. "index_name_prefix": "week_index-",
  9. "date_rounding": "w",
  10. "date_formats": ["YYYY-MM-DD"]
  11. }
  12. }
  13. ]
  14. }

copy

Step 2 (Optional): Test the pipeline.

It is recommended that you test your pipeline before you ingest documents.

To test the pipeline, run the following query:

  1. POST _ingest/pipeline/date-index-name1/_simulate
  2. {
  3. "docs": [
  4. {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source": {
  8. "date_field": "2023-10-30"
  9. }
  10. }
  11. ]
  12. }

copy

Response

The following example response confirms that the pipeline is working as expected:

  1. {
  2. "docs": [
  3. {
  4. "doc": {
  5. "_index": "<week_index-{2023-10-01||/w{yyyy-MM-dd|UTC}}>",
  6. "_id": "1",
  7. "_source": {
  8. "date_field": "2023-10-30"
  9. },
  10. "_ingest": {
  11. "timestamp": "2023-11-13T18:23:10.408593092Z"
  12. }
  13. }
  14. }
  15. ]
  16. }

Step 3: Ingest a document.

The following query ingests a document into an index named testindex1:

  1. PUT testindex1/_doc/1?pipeline=date-index-name1
  2. {
  3. "date_field": "2023-10-30"
  4. }

copy

Response

The request indexes the document into the index week_index-2023-10-23 and will index all documents with a timestamp within that week into the same index because the pipeline rounds by week.

  1. {
  2. "_index": "week_index-2023-10-30",
  3. "_id": "1",
  4. "_version": 4,
  5. "result": "updated",
  6. "_shards": {
  7. "total": 2,
  8. "successful": 1,
  9. "failed": 0
  10. },
  11. "_seq_no": 3,
  12. "_primary_term": 1
  13. }

Step 4 (Optional): Retrieve the document.

To retrieve the document, run the following query:

  1. GET week_index-2023-10-30/_doc/1

copy