kishan kurivella
kishan kurivella

Reputation: 599

elastic search: Advanced Filter Query

I am Working on Elastic Search for My current Project. I need a filter for users based on their industries. please look at my code once. and mySql query as follows

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'))
                            )
                        ))
        )));

I passed one Industry Value. how can i pass multiple values of industries

Upvotes: 0

Views: 295

Answers (1)

Val
Val

Reputation: 217354

Great start !! You can achieve what you want by using a terms filter instead of a term one and specifying the values 1, 3, 5 in an array():

...
array('terms' => array('industries.id' => array(1, 3, 5)))
...

Upvotes: 1

Related Questions