Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elastic.co/Elastic search-具有多个增强查询的相关反馈_Search_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Relevance_Boosting - Fatal编程技术网 elasticsearch,relevance,boosting,Search,elasticsearch,Relevance,Boosting" /> elasticsearch,relevance,boosting,Search,elasticsearch,Relevance,Boosting" />

Elastic.co/Elastic search-具有多个增强查询的相关反馈

Elastic.co/Elastic search-具有多个增强查询的相关反馈,search,elasticsearch,relevance,boosting,Search,elasticsearch,Relevance,Boosting,我正在尝试为弹性搜索实现相关反馈(Elastic.co) 我知道,它允许对正项和负项进行规范,其思想是对负项进行折扣,同时不排除它们,就像布尔型必不可忽略项一样 然而,我正试图实现积极和消极的两个方面 也就是说,我想获取一个包含正负项的列表,并生成一个查询,这样就有了不同的正负提升层,每个层都包含自己的查询项 类似于(伪查询): 我的问题是,这是否可以通过嵌套的boosting查询实现,或者使用多个should子句是否更好 我担心的是,我不确定bool查询的should子句中增加0.2是否仍然会

我正在尝试为弹性搜索实现相关反馈(Elastic.co)

我知道,它允许对正项和负项进行规范,其思想是对负项进行折扣,同时不排除它们,就像布尔型必不可忽略项一样

然而,我正试图实现积极和消极的两个方面

也就是说,我想获取一个包含正负项的列表,并生成一个查询,这样就有了不同的正负提升层,每个层都包含自己的查询项

类似于(伪查询):

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

我担心的是,我不确定bool查询的should子句中增加0.2是否仍然会使文档的分数增加,因为我希望对文档进行折扣,而不是增加分数

对于增强查询,我担心的是我无法控制正项的加权程度


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

似乎可以组合
bool
查询并使用调整boost值

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
           }
         }
       }
     ]
   }
 } 
} 

或者,如果您想在索引时将语言模型编码到集合中,您可以尝试下面描述的方法:

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

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应用自定义的boost效果

下面的布尔查询正在运行基于boost值在弹性搜索索引中提升文档的查询

 {
  "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
  }
}

太棒了,谢谢。我没有意识到负面提升是可能的(我在某个地方读到它们必须大于0)。我已经通过验证器运行过了,它不会抱怨-所以我要试一试!啊哈!因此,有一种方法可以做到这一点。我想我会用这个来扩展这个问题的答案。谢谢
 {
  "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
  }
}