【问题标题】:Elasticsearch custom date time format incl. ordinal numbersElasticsearch 自定义日期时间格式,包括。序数
【发布时间】:2021-05-15 07:30:43
【问题描述】:

我需要在我的索引中为date 字段定义format

{
  "mappings": {
    "properties": {
      "date": {
        "type": "date",
        "format": "???"
      }
    }
  }
}

覆盖February 10th 2021, 23:59:58.556 等值。

我尝试了MMMM DD YYYY, HH:mm:ss.SSS,但它不起作用。

【问题讨论】:

    标签: elasticsearch datetime-format elasticsearch-mapping elasticsearch-date


    【解决方案1】:

    执行以下操作:

    {
      "mappings": {
        "properties": {
          "date": {
            "type": "date",
            "format": "MMMM dd['st']['nd']['rd']['th'] yyyy', 'HH:mm:ss.SSS"
          }
        }
      }
    }
    

    [] 表示可选部分,'' 表示文字部分。所以该模式表示当天的数字后面可能跟有stndrdth

    需要', ' 标记来覆盖分隔 日期时间 的逗号 + 空格。

    【讨论】:

      【解决方案2】:

      看这里:Documentation

      例如:

      PUT 
      {
        "mappings": {
          "properties": {
            "my_special_date_field": {
              "type":   "date",
              "format": "yyyy-MM-dd HH:mm:ss"
            }
          }
        }
      }
      

      所有内置格式的列表:built-in formats

      【讨论】:

      • 格式不正确failed to parse date field [February 10th 2021 , 23:59:58.556] with format [yyyy-MM-dd HH:mm:ss]
      • 啊,您的意思是您想要适合您输入的确切格式?检查第二个链接,我也会查看它。
      • 是的,我需要February 10th 2021 , 23:59:58.556 的格式我在您的链接中没有找到答案
      • 我看到的最接近的是 RFC_1123_DATE_TIME: docs.oracle.com/javase/8/docs/api/java/time/format/…,文档说它是受支持的。
      • 但是我怎样才能以mm-yyyy 的格式写出来呢?我无法将RFC_1123_DATE_TIME 格式化
      猜你喜欢
      • 2011-04-11
      • 2022-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      相关资源
      最近更新 更多