How can I set the range against an existing fields in the same document?

How can I set the range against an existing fields in the same document?

GET my_index/_search
{
    "query": {
        "range" : {
            "date" : {
                "gte" : "now-[period]d/d",
                "lte" :  "now/d"
            }
        }
    }
}

Are you trying to filter by a duration by comparing start and end times within a document? If so, maybe updating those documents using update by query and then executing a fast query would work as well?

A very slow alternative could a script_query to filter out documents with a duration or a script_field to display such, if that is what you are after.

Hello, the idea is to perform the same SQL query but in the ES conversion. where 'period' is the field that contains the number of days to calculate. So my question is how can I set the fields within it, that is, evaluate the field of the same document in a Range query.

Example SQL

(UNIX_TIMESTAMP(DATE_ADD(`date`, INTERVAL `period` DAY)) > UNIX_TIMESTAMP(NOW())

Example ES

GET my_index/_search
{
    "query": {
        "range" : {
            "date" : {
                "gte" : "now-[period]d/d",
                "lte" :  "now/d"
            }
        }
    }
}

See https://www.elastic.co/guide/en/elasticsearch/reference/7.5/query-dsl-range-query.html#ranges-on-dates - which is specifying a period and uses rounding.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.