elasticsearch-py 无法使用 script_score 进行查询

elasticsearch-py can't query with script_score

我目前正在尝试通过 Python 查询 ES,使用 elasticsearch-py 但没有成功...我正在 "elasticsearch-head" 插件上测试请求并且它工作正常(结果得分)

但是,当我在 Python 中这样做时,似乎出了点问题,虽然我得到了相同的结果,但它们的评分不正确...

代码如下:

custom_query={
  "query": {
    "function_score": {
      "query": {
        "match_all": {}
      },
      "functions": [
        {
          "script_score": {
            "lang": "groovy", 
            "script": "_score+20",
            "params":{"myMap":{}}
          }
        }
      ]
    }
  }
}

这是我的自定义查询,很简单,只是为了测试评分机制。

src = es.search(index=['test'],scroll='60s',search_type='scan',size=10,body=custom_query)

现在我测试一下:

while(1):
    src = es.scroll(scroll_id=sid, scroll='60s')
    sid = src['_scroll_id']
    kws.extend(src['hits']['hits'])

所有这些给出的是一组评分不正确的结果...我什至启用了“_explanation”以了解脚本是否被使用... 这个意思: - “_score”始终为 0 - “_explanation”显示类似:

{
    'description': 'function score',
    product of:'',
        'value': 21.0,
        'details': [
            {
                'description': 'ConstantScore(*:*)',
                product of:'',
                    'value': 1.0,
                    'details': [
                        {'description': 'boost', 'value': 1.0}, {'description': 'queryNorm', 'value': 1.0}
                    ]
            },
            {
                'description': 'Math.min of',
                'value': 21.0,
                'details': [
                    {
                        'description': 'script score function',
                        computed with script:"return _score+30;" and parameters: \n{myMap={}}', 'value': 21.0
                    },
                    {
                        'description': 'maxBoost',
                        'value': 3.4028235e+38
                    }
                ]
            },
            {
                'description': 'queryBoost',
                'value': 1.0
            }
        ]
}

看来问题出在 ElasticSearch 本身..."search-type":"scan" 不允许对多个结果进行评分。

here

中提供了对该问题的更详尽的解释