是否可以以HH:mm之类的格式保存弹性搜索中的时间字段,然后基于HH:mm-HH:mm之类的时间查询范围进行搜索?
答案 0 :(得分:2)
是的,您可以使用这种格式将时间存储在弹性文件中,在此处查看有关不同日期格式的相关文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html
hour_minute or strict_hour_minute
A formatter for a two digit hour of day and two digit minute of hour: HH:mm.
如果使用以下格式的构建,您将具有这样的映射:
PUT my_index
{
"mappings": {
"properties": {
"date": {
"type": "date",
"format": "hour_minute"
}
}
}
}
要进行搜索,您可以在范围查询中使用构建格式。
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
GET /_search
{
"query": {
"range" : {
"age" : {
"gte" : "10:15",
"lte" : "20:13",
"format" : "hour_minute"
}
}
}
}