[英]How to calculate day difference between today's date and date from doc but eliminating time from it in scripts of elastic search
I tried this solution and it works but it takes time stamp also....I want to eliminate time stamp...我试过这个解决方案,它有效,但它也需要时间戳......我想消除时间戳......
"filter": {
"script": {
"script": {
"inline":"(new Date().getTime() - doc['current_edd'].date.getMillis()) /
(1000 * 60 * 60 * 24) == params.missDelby",
"params": { "missDelby": 1 }
}
}
}
Use can use some math to remove the time part with this simple calcul使用这个简单的计算可以使用一些数学来去除时间部分
long t1 = new Date().getTime();
t1 -= t1 % (24 * 3600 * 1000); //24 * 3600 * 1000 total milliseconds in a day
The you can update your query like this您可以像这样更新您的查询
"filter": {
"script": {
"script": {
"inline": "long t1 = new Date().getTime();
long t2 = doc['PostCodeDate'].value.getMillis();
t1 -= t1 % (24 * 3600 * 1000);
t2 -= t2 % (24 * 3600 * 1000);
return (t1 - t2) / (24 * 3600 * 1000) == params.missDelby",
"params": { "missDelby": 1 }
}
}
}
I'll update my solution as soon as I found a simpler approach.我会在找到更简单的方法后立即更新我的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.