gpt4 book ai didi

elasticsearch - 将日期转换为字符串 Elasticsearch

转载 作者:行者123 更新时间:2023-12-02 22:46:17 25 4
gpt4 key购买 nike

我想从 flex 搜索中获取日期,我的映射就像-

"timeModified": 
{
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}

我在 flex 搜索中的数据存储是-
"timeModified": "2015-03-12T13:18:50.000+05:30"

我想从日期中获取年份。当我执行以下查询时-
{
"query" : {
"match_all": {}
},
"script_fields" : {
"left_field" : {
"script" : {
"inline": "doc.timeModified.value.substring(0, length)",
"params": {
"length": 4
}
}
}
}
}

它给我异常(exception)-

"No signature of method: java.lang.Long.substring() is applicable for argument types: (java.lang.Integer, java.lang.Integer) values: [0, 4]\nPossible solutions: toString(), toString(), toString(), toString(long, int)"



如果我可以选择在不更改实际映射类型的情况下将字段值日期转换为字符串,则可以得到正确的值。因此,请提出如何在 flex 搜索查询中将其转换为字符串。
或者,如果有其他选择来获取日期,则还建议。

最佳答案

您收到的错误是因为字段值是Long而不是String。但是,您也可以像这样直接访问date值:

{
"query" : {
"match_all": {}
},
"script_fields" : {
"left_field" : {
"script" : {
"inline": "doc.timeModified.date.getYear()"
}
}
}
}

关于elasticsearch - 将日期转换为字符串 Elasticsearch ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43543074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com