# \[Solved\] Compile error when searching in discover, unexpected token \['\<EOF\>'\] was expecting one of \['}'\]

**URL:** <https://discuss.elastic.co/t/solved-compile-error-when-searching-in-discover-unexpected-token-eof-was-expecting-one-of/84156>\
**Category:** Kibana\
**Created:** [May 1, 2017, 1:50pm UTC](https://discuss.elastic.co/t/solved-compile-error-when-searching-in-discover-unexpected-token-eof-was-expecting-one-of/84156 "2017-05-01T13:50:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris03](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris03/32/17824_2.png) [@chris03](https://discuss.elastic.co/u/chris03)\
**Post date:** [May 1, 2017, 1:51pm UTC](https://discuss.elastic.co/t/solved-compile-error-when-searching-in-discover-unexpected-token-eof-was-expecting-one-of/84156/1 "2017-05-01T13:51:00Z")

</div>

Kibana was working just fine but now the below error appears each time I search in the "Discover" panel.  
It appeard on version 5.3.0, I upgraded to 5.3.1 but still got the error.

Looking at the "script" in the error it seems that there is a } missing at the end.  
I'm new to Kibana so I don't really know where this script is coming from or how to fix it...

```
Error: Request to Elasticsearch failed: {
    "error": {
        "root_cause": [{
            "type": "script_exception",
            "reason": "compile error",
            "script_stack": ["... return \"no exception\";\n}", " ^---- HERE"],
            "script": "def message = doc['message.keyword'].value;\nif (doc['message.message'].value =~ /Caught exception in Exception Strategy/) {\n int lastSlashIndex = path.lastIndexOf(':');\n if (lastSlashIndex > 0) {\n return path.substring(lastSlashIndex+1);\n} else {\n return \"no exception\";\n}",
            "lang": "painless"
        }],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [{
            "shard": 0,
            "index": "filebeat-2017.05.01",
            "node": "-iVxCmFyRLK-KscU_yKuPA",
            "reason": {
                "type": "script_exception",
                "reason": "compile error",
                "script_stack": ["... return \"no exception\";\n}", 
                                 " ^---- HERE"],
                "script": "def message = doc['message.keyword'].value;\nif (doc['message.message'].value =~ /Caught exception in Exception Strategy/) {\n int lastSlashIndex = path.lastIndexOf(':');\n if (lastSlashIndex > 0) {\n return path.substring(lastSlashIndex+1);\n} else {\n return \"no exception\";\n}",
                "lang": "painless",
                "caused_by": {
                    "type": "illegal_argument_exception",
                    "reason": "unexpected token ['<EOF>'] was expecting one of ['}']."
                }
            }
        }],
        "caused_by": {
            "type": "script_exception",
            "reason": "compile error",
            "script_stack": ["... return \"no exception\";\n}",
                             " ^---- HERE"],
            "script": "def message = doc['message.keyword'].value;\nif (doc['message.message'].value =~ /Caught exception in Exception Strategy/) {\n int lastSlashIndex = path.lastIndexOf(':');\n if (lastSlashIndex > 0) {\n return path.substring(lastSlashIndex+1);\n} else {\n return \"no exception\";\n}",
            "lang": "painless",
            "caused_by": {
                "type": "illegal_argument_exception",
                "reason": "unexpected token ['<EOF>'] was expecting one of ['}']."
            }
        }
    },
    "status": 500
}
at http: //myserver:5601/bundles/kibana.bundle.js?v=14844:28:15872
    at Function.Promise.try(http: //myserver:5601/bundles/commons.bundle.js?v=14844:75:22403)
        at http: //myserver:5601/bundles/commons.bundle.js?v=14844:75:21773
        at Array.map(native) at Function.Promise.map(http: //myserver:5601/bundles/commons.bundle.js?v=14844:75:21728)
            at callResponseHandlers(http: //myserver:5601/bundles/kibana.bundle.js?v=14844:28:15484)
                at http: //myserver:5601/bundles/kibana.bundle.js?v=14844:28:3614
                at processQueue(http: //myserver:5601/bundles/commons.bundle.js?v=14844:38:23621)
                    at http: //myserver:5601/bundles/commons.bundle.js?v=14844:38:23888
                    at Scope.$eval(http: //myserver:5601/bundles/commons.bundle.js?v=14844:39:4619)

```

Script with a missing } at the end

```
def message = doc['message.keyword'].value;

if (doc['message.message'].value = ~/Caught exception in Exception Strategy/) {
    int lastSlashIndex = path.lastIndexOf(':');
    if (lastSlashIndex > 0) {
        return path.substring(lastSlashIndex + 1);
    } else {
        return "no exception";
    }
```

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [May 1, 2017, 2:01pm UTC](https://discuss.elastic.co/t/solved-compile-error-when-searching-in-discover-unexpected-token-eof-was-expecting-one-of/84156/2 "2017-05-01T14:01:37Z")

</div>

Hi,

Sorry am a bit lost here. Can you please post a screenshot of the error? I am trying to figure out where are you on Kibana and what are you trying to do?

Thanks,  
Bhavya

---

<div class="post-metadata">

**Author:** ![chris03](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris03/32/17824_2.png) [@chris03](https://discuss.elastic.co/u/chris03)\
**Post date:** [May 1, 2017, 2:07pm UTC](https://discuss.elastic.co/t/solved-compile-error-when-searching-in-discover-unexpected-token-eof-was-expecting-one-of/84156/3 "2017-05-01T14:07:12Z")

</div>

There you go:

 ![](https://us1.discourse-cdn.com/elastic/original/3X/f/d/fda374324ecdcd93b50b0df9088cff1677bbab82.png)

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [May 4, 2017, 8:34pm UTC](https://discuss.elastic.co/t/solved-compile-error-when-searching-in-discover-unexpected-token-eof-was-expecting-one-of/84156/4 "2017-05-04T20:34:44Z")

</div>

Hi Chris,

Sorry for the delay in getting back to you.  
It looks like you might have created a scripted field which is not compiling correctly. Can you go to management - click on index pattern - filebeat and delete any scripted fields you may have created. This should ideally fix the error.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/b/2/b2e1286e3367ddda69c9cbfa2a27bcf3a71e9314.jpg)

If you need to create scripted fields - here is the documentation on it.  
[https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)

Thanks,  
Bhavya

---

<div class="post-metadata">

**Author:** ![chris03](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris03/32/17824_2.png) [@chris03](https://discuss.elastic.co/u/chris03)\
**Post date:** [May 5, 2017, 12:40pm UTC](https://discuss.elastic.co/t/solved-compile-error-when-searching-in-discover-unexpected-token-eof-was-expecting-one-of/84156/5 "2017-05-05T12:40:44Z")

</div>

That was exactly it.  
Not sure how that script got created but I'll remember to look there if I run in similars errors again.

Thank you so much !!!

---

<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 2, 2017, 12:48pm UTC](https://discuss.elastic.co/t/solved-compile-error-when-searching-in-discover-unexpected-token-eof-was-expecting-one-of/84156/6 "2017-06-02T12:48:15Z")

</div>

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