Es query statement asking for help

now there is a data with the following fields

id expired create_time

the requirement is to filter out creation time + expiration time (seconds) < system current time . If it is a sql statement, it is very simple:

select * from table where DATE_ADD(create_time,INTERVAL expired SECOND) < now();

how should I query in es?

Mar.21,2022

you first subtract the expiration time from the system time, and then judge that this time is not compared with the creation time in the es library


has been solved, use script to query:

GET /.../_search
{
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": {
              "source": "return (doc['create_time'].value.getMillis() + doc['expired'].value * 1000) < new Date().getTime()"
            }
          }
        }
      ]
    }
  },
  "size": 20
}
Menu