【发布时间】:2015-02-20 00:28:59
【问题描述】:
我在 Laravel 中使用弹性搜索。
所以我有返回正确结果的查询:
$results = Es::search(array(
'index' => 'testindex',
'type' => $type,
'body' => [
'query' => [
'filtered' => [
'query' => [
'match' => [
'_all' => '2015-02'
]
],
'filter' => [
'bool' => [
'must' => [
'term' => [
'type' => 11
]
],
]
]
]
],
'size' => 5,
'from' => 0
]
));
它的作用是:
- 在所有字段中搜索 $query AND
- 字段“类型”必须为 11。
这里是输出:http://pastebin.com/icWniix4 总共有 9 个结果是正确的。
但是当我添加另一个必须项时,它会返回无效结果
$results = Es::search(array(
'index' => 'testindex',
'type' => $type,
'body' => [
'query' => [
'filtered' => [
'query' => [
'match' => [
'_all' => '2015-02'
]
],
'filter' => [
'bool' => [
'must' => [
'term' => [
'type' => 11
],
'term' => [
'public' => 1
]
],
]
]
]
],
'size' => 5,
'from' => 0
]
));
因此,这仅添加了“公共”一词。 它的作用是:
- 在所有字段中搜索 $query AND
- 字段“类型”必须是 11 并且
- 字段“public”必须为 1
所以现在结果总共有 429 个。它忽略“类型”术语并返回“公共”= 1 的所有内容。但是根据文档,如果我使用 MUST,那么它应该匹配所有这些。搜索结果http://pastebin.com/cVcatcyi
那么我怎样才能写出我需要的查询呢? $query + type + public
官方文档没有回答我的问题。
有什么建议吗?
【问题讨论】:
标签: php laravel-4 elasticsearch