gpt4 book ai didi

php - 从ID中排除结果从elasticsearch-php中的搜索

转载 作者:行者123 更新时间:2023-12-03 01:02:20 25 4
gpt4 key购买 nike

我正在尝试类似的操作:

$params['body']['query']['bool']['must_not']['id']['value']=$pid;

但这是行不通的。需要有关正确语法的帮助。

完整代码:
$pid = $_GET['pid'];
$params = array();
$params['index'] = 'xyz';
$params['type'] = 'product';
$params['body']['query']['filtered']['filter']['and'][]['term']['userid'] = $uid;
$params['body']['query']['filtered']['filter']['and'][]['term']['categoryid3'] = $pc;
$params['body']['query']['bool']['must_not']['id']['value']=$pid;
$params['size'] ='5';
$result = $client->search($params);

更新了完整代码
$pid = $_GET['pid'];
$params = array();
$params['index'] = 'xyz';
$params['type'] = 'product';
$params['body']['query']['filtered']['filter']['and'][]['term']['userid'] = $uid;
$params['body']['query']['filtered']['filter']['and'][]['term']['categoryid3'] = $pc;
$params['body']['query']['filtered']['filter']['not'][]['ids']['values'] = [$pid];
$params['size'] ='5';
$result = $client->search($params);

现在,它只显示该结果,而不是用pid排除该结果。

注意:我自己解决了。.在答案部分中添加

最佳答案

正确的查询是 ids 而不是id

$params['body']['query']['bool']['must_not']['ids']['values'] = [$pid];
^ ^ ^ ^
| | | |
fix this and this and this

除了您的查询格式不正确外,还应该
$params['body']['query']['filtered']['filter']['not'][]['ids']['values'] = [$pid];

关于php - 从ID中排除结果从elasticsearch-php中的搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35475009/

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