【发布时间】:2021-06-19 03:10:21
【问题描述】:
当我尝试从时间戳中获取毫秒时,Elasticsearch 返回舍入值(使用 docker.elastic.co/elasticsearch/elasticsearch:7.11.0 图像)。
我的映射:
{
"mappings": {
"properties": {
...
"updated_at": {
"type": "date"
}
...
}
}
}
我的脚本查询:
{
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "doc['updated_at'].value.millis"
}
}
}
}
结果:
{
...
"hits": {
...
"max_score": 1616185130000,
"hits": [
{
...
"_score": 1616185130000, <---- wrong value
"_source": {
...
"updated_at": 1616185148409 <---- should be this
}
},
{
...
"_score": 1616185130000, <---- same wrong value even if updated_at is different
"_source": {
...
"updated_at": 1616185148408 <---- should be this
}
}
...
还尝试使用长类型的映射:
{
"mappings": {
"properties": {
...
"updated_at": {
"type": "long"
}
...
}
}
}
查询:
{
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "doc['updated_at'].value"
}
}
}
}
得到了同样的结果。
我不能使用排序,因为我们需要通过公式来提升,我坚持这个问题。
【问题讨论】:
-
您能否显示您在
_source文档中的updated_at值? -
@Val 它们出现在结果中:1616185148408, 1616185148409
-
我只是想确保您索引这些确切的值,而不是日期字符串,对吧?
-
@Val 是的,你是对的,我把数字放在了索引中
标签: elasticsearch elasticsearch-painless