ElasticSearch脚本过滤器比较两个字段

时间:2015-04-08 08:02:53

标签: elasticsearch

我想使用脚本过滤器来获得得分值等于maxScore值的所有匹配。但它不起作用。

{
    "query": {
        "filtered": {
            "filter": {
                "script": {
                    "script": "doc['match.score'].value == doc['match.maxScore'].value"
                }
            }
        }
    }
}

我有这个错误:

{
    "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[yk_PnKg9SOaf1d8acCsjvw][cobink_search][0]: SearchParseException[[cobink_search][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"filter":{"script":{"script":"doc['match.score'].value == doc['match.maxScore'].value"}}}}}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }{[0jYKWZlyQiiVPHlzmoMjkA][cobink_search][1]: RemoteTransportException[[Hammer Harrison][inet[/192.168.1.100:9300]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[cobink_search][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"filter":{"script":{"script":"doc['match.score'].value == doc['match.maxScore'].value"}}}}}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }{[yk_PnKg9SOaf1d8acCsjvw][cobink_search][2]: SearchParseException[[cobink_search][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"filter":{"script":{"script":"doc['match.score'].value == doc['match.maxScore'].value"}}}}}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }{[yk_PnKg9SOaf1d8acCsjvw][cobink_search][3]: SearchParseException[[cobink_search][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"filter":{"script":{"script":"doc['match.score'].value == doc['match.maxScore'].value"}}}}}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }{[0jYKWZlyQiiVPHlzmoMjkA][cobink_search][4]: RemoteTransportException[[Hammer Harrison][inet[/192.168.1.100:9300]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[cobink_search][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"filter":{"script":{"script":"doc['match.score'].value == doc['match.maxScore'].value"}}}}}]]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; }]",
    "status": 400
}

谢谢你们:)

2 个答案:

答案 0 :(得分:2)

在您的情况下禁用动态脚本。在elasticsearch.yml文件中添加以下行以启用动态脚本。然后你的查询应该工作。但请注意,这可能会在您的Elasticsearch集群中留下安全漏洞。详细了解herehere

script.disable_dynamic: false

答案 1 :(得分:1)

在版本2.x及更高版本中,您需要使用

script.indexed: on
script.inline: on
在elasticsearch.yml文件中

,以启用脚本。