問題描述
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 user13145920、Joe ‑ ElasticsearchBook.com、Tom Elias)