FriendsOfSymfony / FOSElasticaBundle

Elasticsearch PHP integration for your Symfony project using Elastica.
http://friendsofsymfony.github.io
MIT License
1.25k stars 793 forks source link

Elatica finder doing database query (Doctrine) #1872

Open muratsac opened 2 years ago

muratsac commented 2 years ago

Search code snippet

$boolQuery = new \Elastica\Query\BoolQuery();
$fieldQuery = new \Elastica\Query\MatchQuery();
$fieldQuery->setFieldQuery('name', 'Alt');
$boolQuery->addShould($fieldQuery);
$data = $this->finder->find($boolQuery);

Logs

[Application] Jul 11 09:29:30 |INFO   | ELASTI category/_search (POST) 7.95 ms 0={"query":{"bool":{"should":[{"match":{"name":{"query":"Alt"}}}]}}}

[Application] Jul 11 09:29:30 |DEBUG  | DOCTRI SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.slug AS slug_2, c0_.order_number AS order_number_3, c0_.title AS title_4, c0_.parent_id AS parent_id_5, c0_.image AS image_6 FROM category c0_ WHERE c0_.id IN (?) 0=["2"]

Why is there a doctrine query?

DavidGarciaCat commented 2 years ago

It also makes me question why. I really want to use FOS Elastica as a way to expedite slow database queries, and I have all the mapping through related Object IDs, and everything is set up with JMS Serializer, so I don't understand why the project runs FOS Elastica queries + ORM queries too

DavidGarciaCat commented 2 years ago

Then we will get an Array instead of an Object. That's not what should happen.

If the bundle works correctly, then the data is synchronised, so there is no need to run queries. Otherwise, why should we use Elastica instead of Doctrine, if Elasrica runs Doctrine queries? It doesn't make any sense.

The most I can imagine is to offer the Dev to enable Doctrine queries instead of making them by default.

-

( this was a reply for the following message )

$this->finder->find($boolQuery);

after getting the results from elasticsearch, find method transforms and maps with your object class. so if you want to avoid that, I think you can use findRaw method instead.