php - Elasticsearch-php 查询
问题描述
有谁知道弹性搜索-php 示例的好资源,理想情况下涵盖了使用 MySQL 示例的查询。我正在为代码语法和何时使用什么而苦苦挣扎。
例如,我想做一个搜索,其中 $name 必须是字段 'business' 的一部分,并且 'country' 匹配 $country
$params = [
'index' => 'xxxxx',
'type' => 'zzzzz',
'body' => [
'from' => 0,
'size' => $maxResults,
'query' => [
'bool' => [
'must' => [
'match' => ['name' => $searchString],
],
'must' => [
'match' => ['country' => $country],
],
],
],
],
];
第一个“必须”似乎被完全忽略了。删除它将返回完全相同的结果。
我搜索了几个小时。有很多带有简单搜索示例的快速初学者教程,但我已经像上面的示例一样被卡住了一步
谢谢
解决方案
must
一个查询中只能有一个bool
,那么所有的约束都必须是must
数组的元素。试试这样:
$params = [
'index' => 'xxxxx',
'type' => 'zzzzz',
'body' => [
'from' => 0,
'size' => $maxResults,
'query' => [
'bool' => [
'must' => [
[
'match' => ['name' => $searchString],
],
[
'match' => ['country' => $country],
],
]
],
],
],
];
推荐阅读
- python - 如何防止 Heroku 时钟测功机睡在免费套餐上?
- javascript - 如果拖动可拖动元素,引导模式不会在第一次单击背景时关闭
- python - Folium 中的时间滑块 Choropleth 无法正确着色
- firebase - 具有空值安全性的 Dart/Flutter 问题
- c# - 如何从 HttpResponseData 对象获取状态代码和标头数据?
- html - html 菜单按钮在移动设备上不起作用
- javascript - 为什么这个函数返回不合逻辑的结果?
- pdf - 修改可能发生在 pdf 文本的哪个位置?
- r - 如何使用 R 在页面中查找文本的位置?
- python - 如何启动、停止和重新启动线程?