我的弹性搜索中有一个字段是visibility_boosters,它有两个属性country_id和booster_rate。
我想用这两个字段(country_id和booster_rate(应用多匹配查询。
country_id是动态的,可见性增强标准如下:
0%=>0|5%=>2|10%=>4|15%=>6|20%=>8
比如,如果能见度增强器5%,则增益为2,如果能见度助推器10%,则增益将为4。
如果两个字段在此基础上匹配,我想提升该文档。
我已经尝试了以下解决方案,但对我不起作用。
我的查询:
if ($country && $country != null) {
$params['body']['query']['bool']['should'][] = [
"bool" => [
"must" => [
[ "match" => [ "visibility_boosters.country_id" => $country->id ] ],
[ "match" => [ "visibility_boosters.booster_rate" => 5 ] ],
],
"boost" => 2.0
]
];
$params['body']['query']['bool']['should'][] = [
"bool" => [
"must" => [
[ "match" => [ "visibility_boosters.country_id" => $country->id ] ],
[ "match" => [ "visibility_boosters.booster_rate" => 10 ] ],
],
"boost" => 4.0
]
];
$params['body']['query']['bool']['should'][] = [
"bool" => [
"must" => [
[ "match" => [ "visibility_boosters.country_id" => $country->id ] ],
[ "match" => [ "visibility_boosters.booster_rate" => 15 ] ],
],
"boost" => 6.0
]
];
$params['body']['query']['bool']['should'][] = [
"bool" => [
"must" => [
[ "match" => [ "visibility_boosters.country_id" => $country->id ] ],
[ "match" => [ "visibility_boosters.booster_rate" => 20 ] ],
],
"boost" => 8.0
]
];
}
这些查询只适用于一个匹配查询,如果一个查询匹配,则它将提升单据。我希望如果两个条件都匹配,那么根据可见性标准提升文档。
获取查询的最佳方法是在Kibana搜索之后。做Kibana发现,并选择你的索引。添加具有所需条件的筛选器。还可以为所需数据添加搜索模式,然后单击"刷新"。一旦您的数据显示在页面中,转到右上角的检查。转到请求。寻找JSON格式的查询,您可以获得所需的查询,并在API或其他集成系统需要的任何地方使用它。