Elasticsearch 自定義日期時間格式,包括。序數 (Elasticsearch custom date time format incl. ordinal numbers)


問題描述

Elasticsearch 自定義日期時間格式,包括。序數 (Elasticsearch custom date time format incl. ordinal numbers)

我需要為我的索引中的 date 字段定義 format

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

以涵蓋像 February 10th 2021, 23 這樣的值:59:58.556.

我試過 MMMM DD YYYY, HH:mm:ss.SSS 但它不起作用。


參考解法

方法 1:

Go with the following:

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

[] denotes optional parts and '' denotes literal parts. So the pattern says that the number of the day may be followed by st, nd, rd or th.

The ', ' token is needed to cover the comma + whitespace separating the date from the time.

方法 2:

look here: Documentation

for example:

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

a list of all the built‑in formats: built‑in formats

(by user13145920Joe ‑ ElasticsearchBook.comTom Elias)

參考文件

  1. Elasticsearch custom date time format incl. ordinal numbers (CC BY‑SA 2.5/3.0/4.0)

#datetime-format #elasticsearch-date #elasticsearch #elasticsearch-mapping






相關問題

給定一個 DateTime 對象,如何獲取字符串格式的 ISO 8601 日期? (Given a DateTime object, how do I get an ISO 8601 date in string format?)

Праграма WPF наладжвае кароткую дату пры выкарыстанні stringformat={}{0:d} (WPF application customize shortdate when using stringformat={}{0:d})

使用 java.time.DateTimeFormatter 格式化 java Date,包括時間偏移 (Formating java Date with java.time.DateTimeFormatter including time offset)

# 如何使用 DateTime 類(處理轉換、格式、差異和時區) (# How to use the DateTime class (Dealing with Conversions, Formatting, Diffs, and Time zones))

從一種時間格式轉換為另一種時間格式 (Converting from one time format to the other)

如何將python中的數據框列對象轉換為日期時間格式 (How to convert a dataframe column object in python to date time format)

BeautifulSoup:如何以 datwtime 格式獲取 youtube 視頻的發布日期時間? (BeautifulSoup: How to get publish datetime of a youtube video in datwtime format?)

如何在 C# 中轉換 dateTime 格式? (How do I convert dateTime format in C#?)

在 SQL 中的時間範圍之間獲取記錄的替代方法(計算財政年度) (Alternative ways to get records between a time frame in SQL (calculate fiscal year))

Elasticsearch 自定義日期時間格式,包括。序數 (Elasticsearch custom date time format incl. ordinal numbers)

我有一個 int 格式的日期 DDMMYYYY,我怎樣才能分隔日月年 (I have a date in int format DDMMYYYY, how can I separate day and month and year)

Intl.DateTimeFormat 中 dayPeriod 的參考 (Reference for dayPeriod in Intl.DateTimeFormat)







留言討論