有没有人知道elasticsearch示例有一个很好的资源,最好包括以MySQL为例的查询。我正在为代码语法和何时使用什么而挣扎。
例如,我想搜索$name必须是字段“业务”的一部分,以及“country”与$country匹配的位置
$params = [
'index' => 'xxxxx',
'type' => 'zzzzz',
'body' => [
'from' => 0,
'size' => $maxResults,
'query' => [
'bool' => [
'must' => [
'match' => ['name' => $searchString],
],
'must' => [
'match' => ['country' => $country],
],
],
],
],
];第一个“必须”似乎被完全忽略了。删除它将返回完全相同的结果。
我到处找了几个小时。有许多简单的搜索示例的快速入门教程,但我已经被困在了更远的一步,如上面的示例。
谢谢
发布于 2020-03-04 10:44:47
在一个must查询中只能有一个bool,那么所有约束都必须是must数组的元素。试着像这样做:
$params = [
'index' => 'xxxxx',
'type' => 'zzzzz',
'body' => [
'from' => 0,
'size' => $maxResults,
'query' => [
'bool' => [
'must' => [
[
'match' => ['name' => $searchString],
],
[
'match' => ['country' => $country],
],
]
],
],
],
];https://stackoverflow.com/questions/60522280
复制相似问题