gpt4 book ai didi

elasticsearch - ElasticSearch-嵌套在过滤器中的script_score不影响得分-为什么?

转载 作者:行者123 更新时间:2023-12-02 22:26:57 25 4
gpt4 key购买 nike

使用的属性:

{
"mappings": {
"properties": {
"attribute_must_1": {
"type": "nested"
},
"attribute_1": {
"type": "nested"
},
"attribute_2": {
"type": "nested"
},
}
}
}
输入测试文件:
POST _bulk
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":9},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":9},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":8},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":7},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":11},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":5},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":10},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":6},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":7},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":7},"attribute_2":{"id":3}}
实际查询:
q = {
"size": 10,
"query": {
"function_score": {
"query": {
"bool": {
"filter": [
],
"must": [
{
"nested": {
"path": "attribute_must_1",
"query": {
"term": {
"attribute_must_1.id": "1"
}
}
}
}
]
}
},
"boost": 1,
"functions": [
{
"filter": {
"nested": {
"path": "attribute_1",
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "decayNumericLinear(params.origin, params.scale, params.offset, params.decay, doc['attribute_1.id'].value)",
"params": {
"origin": 10,
"scale": 5,
"decay": 2,
"offset": 0
}
}
}
},
}
},
"weight": 30
},
{"filter": {"nested": {"path": "attribute_2", "query": {"term": {"attribute_2.id": "3"}}}}, "weight": 70},

],
"score_mode": "sum",
"boost_mode": "replace"
}
},
"sort": [
"_score",
{
"date_deposit": {
"order": "desc"
}
}
]
}
我正在尝试添加一个带有嵌套字段“attribute_1”的新过滤器,我想在该字段中计算实际值与所有其他文档的值之间的距离,但对得分没有影响,我可以看到:
对于找到的attribute_1:
文件= [9、9、9、10、9、9、4、9、3、9]
我得到了(从2个属性中获得30%和70%的权重之和):
分数= [100,100,100,100,100,100,100,100,100,100]
因此它看起来相当二进制,而应该是线性函数。
我想要的是这样的:
用于找到的文档值:[10、9、8、3、10]
输入值为10->我希望具有:
得分(以百分比表示):[100%,90%,80%,30%,100%]
我希望得到一个简单的分数,其输出范围为0-100%,但包括以下方式来自多个属性(attribute_1,attribute_2,...)的部分分数:

基于距离(即0%到30%之间的任何值)的线性分数中来自attribute_1的
  • 分数
  • 来自attribute_2的
  • 得分是0%或70%(字词查询)

  • 我尝试了各种变体,但没有任何效果-正确的做法是什么?我的印象是 filter查询无法以某种方式执行script_scores ...
    我希望有人可以帮助我吗?
    巨大的THNX!

    最佳答案

    I have tried different variations, but nothing works - what is the correct way of doing that? I have the impression that the filter query can't do script_scores somehow ...


    你是对的。如 documentation中所述-“在过滤器上下文中,查询子句回答问题“此文档与该查询子句匹配吗?”答案很简单,是或否- 不会计算分数。过滤器上下文主要用于过滤结构化数据,例如。
    我建议您不要在需要评分的查询中使用过滤器。

    关于elasticsearch - ElasticSearch-嵌套在过滤器中的script_score不影响得分-为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62810751/

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