Kibana: Scripted Field: Dynamic date (now - 15d / now - 30d) not working

I have a scripted field of the format "Date". When I try using this field in Kibana visualization and apply a filter like "date > now-30d",
I am getting an error:

    caused_by": {
                "type": "date_time_parse_exception",
                "reason": "Text 'now-15d' could not be parsed at index 0"
              }

The field works fine when used for Date Histogram. Please suggest what is wrong and what can be done to fix this.

Can you share your mappings?

    "results" : {
                "completed_on" : 1617936964,
                "created_time" : "2021-04-05 15:35:58",
                "include_all" : false,
                "url" : "String",
                "created_on" : 1617636958,
                "name" : "test",
    }

I am trying to convert the time string to DateTime and the script is

    if(doc.containsKey('results.created_time.keyword') && doc['results.created_time.keyword'].size() != 0) { return Instant.ofEpochSecond(doc['results.created_time.keyword'].value).atZone(ZoneId.systemDefault()); } else { return Instant.ofEpochSecond(0).atZone(ZoneId.systemDefault()); }

I have also tried using DateFormatter and return millis, but getting a different error "toInstant" method is not found (as ES is trying to convert the output of this script to Instant)

So your field is text and not date.
First, convert it successfully to date.
You can use painless lab for this.

As mentioned, am using a scripted field for the date part. But I am not able to apply range filters to this scripted Field.

However, I can use this field in the Date Histogram and it works. When I try applying the range filter I get the above error:

Want to know if what causes date Histogram to work but not range filters.

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