webgoesviral
webgoesviral

Reputation: 385

Range Filter Query with elasticsearch in a symfony2 project

$mainQuery = new \Elastica\Query\BoolQuery();
$rangeFilter = new Filtered(
$mainQuery,
   new Range('price', array(
         'gte' => $min,
         'lte' => $max
    ))
  );
$data = $finder->search($rangeFilter);

In my controller Action, I am using above code to filter the elasticsearch data between the price of $min, $max(variables passed to this controller). Somehow the data returned to me is not correct result for my Query.

Am I using a wrong method to implement FOSElasticaBundle methods. Also, if anyone can please share some links or tutorials on how to use elasticsearch with symfony2 or how to make Queries with FOSElasticBundle that'd be great help.

Upvotes: 2

Views: 1443

Answers (1)

Paula Andrea
Paula Andrea

Reputation: 230

I did it work this way...

 $boolQuery= new  Elastica\Filter\Bool();
        $boolQuery->addMust(new Range('created_at', array(
            'gte' => Util::convertDate($dataSearch['fechaInicial']),
            'lte' => Util::convertDate($dataSearch['fechafinal'])
        )));
        $result= $this->finder->find($boolQuery));

It works for me! Here there are more details! https://openclassrooms.com/forum/sujet/foselasticabundle-1

Upvotes: 2

Related Questions