Groovy脚本弹性搜索的日期差异 [英] Date Difference with Groovy Script Elastic Search
本文介绍了Groovy脚本弹性搜索的日期差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下代码基于嵌入式Groovy脚本创建排序.
I am trying to create a Sort based on an inline Groovy Script with following code.
基本上是尝试从当前时间减去日期字段,然后使用返回的差异对其进行排序.
Basically trying to minus a date field with current time and sort it using the returned difference.
"sort": [
{
"_script": {
"script": "DateTime date = new DateTime(doc['enddate'].value); return date.minus(date , '2016-08-12T12:24:03');",
"type": "number",
"order": "asc"
}
}]
但是这种方法不正确.
推荐答案
您可以尝试
{
"sort": [
{
"_script": {
"script": "DateTime.now().millis - doc.enddate.date.millis",
"type": "number",
"order": "asc"
}
}
]
}
这篇关于Groovy脚本弹性搜索的日期差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文