elasticsearchHow can I store and query zoned datetime values in Elasticsearch?
Elasticsearch provides the ability to store and query zoned datetime values using the date
datatype. It is important to note that the date
datatype only supports ISO8601 formatted dates.
For example, to store a zoned datetime value of 2020-05-01T12:00:00+02:00
, you would use the following code:
PUT my_index/_doc/1
{
"my_date": "2020-05-01T12:00:00+02:00"
}
To query for the zoned datetime value, you would use the range
query:
GET my_index/_search
{
"query": {
"range": {
"my_date": {
"gte": "2020-05-01T12:00:00+02:00"
}
}
}
}
The output of the query should look like this:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"my_date": "2020-05-01T12:00:00+02:00"
}
}
]
}
}
In summary, storing and querying zoned datetime values in Elasticsearch can be done using the date
datatype and the range
query.
Helpful links
More of Elasticsearch
- How can I use Elasticsearch and ZFS together?
- How can I use elasticsearch zone awareness to improve my software development?
- How can I use Elasticsearch with Zammad?
- How can I use Elasticsearch and Zookeeper together to manage distributed applications?
- How can I use Elasticsearch to diagnose "yellow" issues?
- How can I use Yandex Mirror to access Elasticsearch data?
- How can I use Elasticsearch and Zabbix together for software development?
- How can I use Elasticsearch and Hunspell to add Russian language support to my software?
- How can I check the status of a yellow index in Elasticsearch?
- How do I set up an Elasticsearch Yum repository?
See more codes...