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

es version:7.9

script 1:

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:

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:

{
  "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:

{
  "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.

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