# Painless with contains script doesn't work

**URL:** <https://discuss.elastic.co/t/painless-with-contains-script-doesnt-work/310423>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 22, 2022, 7:27pm UTC](https://discuss.elastic.co/t/painless-with-contains-script-doesnt-work/310423 "2022-07-22T19:27:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FKarraz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fkarraz/32/80628_2.png) [@FKarraz](https://discuss.elastic.co/u/FKarraz)\
**Post date:** [July 22, 2022, 7:27pm UTC](https://discuss.elastic.co/t/painless-with-contains-script-doesnt-work/310423/1 "2022-07-22T19:27:48Z")

</div>

Hi, i have my index called "time\_test" with the following mapping

```auto
{
	"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:

```auto
{
	"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.

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [July 23, 2022, 12:10pm UTC](https://discuss.elastic.co/t/painless-with-contains-script-doesnt-work/310423/2 "2022-07-23T12:10:21Z")

</div>

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

Besides,

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

```

does not work?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 20, 2022, 12:10pm UTC](https://discuss.elastic.co/t/painless-with-contains-script-doesnt-work/310423/3 "2022-08-20T12:10:41Z")

</div>

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