【发布时间】:2017-09-22 23:04:38
【问题描述】:
目前,我正在尝试在多个字段中使用 should 子句以及在一个字段中使用 must 子句来查询弹性搜索。
用 SQL 我会写这个查询:
SELECT * FROM test where ( titleName='Business' OR titleName='Bear') AND (status='Draft' OR status='Void') AND creator='bob'
我试过这个:
$params = [
'index' => myindex,
'type' => mytype,
'body' => [
"from" => 0,
"size" => 1000,
'query' => [
'bool' => [
'must' => [
'bool' => [
'should' => [
['match' => ['titleName' => 'Business']],
['match' => ['titleName' => 'Bear']]
]
],
'should' => [
['match' => ['status' => 'Draft']],
['match' => ['status' => 'Void']]
]
'must' => [
['match'] => ['creator' => 'bob']
]
]
]
]
]
];
上述查询字符串使用单个状态字段或单个标题字段。但它不适用于这两个领域。
有人有解决办法吗?
【问题讨论】:
标签: elasticsearch