php - 过滤多匹配 ES PHP
问题描述
开始在 ES 上工作。我希望能够使用 PHP 中的过滤器进行 multi_match。我遵循了官方 ES 文档,但我不明白我的错误。
这是代码:
public function search_data_into_index($array)
{
$params = [
'index' => 'skills',
'type' => 'people',
'body' => [
'query' => [
'multi_match' => [
'query' => 'react',
'fields' => [$array[2]],
'fuzziness' => 'AUTO',
],
'filter' => [
'geo_distance' => [
'distance' => '300m',
'location' => '-25, -49'
]
]
]
]
];
$response = $this->client->search($params);
print_r($response);
}
这是我的错误:
{"error":{"root_cause":[{"type":"parsing_exception","reason":"[multi_match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":94}],"type":"parsing_exception","reason":"[multi_match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]
解决方案
multi_match
查询必须位于内部bool/must
:
public function search_data_into_index($array)
{
$params = [
'index' => 'skills',
'type' => 'people',
'body' => [
'query' => [
'bool' => [
'must' => [
'multi_match' => [
'query' => 'react',
'fields' => [$array[2]],
'fuzziness' => 'AUTO',
]
],
'filter' => [
'geo_distance' => [
'distance' => '300m',
'location' => '-25, -49'
]
]
]
]
]
];
$response = $this->client->search($params);
print_r($response);
}
推荐阅读
- java - 关于覆盖jpanelpaintcomponent和相对位置
- c# - 如何在代码中编写 RenderFragment ChildContent
- python - 在不同条件下更改 pandas df 中的列值/在 4 点 likert-scale 上反转答案
- python - 如何在python中使用多个数据在子图中添加图例
- flutter - 在 Flutter 应用程序中切换收藏按钮后,如何在 JSON 本地文件中更新收藏状态布尔值(true/false)
- git - 推送到 GitHub 上的存储库时身份验证失败(从 GitHub Desktop 和命令行)
- javascript - 通过 javascript 将 CSS 添加到元素在控制台中有效,但在 html 结构中无效
- html - 为什么 PayPal Iframe 停留在固定导航栏上方?
- sql - 日期时间值生成 MS SQL
- c# - 为什么弹出阴影不显示?