0

I have to upgrade one of my customer's web site from Symfony 2.8/Elastic Search 1.7/FOS\elastica-bundle" 3.2 to 3.4/6.2/5.0.3.

I have made a copy of the existing web site on a brand new server with Elastic Search 6.2 installed.

I have read many about this and understood I have to rewrite the Bundle that managed Elastic queries because a lot of methods are outdated, specially DSL filters.

Di you have any idea of what the following code (in the Bundle controller) would become in ES 6.2 :

$query = $request->query->get("query","");       
$finder = $this->container->get("fos_elastica.finder.scls_concert.concert");
$queryBuilder = new QueryBuilder();
$esTextQuery = $queryBuilder->query()->query_string($query);
$esDateFilter = $queryBuilder->filter()->range('date_start',array('gte' => (new \DateTime())->getTimestamp()));

$esQuery = $queryBuilder->query()->filtered($esTextQuery,$esDateFilter);
$result = $finder->findPaginated($esQuery,["size" => 5]);

Many thanks in advance.

Mister PO
  • 3
  • 2

1 Answers1

0

The main issue in the above code is that the filtered query is gone and needs to be replaced by bool:

So I think, you can do something along these lines:

$esDateFilter = new Range( 'date_start', array('gte' => (new \DateTime())->getTimestamp()) );

$esQuery = new BoolQuery();
$esQuery->addMust($esTextQuery);
$esQuery->addFilter($esDateFilter);
$result = $finder->findPaginated($esQuery,["size" => 5]);
Val
  • 207,596
  • 13
  • 358
  • 360
  • I'm afraid the following line is also wrong as DSL filter is not supported anymore : $esDateFilter = $queryBuilder->filter()->range('date_start',array('gte' => (new \DateTime())->getTimestamp())); – Mister PO Aug 31 '18 at 14:50
  • Try simply removing `filter()`, see my updated answer – Val Aug 31 '18 at 14:53
  • Not working, still getting "DSL "filter" not supported " error. I alsor replace $bool with $esQuery. – Mister PO Aug 31 '18 at 15:16
  • Looks better with the following code : $esDateFilter = new Range( 'date_start', array('gte' => (new \DateTime())->getTimestamp()) ); – Mister PO Aug 31 '18 at 15:49
  • Thanks a lot for your help Val, I really appreciate it ! – Mister PO Sep 02 '18 at 06:47