FOSElasticaBundle
FOSElasticaBundle copied to clipboard
Feature suggestion: implement aggregation result to model transformers
While it's possible to get aggregation results in FOSElastica, there currently is no built-in method to transform these results into real models. While this probably can't be implemented with just any type of aggregation, there are certainly cases where this both makes sense and is easy to implement.
For example, I need to filter product manufacturers by product category to display them in a secondary filter. I have two ways to achieve this:
- I can store this indirect relation in the manufacturer index. I tried to, but apparently indexing becomes super slow when huge numbers of database records are involved. With 1.5M products made by several hundred manufacturers and assigned to a few thousand categories, each MySQL query (I'm pasting an example below) was taking me anywhere between several seconds and several minutes to execute. Most attempts to visit the page during indexing resulted in a timeout error.
- I can store manufacturers as a nested object (or just their ids as a property) in product index and get them as an aggregation when querying the product index. Afterwards, I can easily get them by id from either Elasticsearch or MySQL. This means that no indirect relations need to be indexed or updated, thus considerably lowering the amount of time and resources required to seed or update the index.
I'm going down the second route at the moment, but I noticed that there don't seem to be any transformers I could use to transform an aggregation result array into entities. This is a feature suggestion to implement that.
Example long MySQL query:
SELECT * FROM category s0_ WHERE s0_.id IN (SELECT s1_.category_id AS sclr_12 FROM product_category s1_ WHERE s1_.product_id IN (SELECT s2_.id FROM product s2_ WHERE s2_.manufacturer_id = ?))