gpt4 book ai didi

php - Elasticsearch:为PHP数组中的多个匹配设置参数

转载 作者:行者123 更新时间:2023-12-03 00:36:05 25 4
gpt4 key购买 nike

我正在寻找使用Boost调整相关性对多个关键字进行直接匹配的Elasticsearch。我为此使用PHP客户端。我很难纠正我有多个具有相同名称的数组索引这一事实。

$params = [
'index' => 'people',
'type' => 'person',
'body' => [
'query' => [
'bool' => [
'should' => [
'match' => [
'Company1' => [
'query' => $order['BillTo_Name'],
'boost' => $_GET['company-name-weight']
]
],
'match' => [
'Address1' => [
'query' => $order['ShipTo_Addr1'],
'boost' => $_GET['address-weight']
]
],
'match' => [
'PostalCode' => [
'query' => $order['ShipTo_Zip'],
'boost' => $_GET['company-name-weight']
]
],
'match' => [
'LastName' => [
'query' => $order['contact'],
'boost' => $_GET['name-weight']
]
]
]
]
]
]
];

这导致我的数组折叠为一个匹配条件,因为我有4个行,并且它们具有相同的数组索引$ params [body] [query] [bool] [should] [match]。
var_dump($params);

array(3) {
["index"]=>
string(5) "leads"
["type"]=>
string(4) "lead"
["body"]=>
array(1) {
["query"]=>
array(1) {
["bool"]=>
array(1) {
["should"]=>
array(1) {
["match"]=>
array(1) {
["LastName"]=>
array(2) {
["query"]=>
string(10) "Parker"
["boost"]=>
string(1) "1"
}
}
}
}
}
}
}

我无所适从,如何用4个单独的匹配来重组此查询,并以PHP客户端可以消化的方式为每个匹配指定boost。

最佳答案

我想在这里张贴是结束我的痛苦所需要的。在此处张贴以供后代使用。解决方案是将每个match子句嵌套一个数组。

$params = [
'index' => 'leads',
'type' => 'lead',
'body' => [
'query' => [
'bool' => [
'should' => [
[
'match' => [
'Company1' => [
'query' => $order['BillTo_Name'],
'boost' => $_GET['company-name-weight']
]
]
],[
'match' => [
'Address1' => [
'query' => $order['ShipTo_Addr1'],
'boost' => $_GET['address-weight']
]
]
],[
'match' => [
'PostalCode' => [
'query' => $order['ShipTo_Zip'],
'boost' => $_GET['company-name-weight']
]
]
],[
'match' => [
'LastName' => [
'query' => $order['contact'],
'boost' => $_GET['name-weight']
]
]
]
]
]
]
]

];

关于php - Elasticsearch:为PHP数组中的多个匹配设置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33678340/

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