我的索引有一个日期字段,格式为2020-01-04T05:00:06.870000Z
. 在 ES 查询响应中,我需要表单中的日期yyyyMMdd
,所以20200104
. 我尝试使用脚本查询并分别提取日、月和年。我怎样才能将它们连接起来_source
以获得number
表格yyyyMMdd
?
样本数据 :
"_source": {
"updated": "2020-01-04T05:00:06.870000Z"
}
"_source": {
"updated": "2020-01-04T09:00:08.870000Z"
}
"_source": {
"updated": "2019-12-04T01:00:06.870000Z"
}
}
询问:
"sort" : [
{
"_script": {
"type": "number",
"script": {
"lang": "painless",
"source": "doc['updated'].value.getYear()"
//similarly use getMonthOfYear() and getDayOfMonth(). How to concatenate and convert to number ?
},
"order": "desc"
}
}
]