我正在使用elasticSearch进行搜索,但是我想对其进行过滤,并且搜索必须匹配两个过滤器。
这是代码:
"query" => [
"bool" => [
"must" => [
'multi_match'=> [
'query'=> $this->input->get('search'),
'fields'=> ["title^2", "description"]
]
],
"filter" => [
"terms" => [
"Categories" => ['Featured Works']
],
"terms" => [
"Tags" => ['Merida']
]
]
]
]
携带搜索结果,但将过滤器作为“或”,我想要一个“与”
答案 0 :(得分:0)
问题在于如何在PHP关联数组中定义terms
过滤器。由于两者具有相同的键,因此只有一个键会出现在您的查询中。改为这样:
"filter" => [
[
"terms" => [
"Categories" => ['Featured Works']
]
],
[
"terms" => [
"Tags" => ['Merida']
]
]
]