Elasticsearch:在span_query中使用boost?

hiz5n14c  于 2023-06-21  发布在  ElasticSearch
关注(0)|答案(2)|浏览(104)

我想在span_or查询中使用boost,但得到一个错误。
下面是我的elasticsearch代码和返回的错误

GET /addr/_search
{
  "query":{    
    "span_near": {
        "clauses" : [
            { 
              "span_or": { 
                "clauses" : [
                  {
                    "span_term": {
                      "poi": {
                        "value": "long",
                        "boost" : 2.0
                      }
                    }
                  }, 
                  { 
                    "span_term": {
                      "poi": {
                        "value": "mei"
                       }
                    }
                  }
                ]
              }
            },
            { "span_term" : { "poi" : "da" } }
        ],
        "slop" : 1,
        "in_order" : true
    }
  },
  "sort": [{"freq": {"order": "desc"}}]
}
root_cause": [
      {
        "type": "parsing_exception",
        "reason": "span_or [clauses] as a nested span clause can't have non-default boost value [2.0]",
        "line": 15,
        "col": 19
      }
    ]

那么在span_or或span_near查询中可以使用boost吗?就像在bool查询中一样

owfi6suc

owfi6suc1#

boost参数只允许用于外部span查询...如下所述:https://www.elastic.co/guide/en/elasticsearch/reference/current/span-queries.html
只允许在外部span查询上设置boost。复合span查询,如span_near,只使用内部span查询的匹配span列表来查找自己的span,然后使用这些span来生成分数。内部span查询从不计算分数,这就是不允许提升的原因:它们只影响计算分数的方式,而不影响跨度。

GET /addr/_search
{
  "query":{    
    "span_near": {
        "boost" : 2.0 <-------------------- here //untested
        "clauses" : [
            { 
              "span_or": { 
                "boost" : 2.0 <-------------------- here //untested
                "clauses" : [
                  {
                    "span_term": {
                      "poi": {
                        "value": "long",
                        "boost" : 2.0 <-------------- not allowed
                      }
                    }
                  }, 
                  { 
                    "span_term": {
                      "poi": {
                        "value": "mei"
                       }
                    }
                  }
                ]
              }
            },
            { "span_term" : { "poi" : "da" } }
        ],
        "slop" : 1,
        "in_order" : true
    }
  },
  "sort": [{"freq": {"order": "desc"}}]
}
sc4hvdpw

sc4hvdpw2#

关于Span查询评分:

1.只允许在外部span查询上设置boost。
1.内部span查询从不计算分数
复合span查询,如span_near,只使用内部span查询的匹配span列表来查找自己的span,然后使用这些span来生成分数。
https://www.elastic.co/guide/en/elasticsearch/reference/current/span-queries.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/span-queries.html

相关问题