title: IllegalAccessError after a few queries when using script filter in elasticsearch query
body: <p>I have a 'users' elasticsearch index, where a user looks like:</p>
  
  <pre><code>{
    "id" : 1,
    "name" : "Jeroen",
    "hours": [8,9,10,11,12,19,20,21,22,23],
    "country": "NL",
    "utc_offset": 1.0
  }
  </code></pre>
  
  <p>I want to find all users of which the 'hours' field contains the current hour in their local time. So for example, I only want to find the above user when it's between 8.00-12.00 or 20.00-23.00 in the Netherlands.</p>
  
  <p>My solution for this is using a script filter. I didn't know how to implement this with MVEL, so I installed the <a href="https://github.com/elasticsearch/elasticsearch-lang-javascript" rel="nofollow">javascript plugin</a>. Now my query looks like this:</p>
  
  <pre><code>{
    "query": {
      "match_all": {}
    },"filter": {
      "script": {
         "script": "var a = doc['hours'].values; var d = new Date(); d.setTime(d.getTime() + doc['utc_offset'].value * 3600 * 1000); a.indexOf('' + d.getHours()) != -1",
         "params": {}
      }
    }
  }
  </code></pre>
  
  <p>So this works, but after a while elasticsearch is starting to throw exceptions, like this:</p>
  
  <pre><code>{
    "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[x9FlNmmsT26hJbrfnyH2uA][users][2]: QueryPhaseExecutionException[[users][2]: query[ConstantScore(*:*)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: IllegalAccessError[org/elasticsearch/index/fielddata/ScriptDocValues$Strings$1]; }{[x9FlNmmsT26hJbrfnyH2uA][users][3]: QueryPhaseExecutionException[[users][3]: query[ConstantScore(*:*)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: IllegalAccessError[org/elasticsearch/index/fielddata/ScriptDocValues$Strings$1]; }{[x9FlNmmsT26hJbrfnyH2uA][users][0]: QueryPhaseExecutionException[[users][0]: query[ConstantScore(*:*)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: IllegalAccessError[org/elasticsearch/index/fielddata/ScriptDocValues$Strings$1]; }{[x9FlNmmsT26hJbrfnyH2uA][users][2]: QueryPhaseExecutionException[[users][3]: query[ConstantScore(*:*)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: IllegalAccessError[org/elasticsearch/index/fielddata/ScriptDocValues$Strings$1]; }{[x9FlNmmsT26hJbrfnyH2uA][users][4]: QueryPhaseExecutionException[[users][4]: query[ConstantScore(*:*)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: IllegalAccessError[org/elasticsearch/index/fielddata/ScriptDocValues$Strings$1]; }]",
  "status": 500
  </code></pre>
  
  <p>}</p>
  
  <p>A <a href="https://github.com/elasticsearch/elasticsearch/issues/3094" rel="nofollow">similar issue</a> was posted where it was suggested it's a problem with the JIT compiler. As a workaround it was suggested to disable it by using '-Dmvel2.disable.jit=true'. I've tried this, by putting it in ES_JAVA_OPTS in /etc/default/elasticsearch but it didn't seem to have any effect.</p>
  
  <p>Does anybody have a clue what's going wrong and how to fix it, or have an alternative way of performing this query? </p>