script_score查询不支持[源代码]

时间:2018-06-21 13:23:01

标签: elasticsearch elasticsearch-6

我正在使用Elasticsearch OSS(docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4)的官方Docker镜像,似乎根本无法使script_score正常工作。似乎未启用脚本。

例如,此:

POST http://localhost:9200/address/address/_search

{
    "query": {
        "function_score": {
            "query": {
                "match": {
                    "fullAddress": {
                        "query": "13 fake",
                        "operator": "and"
                    }
                }
            },
            "script_score": {
                "lang": "expression",
                "source": "doc['flatNumber'].length"
            }
        }
    }
}

给我这个:

{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "script_score query does not support [source]",
                "line": 13,
                "col": 15
            }
        ],
        "type": "parsing_exception",
        "reason": "script_score query does not support [source]",
        "line": 13,
        "col": 15
    },
    "status": 400
}

我尝试启用它:

PUT http://localhost:9200/_cluster/settings

{
    "persistent": {
        "script.engine.groovy.inline.aggs": "on"
    }
}

但无济于事:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "persistent setting [script.engine.groovy.inline.aggs], not recognized"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "persistent setting [script.engine.groovy.inline.aggs], not recognized"
    },
    "status": 400
}

如何让script_score工作?

1 个答案:

答案 0 :(得分:1)

您只是在script中缺少script_score部分。像这样修改它,它将起作用:

    "script_score": {
        "script": {
            "lang": "expression",
            "source": "doc['flatNumber'].length"
        }
    }