# Scripted fields examples from the article result in a compile error

**URL:** <https://discuss.elastic.co/t/scripted-fields-examples-from-the-article-result-in-a-compile-error/234066>\
**Category:** Kibana\
**Created:** [May 24, 2020, 8:04pm UTC](https://discuss.elastic.co/t/scripted-fields-examples-from-the-article-result-in-a-compile-error/234066 "2020-05-24T20:04:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![111343](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111343/32/68977_2.png) [@111343](https://discuss.elastic.co/u/111343)\
**Post date:** [May 24, 2020, 8:04pm UTC](https://discuss.elastic.co/t/scripted-fields-examples-from-the-article-result-in-a-compile-error/234066/1 "2020-05-24T20:04:33Z")

</div>

Hi all, I'm trying to use scripted fields and all examples [from the article](https://www.elastic.co/blog/using-painless-kibana-scripted-fields) result in a compile error. (Examples are in sub-thread). Is there anything I am missing? Feel free to re-direct me to another channel, if this is the wrong one for this question

for example

```auto
  def m = /^.*\.([a-z]+)$/.matcher(doc['host.keyword'].value);
if ( m.matches() ) {
   return m.group(1)
} else {
   return "no match"
}

```

results in

```auto
 "root_cause": [
  {
   "type": "script_exception",
   "reason": "compile error",
   "script_stack": [
    "def m = /^.*\\.([a-z]+)$/.matcher( ...",
    " ^---- HERE"
   ],
   "script": "def m = /^.*\\.([a-z]+)$/.matcher(doc['host.keyword'].value);\nif ( m.matches() ) {\n return m.group(1)\n} else {\n return \"no match\"\n}",
   "lang": "painless"
  },

```

Any ideas where to dig?

---

<div class="post-metadata">

**Author:** ![myasonik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/myasonik/32/62369_2.png) [@myasonik](https://discuss.elastic.co/u/myasonik)\
**Post date:** [May 26, 2020, 8:44pm UTC](https://discuss.elastic.co/t/scripted-fields-examples-from-the-article-result-in-a-compile-error/234066/2 "2020-05-26T20:44:30Z")

</div>

Have you turned regex in your `elasticsearch.yml` file?

```auto
script.painless.regex.enabled: true

```

---

<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:** [June 23, 2020, 8:44pm UTC](https://discuss.elastic.co/t/scripted-fields-examples-from-the-article-result-in-a-compile-error/234066/3 "2020-06-23T20:44:32Z")

</div>

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