简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM