我有这个查询(通过PHP客户端),用于ElasticSearch 6.2:
[
"query"=> [
"bool" => [
"filter" => [
"term" => [ "row.name" => $name ],
"term" => [ "row.origin" => $origin ]
]
]
],
"size" => "10"
]
如果我仅对row.name
或row.origin
使用一个搜索,它就可以工作,但是对两者而言,它都可以像OR一样工作并返回所有结果。如何过滤以仅返回与row.name
和row.origin
答案 0 :(得分:1)
您采取了正确的方法,但我猜您错过了括号。
代替:
[
"query"=> [
"bool" => [
"filter" => [
"term" => [ "row.name" => $name ],
"term" => [ "row.origin" => $origin ]
]
]
],
"size" => "10"
]
您应该具有:
[
"query"=> [
"bool" => [
"filter" => [
["term" => [ "row.name" => $name ]],
["term" => [ "row.origin" => $origin ]]
]
]
],
"size" => "10"
]
在您的情况下,您使用两个相同的(term
)键创建了一个地图:
[
"term" => [ "row.name" => $name ],
"term" => [ "row.origin" => $origin ]
]
第二个term
取代了第一个{实际上,您发送了:
[
"term" => [ "row.origin" => $origin ]
]
要发送多个term
过滤器,您需要将其视为列表:
[
["term" => [ "row.name" => $name ]],
["term" => [ "row.origin" => $origin ]]
]