alleyinteractive / searchpress

Elasticsearch integration for WordPress.
84 stars 12 forks source link

Allow es aggregation in non-search-like (main) queries #186

Closed renatonascalves closed 1 month ago

renatonascalves commented 2 months ago

Description

Currently, it is not easy to add an aggregation to a tag archive page/query. And getting the aggregation results back.

Tools like the Elasticsearch Extensions only work for search related queries: https://github.com/alleyinteractive/elasticsearch-extensions/blob/bf99e9819ea93f173a465a3b9cd5f298d63b47f8/lib/adapters/class-searchpress.php#L494

Queries that someone is searching something, but not for direct queries, getting an archive page results with additional aggregations.

It is currently possible to add an aggregation to the es request while using the es-wp-query extension, I tested using this hook: https://github.com/alleyinteractive/es-wp-query/blob/1c7402b2f92fd9327e0189a39c85c2ab8b6ea2ec/class-es-wp-query-wrapper.php#L1225

But not getting the results back since there is no way to attach the results to the main query.

Use Case

Adding an aggregation to the es query that's performed in the main query of a WordPress object. Like an archive/tag page request.