之前,我有这个:
{
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: {}
}
}
答案 0 :(得分:12)
在以前的版本中,mvel是elasticsearch中的脚本,现在已经过折旧。
这是一个问题。 https://github.com/elasticsearch/elasticsearch/issues/7029
实际问题是1.3.x中不支持mvel的动态脚本,但它也是1.3.x中的默认语言,将在1.4.x中更改,因此你必须包含lang参数,并给出值为,(lang = groovy)
{
query:{
function_score:{
script_score : {
"script" : "_score * doc['random_score'].value",
"lang":"groovy"
}
}
}
}
希望这有帮助!!感谢