This version of the OpenSearch documentation is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.

Date

The date processor is used to parse dates from document fields and to add the parsed data to a new field. By default, the parsed data is stored in the @timestamp field. The following is the syntax for the date processor:

  1. {
  2. "date": {
  3. "field": "date_field",
  4. "formats": ["yyyy-MM-dd'T'HH:mm:ss.SSSZZ"]
  5. }
  6. }

copy

Configuration parameters

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

ParameterRequiredDescription
fieldRequiredThe name of the field to which the data should be converted. Supports template snippets.
formatsRequiredAn array of the expected date formats. Can be a date format or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N.
descriptionOptionalA brief description of the processor.
ifOptionalA condition for running this processor.
ignore_failureOptionalIf set to true, failures are ignored. Default is false.
localeOptionalThe locale to use when parsing the date. Default is ENGLISH. Supports template snippets.
on_failureOptionalA list of processors to run if the processor fails.
output_formatOptionalThe date format to use for the target field. Default is yyyy-MM-dd’T’HH:mm:ss.SSSZZ.
tagOptionalAn identifier tag for the processor. Useful for debugging to distinguish between processors of the same type.
target_fieldOptionalThe name of the field in which to store the parsed data. Default target field is @timestamp.
timezoneOptionalThe time zone to use when parsing the date. Default is UTC. Supports template snippets.

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-output-format, that uses the date processor to convert from European date format to US date format, adding the new field date_us with the desired output_format:

  1. PUT /_ingest/pipeline/date-output-format
  2. {
  3. "description": "Pipeline that converts European date format to US date format",
  4. "processors": [
  5. {
  6. "date": {
  7. "field" : "date_european",
  8. "formats" : ["dd/MM/yyyy", "UNIX"],
  9. "target_field": "date_us",
  10. "output_format": "MM/dd/yyy",
  11. "timezone" : "UTC"
  12. }
  13. }
  14. ]
  15. }

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-output-format/_simulate
  2. {
  3. "docs": [
  4. {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source": {
  8. "date_us": "06/30/2023",
  9. "date_european": "30/06/2023"
  10. }
  11. }
  12. ]
  13. }

copy

Response

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

  1. {
  2. "docs": [
  3. {
  4. "doc": {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source": {
  8. "date_us": "06/30/2023",
  9. "date_european": "30/06/2023"
  10. },
  11. "_ingest": {
  12. "timestamp": "2023-08-22T17:08:46.275195504Z"
  13. }
  14. }
  15. }
  16. ]
  17. }

Step 3: Ingest a document.

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

  1. PUT testindex1/_doc/1?pipeline=date-output-format
  2. {
  3. "date_european": "30/06/2023"
  4. }

copy

Step 4 (Optional): Retrieve the document.

To retrieve the document, run the following query:

  1. GET testindex1/_doc/1

copy