如何计算今天的日期和文档中的日期之间的日期差异,但在弹性搜索的脚本中从中删除时间

How to calculate day difference between today's date and date from doc but eliminating time from it in scripts of elastic search

我试过这个解决方案,它有效,但它也需要时间戳....我想消除时间戳...

"filter": {
    "script": {
        "script": { 
            "inline":"(new Date().getTime() - doc['current_edd'].date.getMillis()) /
                            (1000 * 60 * 60 * 24)  == params.missDelby",
             "params": { "missDelby": 1 }
         }
     }
 }

使用这个简单的计算可​​以使用一些数学来删除时间部分

long t1 = new Date().getTime();
t1 -= t1 % (24 * 3600 * 1000); //24 * 3600 * 1000 total milliseconds in a day

您可以像这样更新您的查询

"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 }
         }
     }
}

一旦找到更简单的方法,我会立即更新我的解决方案。