I have a 'users' elasticsearch index, where a user looks like:
{
"id" : 1,
"name" : "Jeroen",
"hours": [8,9,10,11,12,19,20,21,22,23],
"country": "NL",
"utc_offset": 1.0
}
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.
My solution for this is using a script filter. I didn't know how to implement this with MVEL, so I installed the javascript plugin. Now my query looks like this:
{
"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": {}
}
}
}
So this works, but after a while elasticsearch is starting to throw exceptions, like this:
{
"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
}
A similar issue 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.
Does anybody have a clue what's going wrong and how to fix it, or have an alternative way of performing this query?