Scripted field of type Date throwing an error when filter is added to it in line plot

I have a field loaded by index as startdate which is of the type" string". I created a scripted field startdate_date to store the startdate as a "date" type;

Index field: startdate- type String

Scripted field: startdate_date - Type Date
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(doc['startdate.keyword'].value).getTime();

Plotted a line graph,
y-axis : sum savings
x-axis: date histogram (monthly)

Filter: startdate_date (scripted field) is between
from: now-2M
to: now
However, I am getting the below error
Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"class_cast_exception","reason":"class_cast_exception: Cannot apply [>] operation to types [java.lang.Long] and [java.lang.String]."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"pi-automation-rpa","node":"Cz3ydcezTK6odEqc_xe2dQ","reason":{"type":"script_exception","reason":"runtime error","script_stack":["return s.get() >= v} boolean lt(Supplier s, def v) {"," ^---- HERE"],"script":"boolean gte(Supplier s, def v) {return s.get() >= v} boolean lt(Supplier s, def v) {return s.get() < v}gte(() -> { new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(doc['startdate.keyword'].value).getTime(); }, params.gte) && lt(() -> { new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(doc['startdate.keyword'].value).getTime(); },

I am trying to display only last 6 months data. I am not sure on what is causing this. Any help is appreciated.

Hi @meghana_s,
Welcome to our forum! Thanks for taking the time to post.

I have two requests:

  • Can you please show me the mapping for that index, particularly the part that shows the type of the startdate field. I want to check if you have startdate.keyword enabled.
  • Also can you please provide a preview of the values available in the startdate field?

startdate_date:

2019-09-30 15:00:00.000

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