【问题标题】:Elastic.co/Elastic search - Relevance feedback with multiple Boosting QueriesElastic.co/Elastic search - 具有多个提升查询的相关性反馈
【发布时间】:2015-11-05 04:58:55
【问题描述】:

我正在尝试为 Elastic Search (Elastic.co) 实施相关性反馈。

我知道boosting queries,它允许指定正负项,其想法是打折负项,而不是像布尔 must_not 那样排除它们。

但是,我正在尝试实现分层提升,无论是正面还是负面。

也就是说,我想获取一个分箱的正负术语列表并生成一个查询,以便有不同的正负提升层,每个层都包含自己的查询词。

类似(伪查询):

query{
 {
 terms: [very relevant terms]
 pos_boost: 3
 }
 {
 terms: [relevant terms]
 pos_boost: 2
 }
 {
 terms: [irrelevant terms]
 neg_boost: 0.6
 }
 {
 terms: [very irrelevant terms]
 neg_boost: 0.3
}
}

我的问题是这是否可以通过嵌套的 boosting 查询来实现,或者我是否最好使用多个 should 子句。

我担心的是,我不确定 bool 查询的 should 子句中 0.2 的提升是否仍然会给文档带来正的分数增加,因为我想打折文档,而不是提供任何分数的增加。

通过提升查询,我担心我无法控制 积极 词的加权程度。

任何帮助或其他实现的建议,将不胜感激。 (我真正想做的是为相关文档创建一个语言模型并使用它来排名,但我不知道如何在弹性中轻松实现。)

【问题讨论】:

    标签: search elasticsearch relevance boosting


    【解决方案1】:

    似乎您可以结合bool 查询并使用boosting query clauses 调整提升值。

    POST so/boost/ {"text": "apple computers"}
    POST so/boost/ {"text": "apple pie recipe"}
    POST so/boost/ {"text": "apple tree garden"}
    POST so/boost/ {"text": "apple iphone"}
    POST so/boost/ {"text": "apple company"}
    
    GET so/boost/_search
    {
     "query": {
       "bool": {
         "must": [
           {
             "match": {
               "text": "apple"
             }
           }
         ], 
         "should": [
           {
             "match": {
               "text": {
                 "query": "pie",
                 "boost": 2
               }
             }
           },
           {
             "match": {
               "text": {
                 "query": "tree",
                 "boost": 2
               }
             }
           },
           {
             "match": {
               "text": {
                 "query": "iphone",
                 "boost": -0.5
               }
             }
           }
         ]
       }
     } 
    } 
    

    【讨论】:

    • 太棒了,谢谢。我不知道负提升是可能的(我在某处读过它们必须> 0)。我已经通过验证器运行了它,它没有抱怨 - 所以我会试一试!
    【解决方案2】:

    或者,如果您想在索引时将语言模型编码到您的集合中,您可以尝试此处描述的方法:Elasticsearch: Influence scoring with custom score field in document

    【讨论】:

    • 啊哈!所以有办法做到这一点。我想我会玩这个,目的是扩大提升查询的答案。谢谢!
    【解决方案3】:

    在查询时根据自定义/变量提升值提升弹性搜索文档(基于优先级的搜索查询),即条件提升。

    Java 编码示例:

    customerKeySearch = QueryBuilders.constantScoreQuery(QueryBuilders.termQuery(keys.type",  "xxx"));
    customerTypeSearch = QueryBuilders.constantScoreQuery(QueryBuilders.termQuery("keys.keyValues.value", "xxxx"));                     
    keyValueQuery = QueryBuilders.boolQuery().must(customerKeySearch).must(customerTypeSearch).boost(2f);
    
    customerKeySearch = QueryBuilders.constantScoreQuery(QueryBuilders.termQuery(keys.type",  "xxx"));
    customerTypeSearch = QueryBuilders.constantScoreQuery(QueryBuilders.termQuery("keys.keyValues.value", "xxxx"));                     
    keyValueQuery = QueryBuilders.boolQuery().must(customerKeySearch).must(customerTypeSearch).boost(6f);
    

    描述和搜索查询:

    弹性搜索有其内部分数计算技术,因此我们需要通过在 java 中将 disableCoord(true) 属性设置为 true 来禁用此机制,以便 BoleanQuery 应用自定义提升效果。

    以下布尔查询正在运行查询,用于根据提升值提升弹性搜索索引中的文档。

     {
      "bool" : {
        "should" : [ {
          "bool" : {
            "must" : [ {
              "constant_score" : {
                "query" : {
                  "term" : {
                    "keys.type" : "XXX"
                  }
                }
              }
            }, {
              "constant_score" : {
                "query" : {
                  "term" : {
                    "keys.keyValues.value" : "XXXX"
                  }
                }
              }
            } ],
            "boost" : 2.0
          }
        }, {
          "bool" : {
            "must" : [ {
              "constant_score" : {
                "query" : {
                  "term" : {
                    "keys.type" : "XXX"
                  }
                }
              }
            }, {
              "constant_score" : {
                "query" : {
                  "term" : {
                    "keys.keyValues.value" : "500072388315"
                  }
                }
              }
            } ],
            "boost" : 6.0
          }
        }, {
          "bool" : {
            "must" : [ {
              "constant_score" : {
                "query" : {
                  "term" : {
                    "keys.type" : "XXX"
                  }
                }
              }
            }, {
              "constant_score" : {
                "query" : {
                  "term" : {
                    "keys.keyValues.value" : "XXXXXX"
                  }
                }
              }
            } ],
            "boost" : 10.0
          }
        } ],
        "disable_coord" : true
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-28
      • 2016-11-24
      • 1970-01-01
      • 2017-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多