我可以强制ES以epoch_millis格式返回日期吗? [英] Can I force ES to return dates in epoch_millis format?
问题描述
我有此字段映射
"time": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
'm使用以下过滤器查询文档:
and I'm querying documents with this filter:
"range": {
"time": {
"gt": "1473157500000",
"lte": "1473158700000",
"format": "epoch_millis"
}
此方法有效并返回文档,但结果以不同的格式显示时间字段:
this works and returns documents, but the result show the time field in a different format:
"time": "2016-09-06T10:25:23.678",
是否可以强制在epoch_millis中返回查询?
Is it possible to force queries to be returned in epoch_millis?
推荐答案
_source
始终返回原始文档中的数据。
理想情况下,我认为将 _source
数据转换为desi可能更可取,更灵活
但是对于上述用例,您可以使用 fielddata_fields
。
The _source
always returns the data in the original document.
Ideally I feel it maybe more desirable and flexible to convert the _source
data to the desired format for presentation or otherwise on the client end.
However for the above use case you could use fielddata_fields
.
fielddata_fields 将以字段数据实际存储的格式返回字段,如果 date
字段恰好是 epoch_millis
。
fielddata_fields would return fields in the format of how the field-data is actually stored which in case of date
field happens to be epoch_millis
.
来自文档:
允许返回字段的字段数据表示形式对于每个命中
字段数据字段可以在未存储的字段上工作。了解
很重要,因为使用fielddata_fields参数将使
将该字段的条件加载到内存中(缓存),这会导致更多的内存消耗。
Allows to return the field data representation of a field for each hit Field data fields can work on fields that are not stored. It’s important to understand that using the fielddata_fields parameter will cause the terms for that field to be loaded to memory (cached), which will result in more memory consumption.
示例:
post <index>/_search
{
"fielddata_fields": [
"time"
]
}
这篇关于我可以强制ES以epoch_millis格式返回日期吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!