gpt4 book ai didi

elasticsearch - elasticsearch-获得 'function_score'内的中级分数

转载 作者:行者123 更新时间:2023-12-02 22:27:35 32 4
gpt4 key购买 nike

这是我的索引

POST /blogs/1
{
"name" : "learn java",
"popularity" : 100
}

POST /blogs/2
{
"name" : "learn elasticsearch",
"popularity" : 10
}

我的搜索查询:
GET /blogs/_search
{
"query": {
"function_score": {
"query": {
"match": {
"name": "learn"
}
},
"script_score": {
"script": {
"source": "_score*(1+Math.log(1+doc['popularity'].value))"
}
}
}
}
}

返回:
[
{
"_index": "blogs",
"_type": "1",
"_id": "AW5fxnperVbDy5wjSDBC",
"_score": 0.58024323,
"_source": {
"name": "learn elastic search",
"popularity": 100
}
},
{
"_index": "blogs",
"_type": "1",
"_id": "AW5fxqmL8cCMCxtBYOyC",
"_score": 0.43638366,
"_source": {
"name": "learn java",
"popularity": 10
}
}
]

问题:我需要在结果中返回一个额外的字段,这将给我原始分数(只是tf / idf并没有考虑受欢迎程度)

我研究过的内容: script_fields(在获取时不提供对 _score的访问。

最佳答案

问题出在您查询的方式上,它覆盖了_score变量。相反,如果您使用sort,则_score不会更改,并且可以在同一查询中提取。

您可以尝试以这种方式查询:

{
"query": {
"match": {
"name": "learn"
}
},
"sort": [
{
"_script": {
"type": "number",
"script": {
"lang": "painless",
"source": "_score*(1+Math.log(1+doc['popularity'].value))"
},
"order": "desc"
}
},
"_score"
]
}

关于elasticsearch - elasticsearch-获得 'function_score'内的中级分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58819868/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com