1
votes

I have a sf2 service to make a search request on an elasticasearch server with foselasticabundle. Initialy i made a request with a filter:

public function findAll()
{
    $query = new \Elastica\Query\MatchAll();
    $response = new \Elastica\Query\Filtered($query, self::setFilter());
    return $response;
}

public function setFilter()
{
    $filter = new \Elastica\Filter\Bool();
    $filter->addMust(new \Elastica\Filter\Term(array('active' => true)));
    return $filter;
}

In my controller i get the count of this request :

    $search = $this->get("mb.search");
    $query = $search->findAll();
    $nbOnline = $this->get("fos_elastica.index.xxxx.yy")->count($query);

This code work fine. I would like to add a filter based on a array :

$languages = array(1,3,5)

I didn't find the good way too add this new filter in my query. I hope you can help me on this case. Thanks in advance

1

1 Answers

2
votes

You can use "Terms" filter for this task, here is the PHP implementation.

You code should be looked like this:

new \Elastica\Filter\Terms(array('MY_FIELD' => array(1,3,5)))