elasticsearch,Lucene,elasticsearch" /> elasticsearch,Lucene,elasticsearch" />

Lucene 为什么升级到1.3.2后我的ElasticSearch查询出现错误?

Lucene 为什么升级到1.3.2后我的ElasticSearch查询出现错误?,lucene,elasticsearch,Lucene,elasticsearch,以前,我有过这样的经历: { query: { function_score: { filter: { and: [ { term: { 'currency': 'usd', '_cache': false } } ] }, script_score: { "

以前,我有过这样的经历:

{
  query: {
    function_score: {
      filter: {
        and: [
          {
            term: {
              'currency': 'usd',
              '_cache': false
            }
          }
        ]
      },
      script_score: {
        "script": "_score * doc['random_score'].value"
      }
    }
  }
}
非常基本,我只是按货币过滤并按分数排序

但每次升级后,我都无法使用任何简单的自定义分数查询

我试着用这个例子来简化它:

{
  query: {
    function_score: {
      script_score: {
        "script": "_score * doc['random_score'].value"
      }
    }
  }
}
我得到的错误如下:

{
  "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[PxzZtO8FQviuhxS-3EJFwA][listings][3]:
            SearchParseException[[listings][3]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "function_score": {
                      "script_score": {
                        "script": "_score * doc['random_score'].value"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[listings] script_score the script could not be loaded];
            nested: ScriptException[dynamic scripting for [mvel] disabled]; }{[PxzZtO8FQviuhxS-3EJFwA][listings][4]:
            SearchParseException[[listings][4]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "function_score": {
                      "script_score": {
                        "script": "_score * doc['random_score'].value"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[listings] script_score the script could not be loaded];
            nested: ScriptException[dynamic scripting for [mvel] disabled]; }{[PxzZtO8FQviuhxS-3EJFwA][listings][0]:
            SearchParseException[[listings][0]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "function_score": {
                      "script_score": {
                        "script": "_score * doc['random_score'].value"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[listings] script_score the script could not be loaded];
            nested: ScriptException[dynamic scripting for [mvel] disabled]; }{[PxzZtO8FQviuhxS-3EJFwA][listings][1]:
            SearchParseException[[listings][1]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "function_score": {
                      "script_score": {
                        "script": "_score * doc['random_score'].value"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[listings] script_score the script could not be loaded];
            nested: ScriptException[dynamic scripting for [mvel] disabled]; }{[PxzZtO8FQviuhxS-3EJFwA][listings][2]:
            SearchParseException[[listings][2]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "function_score": {
                      "script_score": {
                        "script": "_score * doc['random_score'].value"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[listings] script_score the script could not be loaded];
            nested: ScriptException[dynamic scripting for [mvel] disabled]; }]",
  "status": 400
}
一些非常简单的东西,例如:

{
  query: {
    match_all: {}
  }
}

在以前的版本中,mvel是用elasticsearch编写脚本的,现在已经贬值了

这里有一个问题

实际问题是mvel的动态脚本在1.3.x中不受支持,但它是1.3.x中的默认语言,也将在1.4.x中更改,因此必须包含lang参数,并将值设为,(lang=groovy)


希望这有帮助!!谢谢

因为它只被弃用,所以它应该使用config/scripts文件夹中的脚本(?)工作。我如何在单独的ES安装中实现这一点?安装插件?对于直接集成ES的maven应用程序,我只需添加
org.elasticsearch elasticsearch lang mvel
它对mvel不起作用,您必须安装它(是作为插件),安装后,您可以使用lang:“mvel”
{
    query:{
        function_score:{
            script_score : {
                "script" : "_score * doc['random_score'].value",
                "lang":"groovy"
            }
        }
   }
}