我有一个'用户' elasticsearch index,用户看起来像:
{
"id" : 1,
"name" : "Jeroen",
"hours": [8,9,10,11,12,19,20,21,22,23],
"country": "NL",
"utc_offset": 1.0
}
我想找到'小时'字段包含当地时间的当前小时。例如,我只想在荷兰的8.00-12.00或20.00-23.00之间找到上述用户。
我的解决方案是使用脚本过滤器。我不知道如何使用MVEL实现这一点,所以我安装了javascript plugin。现在我的查询如下:
{
"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": {}
}
}
}
所以这可行,但过了一段时间后,elasticsearch开始抛出异常,如下所示:
{
"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
}
发布similar issue,表明JIT编译器存在问题。作为一种解决方法,建议使用' -Dmvel2.disable.jit = true'来禁用它。我已经尝试过,将它放在/ etc / default / elasticsearch的ES_JAVA_OPTS中,但它似乎没有任何效果。
是否有人知道出现了什么问题以及如何修复它,或者有其他方法来执行此查询?