# Runtime fields can't be saved because highlighted errors need to be fixed but none are highlighted

**URL:** <https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [May 9, 2024, 3:53am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121 "2024-05-09T03:53:00Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 9, 2024, 3:53am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/1 "2024-05-09T03:53:00Z")

</div>

The message says invalid Painless script but does not highlight any errors. Of course, I want to write a more involved script, but even this basic script is getting rejected without explanation.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/7/27194be740ee2e739c32ea06fe669605157f0474.png)

---

<div class="post-metadata">

**Author:** ![jughosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jughosta/32/107160_2.png) [@jughosta](https://discuss.elastic.co/u/jughosta)\
**Post date:** [May 10, 2024, 8:09am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/2 "2024-05-10T08:09:46Z")

</div>

Hi @rasmus.torkel and welcome to the community!

What version are you using?

Do you always see this error? Does it help to reopen the flyout or enter another script?

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 10, 2024, 8:22am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/3 "2024-05-10T08:22:31Z")

</div>

Thanks for replying. I am not sure there is a way to tell from the browser. I will ask my team to tell me the Kibana version.

I have tried creating a script from scratch multiple times and even restarted my laptop in between. I have seen this error in more complex scripts but I thought for asking the question, I'd make it as basic as I can, so that the correctness of the script is obvious.

I had actually saved at some point and then Kibana would not let me save anymore, even with the same code. Another team member has also reported that the script editor for runtime fields sometimes plays up.

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 10, 2024, 9:16am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/4 "2024-05-10T09:16:36Z")

</div>

I went into Stack Management and this is what it said: "Welcome to Stack Management 8.11.1". This must have been on my screen many times without me noticing.

So I gather 8.11.1 is the relevant version.

---

<div class="post-metadata">

**Author:** ![jughosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jughosta/32/107160_2.png) [@jughosta](https://discuss.elastic.co/u/jughosta)\
**Post date:** [May 10, 2024, 9:43am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/5 "2024-05-10T09:43:22Z")

</div>

Thanks! As far as I know such issues were not reported for 8.11.1 before.

Would be great if you could paste script examples here as text too.

Does the same script work correctly when executed directly in DevTools? For example:

```auto
GET kibana*/_search
{
  "fields":["test"],
  "_source":false,
  "runtime_mappings": {
    "test": {
      "type": "keyword",
      "script": {
        "source":
          "emit('test')" 
        }
      }
    }
}

```

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 11, 2024, 6:40am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/6 "2024-05-11T06:40:51Z")

</div>

Here is the code:

emit('unknown');

I am getting familiar with the dev tools now.

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 13, 2024, 12:26am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/7 "2024-05-13T00:26:01Z")

</div>

Thanks for the script, Julia. I ran it in the Dev Tools Console. The following came back:

```auto
{
  "took": 8,
  "timed_out": false,
  "_shards": {
    "total": 0,
    "successful": 0,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": 0,
    "hits": []
  }
}

```

---

<div class="post-metadata">

**Author:** ![jughosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jughosta/32/107160_2.png) [@jughosta](https://discuss.elastic.co/u/jughosta)\
**Post date:** [May 13, 2024, 9:55am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/8 "2024-05-13T09:55:40Z")

</div>

Thanks, @rasmus.torkel ! You can check in the same way your scripts to verify that there are no syntax errors in them.

If the script works in DevTools, but you still have issues with saving it as a new runtime field in UI, can you please share your exact steps? Also, updating your browser might help.

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 13, 2024, 10:14am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/9 "2024-05-13T10:14:53Z")

</div>

Thanks Julia.

The steps are:

- Go to stack management/data views

- Select my data view

- Click "Add field" button

- Give the field a name but leave the type as "keyword"

- Turn on "Set value" and enter script

- Try to save (this is where it does not work)

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 13, 2024, 10:18am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/10 "2024-05-13T10:18:22Z")

</div>

I am running this version of Chrome: Version 124.0.6367.201 (Official Build) (64-bit)

The browser is managed by my organisation. I am not free to change it. However, if you told me the version is behind and I need to have at least version X, then I could try to convince the support people to upgrade.

---

<div class="post-metadata">

**Author:** ![jughosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jughosta/32/107160_2.png) [@jughosta](https://discuss.elastic.co/u/jughosta)\
**Post date:** [May 13, 2024, 1:36pm UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/11 "2024-05-13T13:36:25Z")

</div>

Thanks! Your browser version looks good.

Do you see any errors in the browser console or in flyout under the script textarea? Or failed network requests?

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 14, 2024, 4:56am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/12 "2024-05-14T04:56:40Z")

</div>

The problem has magically gone away!!

I had suggested to the support people that they restart the ELK/Kibana system. I don't have an answer back as to whether they actually did it.

Don't close yet, please. Let's see if the joy lasts.

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 14, 2024, 6:37am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/13 "2024-05-14T06:37:56Z")

</div>

The error is back. Of course, I wanted to have a more fancy script. I added more stuff and again could not save. I deleted my variable and started again with the simple script I posted above. Same error.

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 15, 2024, 2:03am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/14 "2024-05-15T02:03:05Z")

</div>

There is a work around. For the documentId, put the \_id of a field that you are planning to refer to. I managed to get my script done.

Thanks, Julia, for your assistance.

---

<div class="post-metadata">

**Author:** ![jughosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jughosta/32/107160_2.png) [@jughosta](https://discuss.elastic.co/u/jughosta)\
**Post date:** [May 15, 2024, 8:31am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/15 "2024-05-15T08:31:36Z")

</div>

If not all documents have values for the field in question, then it's recommended to add a check for it in your script so the actual search does not fail. Example:

```auto
if (doc["message"].size() > 0) {
    emit(doc['message'].value);
} else {
    emit('');
}

```

---

<div class="post-metadata">

**Author:** ![rasmus.torkel](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rasmus.torkel](https://discuss.elastic.co/u/rasmus.torkel)\
**Post date:** [May 16, 2024, 12:45am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/16 "2024-05-16T00:45:58Z")

</div>

Thanks for that pointer, Julia. But my problem was that I could not save, not that my script was running but failing.

I am happy for you to close the thread now.

My feedback to the team is that no matter what stupid mistake the user has made or what else is misaligned in the set-up, any software system should produce clear error messages when it can't do what it is asked to do. That way, the user can get their job done quickly and efficiently and the support/dev team has less work to do, solving these kind of issues.

---

<div class="post-metadata">

**Author:** ![jughosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jughosta/32/107160_2.png) [@jughosta](https://discuss.elastic.co/u/jughosta)\
**Post date:** [May 16, 2024, 8:39am UTC](https://discuss.elastic.co/t/runtime-fields-cant-be-saved-because-highlighted-errors-need-to-be-fixed-but-none-are-highlighted/359121/17 "2024-05-16T08:39:49Z")

</div>

Thanks for the feedback!

I created an issue in Github to improve UX [[Data view field] Restore/improve validation message when navigating between documents via preview panel · Issue #183598 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/183598)
