• ES 日期格式处理


    ES 日期格式处理

    ES 中使用动态模板关于处理日期格式问题


    一、ES 动态模板一

    这里是把所有的日志格式字段格式化为 yyyy-MM-dd HH:mm:ss
    举例:
    2023-09-04 保存到es变成 2023-09-04 00:00:00
    2023-09-04 10:00:00 保存到es变成 22023-09-04 10:00:00

    PUT /_template/test_template
    {
      "order": 0,
      # 那些索引需要用到模板,多个逗号分隔
      "index_patterns": [
        "abcdefg","hijkl"
      ],
      "settings": {},
      "mappings": {
        "dynamic_date_formats": "date_optional_time||strict_date_optional_time||yyyy-MM-dd HH:mm:ss",
        "dynamic_templates": [
          {
            "date_fields": {
                "mapping": {
                  "format": "yyyy-MM-dd HH:mm:ss",
                  "ignore_malformed": true,
                  "type": "date"
                },
                "match_mapping_type": "date",
                "match": "*"
              }
          },
          {
            "my_template_string": {
              "match_mapping_type": "string",
              "mapping": {
                "type": "keyword"
              }
            }
          }
        ]
      },
      "aliases": {}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    二、Es 动态模板二

    这里是保留日期的原来格式
    举例:
    2023-09-04 保存到es变成 2023-09-04
    2023-09-04 10:00:00 保存到es变成 22023-09-04 10:00:00

    PUT /_template/test_template2
    {
      "order" : 0,
        # 那些索引需要用到模板,多个逗号分隔
        "index_patterns" : [
          "xxxxxx"
        ],
        "settings" : { },
        "mappings" : {
          "dynamic_date_formats" : "date_optional_time||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
          "dynamic_templates" : [
            {
              "date_fields" : {
                "mapping" : {
                  "format" : "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_second",
                  "ignore_malformed" : true,
                  "type" : "date"
                },
                "match_mapping_type" : "date",
                "match" : "*"
              }
            },
            {
              "my_template_string" : {
                "mapping" : {
                  "type" : "keyword"
                },
                "match_mapping_type" : "string"
              }
            }
          ]
        },
        "aliases" : { }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
  • 相关阅读:
    es集群、
    适合初学者学习课程课题设计javaweb超级简单图书管理系统基于servlet基础开发
    APS智能排产在造纸行业的应用
    重装系统后新建文本文档打不开怎么办
    leetcode刷题日记:141. Linked List Cycle(环形链表)
    登录/注册
    k8s CRD相关
    Error: [vuex] do not mutate vuex store state outside mutation handlers.
    Electron实战之环境搭建
    select实现服务器并发
  • 原文地址:https://blog.csdn.net/qq_36611929/article/details/132567334