# Painless - check if string contains word

**URL:** <https://discuss.elastic.co/t/painless-check-if-string-contains-word/291914>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [December 15, 2021, 7:50am UTC](https://discuss.elastic.co/t/painless-check-if-string-contains-word/291914 "2021-12-15T07:50:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sagar\_cherukuri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sagar_cherukuri/32/98981_2.png) [@sagar\_cherukuri](https://discuss.elastic.co/u/sagar_cherukuri)\
**Post date:** [December 15, 2021, 7:50am UTC](https://discuss.elastic.co/t/painless-check-if-string-contains-word/291914/1 "2021-12-15T07:50:32Z")

</div>

Is it possible to check if a string contains the word in a nested array? I am accessing the fields through params.\_source and I have created a painless script as below, but it's throwing me errors at contains(). How to check f string contains a word with params.\_source using contains()?

```auto
"script_fields": {
	"recency": {
		"script": {
			"lang": "painless",
			"inline": """
				def myString = "";
				def isCurrent = 0;
				def list = new ArrayList();
				for(int i=0; i<params._source.candidate.work_exp.size(); i++){
					myString = params._source.candidate.work_exp[i].description;
					if(myString.toString().contains(params['search_keywords'])){
						isCurrent=0;
						list.add(myString);
					} 
				}
					return list;
					""",
			"params": {
				"search_keywords": keywords
			}

		}
	}
}

```

---

<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:** [January 12, 2022, 7:51am UTC](https://discuss.elastic.co/t/painless-check-if-string-contains-word/291914/2 "2022-01-12T07:51:10Z")

</div>

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