本文介绍了如何从Elasticsearch Painless脚本访问术语位置/偏移量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们使用AWS Elasticsearch,该版本支持版本5起的无痛脚本编写.我需要访问术语位置/偏移量在我的自定义得分脚本中.
We use AWS Elasticsearch, which support Painless scripting from version 5.I need an access to term positions/offsets in my custom score script.
在旧的Groovy脚本中,它起作用了:
In old Groovy scripting it worked:
"query": {
"function_score": {
"query": {"match_phrase": {"text": "life"} },
"script_score": {
"script": {
"lang": "groovy",
"inline": "termInfo=_index['text'].get('life', _POSITIONS);"
}
},
"boost_mode": "multiply"
}
}
但不适用于Painless.它返回编译错误".
But it does not work with Painless. It returns 'compile error'.
推荐答案
我希望这会有所帮助,我希望根据查询文本在文档中的位置获得分数
I hope this helps, I wanted scores based on the position of the query text in the document
{
"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"
}
}
]
}
}
}
这篇关于如何从Elasticsearch Painless脚本访问术语位置/偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!