Painless with contains script doesn't work

Hi, i have my index called "time_test" with the following mapping

{
	"mappings": {
	  "_doc": {
		"properties": {
		  "startDate": {
			"type": "date"
		  }
		}
	  }
	}
  }

I have a script in golang, that push the updates of the documents for the index. I want to update the documents, only if the startDate value in the document is different from the new one.

My painless script is, but is not working:

{
	"script": {
		"params": {
			"newStartDate": "2022-07-20T13:00:00"
		},
		"source":"List l = new ArrayList(); l.add(ctx._source.startDate); if(ctx._source.startDate.contains(params.newStartDate)){ ctx._source.startDate = l;} else { l.add(params.newStartDate);ctx._source.startDate = l;}",
		"lang": "painless"
	}
}

The if condition is never true.
Any idea why it is not working?

Thanks.

the string "2022-07-20T13:00:00" is completely the same with the string in _source?

Besides,

if(!(ctx._source.startDate.contains(params.newStartDate))){ctx._source.startDate.add(params.newStartDate)};

does not work?

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