【问题标题】:How to access term positions/offsets from Elasticsearch Painless script?如何从 Elasticsearch Painless 脚本访问术语位置/偏移量?
【发布时间】:2020-02-05 18:58:49
【问题描述】:

我们使用 AWS Elasticsearch,它从版本 5 开始支持无痛脚本。 我需要在我的自定义评分脚本中访问term positions/offsets

在旧的 Groovy 脚本中它可以工作:

"query": {
    "function_score": {
        "query": {"match_phrase": {"text": "life"} },
        "script_score": {
            "script": {
                "lang": "groovy",
                "inline": "termInfo=_index['text'].get('life', _POSITIONS);"
            }
        },
        "boost_mode": "multiply"
    }
}

但它不适用于 Painless。它返回“编译错误”。

【问题讨论】:

  • 改用 groovy
  • @Val Groovy 在 AWS ES 中被禁用
  • 如果您只想存储日志,AWS Elasticsearch 托管服务已经足够好,但它的限制性很强,如果您需要做更多相关的事情,您应该使用其他提供商。

标签: elasticsearch


【解决方案1】:

我希望这会有所帮助,我想要根据查询文本在文档中的位置进行评分

{
    "query": {
        "bool": {
            "should": [
                {
                    "function_score": {
                        "query": {
                            "match_phrase_prefix": {
                                "field": "query"
                            }
                        },
                        "script_score": {
                            "script": {
                                "lang": "painless",
                                "source": "(params['_source']['field'].toLowerCase().indexOf('query'.toLowerCase())+1)"
                            }
                        },
                        "boost_mode": "max"
                    }
                }
            ]
        }
    }
}

【讨论】:

    猜你喜欢
    • 2018-06-13
    • 2021-08-03
    • 1970-01-01
    • 2019-04-26
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多