Elasticsearch- Date Type

Elasticsearch- Date Type

date type for storing dates and times. It works like this: usually a string representation of the date, for example, 2019-06-25T22: 47. Then, ES parsing the string, then as long a Lucene index values stored. The long-type value is the number of milliseconds from the time provided between January 1, 1970 00:00:00 UTC (UNIX epoch) has elapsed.
When the search of the document, still provide a string date will parse these strings in the background in numerical ES and handled. The reason for this is compared to the string and, when the value stored and processed faster.
date string data format is defined by a format option, ES default resolution timestamp to ISO 8601.
ISO8601 is an international standard for the exchange of date and time data, as RFC 3339 and widely used in the timestamp. Zhang ISO 8601 date below this:

2019 - 06 -25T22: 51 : 45,453 - 03 : 00

Comprising the sub-second and time zone.


Using the format option to specify the date format when there are two options
(1) using a pre-defined time format. For example, date format parsing such date 2019-06-25.
(2) Set your own custom format. You can specify a timestamp pattern followed. For example, to resolve jun 2019 specifies MMMYYYY this date. 

Use custom time format

Customized version of: 'MMM DD YYYY'
in the album index type of music, adding a new attribute mapping, type date, format custom

curl -XPUT 'localhost:9200/music/_mapping/album' -d '{
    "album":{
        "properties":{
            "format_date":{
                "type":"date",
                "format":"MMM DD YYYY"
            }
        }
    }
}'

 

A new data

curl -XPUT 'localhost:9200/music/album/4' -d '{
"name":"十一月的肖邦",
"date":"2005-11-24T22:20",
"format_date":"Nov 24 2005"
}'

 

Guess you like

Origin www.cnblogs.com/EnzoDin/p/11094379.html