我正在为我当前的项目进行弹性搜索。我需要一个基于他们行业的用户过滤器。请看一下我的代码。和mySql查询如下
SELECT U.* FROM `users` `U`
JOIN `user_industries` `UI` ON `UI`.`user_id`=`U`.`id`
WHERE `UI`.`industry_id` IN('1','3','5');
$query = array("from" => $start,
"size" => $recordslimit,
"sort" => array(array('id' => 'desc')),
"query" => array(
"filtered" => array(
"query" => array("match_all" => array()),
"filter" => array(
"bool" => array(
'must' => array(array('term' => array('user_type' => 'v')),
array('term' => array('status' => 'a')),
array('term' => array('industries.id' => 1))
),
'must_not' => array(
array('term' => array('subscription_type' => 'n'))
)
))
)));
我通过了一个行业价值。我怎样才能传递多个行业价值
答案 0 :(得分:1)
好开始!!您可以使用terms
filter代替term
并在1, 3, 5
中指定值array()
来实现您想要的效果:
...
array('terms' => array('industries.id' => array(1, 3, 5)))
...