Painless scripted field - access query range

Hi,

I'm new to Painless (and to Elasticsearch as well) and I'm building a query that looks like this:

  "script_fields": {
    "PeriodTime": {
      "script": {
        "source": "doc['@timestamp'].value.millis - doc['previousStateDateTime'].value.millis",
        "lang": "painless"
      }
    }
  },
  "stored_fields": [
    "*"
  ],
  "_source": {
    "excludes": []
  },
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "match_all": {}
        },
        {
          "range": {
            "@timestamp": {
              "gte": "2021-03-23T00:00:00.000Z",
              "lte": "2021-03-23T23:59:59.000Z",
              "format": "strict_date_optional_time"
            }
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  }

I would like to receive the "gte" and "lte" values inside the source of the scripted field. Is this possible?

Thanks

I don't completely understand your question. Do you want to access gte and lte values from the range query inside script_fields source? If yes, it is not possible. And why would you need that? You are forming a query yourself, you can put in the source whatever you need, including, for example direct values: "2021-03-23T00:00:00.000Z"

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