# Error SearchScript.CONTEXT == false

**URL:** <https://discuss.elastic.co/t/error-searchscript-context-false/175255>\
**Category:** Elasticsearch\
**Created:** [April 3, 2019, 5:42pm UTC](https://discuss.elastic.co/t/error-searchscript-context-false/175255 "2019-04-03T17:42:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EliuFlorez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eliuflorez/32/40884_2.png) [@EliuFlorez](https://discuss.elastic.co/u/EliuFlorez)\
**Post date:** [April 3, 2019, 5:42pm UTC](https://discuss.elastic.co/t/error-searchscript-context-false/175255/1 "2019-04-03T17:42:29Z")

</div>

Hello!  
I am creating a custom plugin and when making this query I have this error.

JSON

```auto
GET example_event/_search
{
  "query": {
    "bool" : {
      "filter" : {
        "script" : {
          "script" : {
            "source": "notHasExpired",
            "lang": "native",
            "params": {
              "field": "recurrent_date"
            }
          }
        }
      }
    }
  }
}

```

Error

```auto
"caused_by": {
      "type": "general_script_exception",
      "reason": "Failed to compile inline script [notHasExpired] using lang [native]",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "native scripts can not be used for context [filter]"
      }
    }

```

If code

```auto
if (context.equals(SearchScript.CONTEXT) == false) {
                //throw new IllegalArgumentException(getType() + " scripts cannot be used for context [" + context.name + "]");
            }

```

where compile receives  
ScriptName: notHasExpired  
scriptSource: notHasExpired  
ContextType: native  
ContextName: filter  
SearchScript.CONTEXT: org.elasticsearch.script.ScriptContext@3e5d4f6b

if I delete the condition of "SearchScript.CONTEXT == false" I have an error of "org.elasticsearch.script.FilterScript $ Factory" but I am using it is "SearchScript.Factory factory = hasAnyOccurrenceBetween :: new;"

Do you have any idea why?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [April 10, 2019, 5:31pm UTC](https://discuss.elastic.co/t/error-searchscript-context-false/175255/2 "2019-04-10T17:31:30Z")

</div>

Since you are within a filter bool clause, the script type is FilterScript.

---

<div class="post-metadata">

**Author:** ![EliuFlorez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eliuflorez/32/40884_2.png) [@EliuFlorez](https://discuss.elastic.co/u/EliuFlorez)\
**Post date:** [April 10, 2019, 5:45pm UTC](https://discuss.elastic.co/t/error-searchscript-context-false/175255/3 "2019-04-10T17:45:23Z")

</div>

> [@rjernst](#):
>
> cláusula

Hello boy. if so I had to set the same script for each of the clauses. But now I have a problem since the same scripts I need to set it in agregation. What is the "import org.elasticsearch.script.?" to use?

---

<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:** [May 8, 2019, 5:45pm UTC](https://discuss.elastic.co/t/error-searchscript-context-false/175255/4 "2019-05-08T17:45:24Z")

</div>

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