# Elasticsearch7.9 How to write data in the form yyyy-MM-dd HH:mm:ss.SSSSSS

**URL:** <https://discuss.elastic.co/t/elasticsearch7-9-how-to-write-data-in-the-form-yyyy-mm-dd-hhss-ssssss/280486>\
**Category:** Elasticsearch\
**Created:** [August 5, 2021, 3:14am UTC](https://discuss.elastic.co/t/elasticsearch7-9-how-to-write-data-in-the-form-yyyy-mm-dd-hhss-ssssss/280486 "2021-08-05T03:14:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![qracle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qracle/32/92559_2.png) [@qracle](https://discuss.elastic.co/u/qracle)\
**Post date:** [August 5, 2021, 3:14am UTC](https://discuss.elastic.co/t/elasticsearch7-9-how-to-write-data-in-the-form-yyyy-mm-dd-hhss-ssssss/280486/1 "2021-08-05T03:14:06Z")

</div>

# es version：7.9

### script 1：

```auto
PUT _template/test_template
{
  "index_patterns": ["test_index*"],
  "settings": {
    "index" : {
      "max_result_window" : "10000",
      "number_of_shards" : "1",
      "number_of_replicas" : "1"
    }
  },
  "mappings": {
    "date_detection": true,
    "dynamic_date_formats": [
      "strict_date_optional_time", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss.SSSSSS"
    ],
    "dynamic_templates": [
      {
        "pattern_as_keyword": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "keyword",
            "norms": false
          }
        }
      },
      {
        "pattern_as_date": {
          "match_pattern": "regex",
          "match": "^.*?[T|t]ime|[D|d]ate$",
          "mapping": {
            "type": "date",
            "format": [
              "strict_date_optional_time", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss.SSSSSS"
            ],
            "norms": false
          }
        }
      },
      {
        "pattern_as_object": {
          "match_pattern": "regex",
          "match": "^.*?[J|j]son|[I|i]nfo$",
          "mapping": {
            "type": "object",
            "norms": false
          }
        }
      },
      {
        "pattern_as_nested": {
          "match_pattern": "regex",
          "match": "^.*?[L|l]ist$",
          "mapping": {
            "type": "nested",
            "norms": false
          }
        }
      },
      {
        "pattern_as_integer": {
          "match_pattern": "regex",
          "match": "^.*?[S|s]tatus$",
          "mapping": {
            "type": "integer",
            "norms": false
          }
        }
      },
      {
        "pattern_as_long": {
          "match_pattern": "regex",
          "match": "^.*?[A|a]mount|[A|a]mt$",
          "mapping": {
            "type": "long",
            "norms": false
          }
        }
      },
      {
        "pattern_as_decimal1": {
          "match_pattern": "regex",
          "match": "^.*?[F|f]ee$",
          "mapping": {
            "type": "scaled_float",
            "scaling_factor": 100,
            "norms": false
          }
        }
      },
      {
        "pattern_as_decimal2": {
          "match_pattern": "regex",
          "match": "^.*?[R|r]ate$",
          "mapping": {
            "type": "double",
            "norms": false
          }
        }
      }
    ],
    "properties": {

    }
  }
}

```

### script 2：

```auto
PUT test_index_1
{
  "orderDate": "2021-08-01",
  "createTime": "2021-08-01 00:30:15",
  "modifiedTime": "2021-08-01 00:30:15.245",
  "finishTime": "2021-08-01 00:30:15.245666",
  "orderTime": 1593306078000,
  "extraInfo": {
    "name": "Bob",
    "age": 12,
    "isMale": true
  },
  "rate": 12.4321344612,
  "orderAmount": 432145,
  "txnFee": 1234.43,
  "merchantName": null,
  "txnStatus": 1
}

```

### error message 1：

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "parse_exception",
        "reason" : "unknown key [modifiedTime] for create index"
      }
    ],
    "type" : "parse_exception",
    "reason" : "unknown key [modifiedTime] for create index"
  },
  "status" : 400
}

```

### error message 2：

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Epoch [epoch_millis] is not supported as dynamic date format"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: Epoch [epoch_millis] is not supported as dynamic date format",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "Epoch [epoch_millis] is not supported as dynamic date format"
    }
  },
  "status" : 400
}

```

### question:

- How can I adjust the Dynamic Template (script 1) to ensure that the data in the script 2 can be written properly?
- If I add epoch\_millis to the dynamic\_date\_formats, it will respond error message 2.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 2, 2021, 3:14am UTC](https://discuss.elastic.co/t/elasticsearch7-9-how-to-write-data-in-the-form-yyyy-mm-dd-hhss-ssssss/280486/2 "2021-09-02T03:14:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
