How do I add custom facets to listing and search?

Faceted navigation in eCommerce allows customers the ability to refine down a catalog of products based on their filter criteria.

In order to define facets against a document, you must first register the facet group. This should be done within the boot() method of a ServiceProvider or the setup() method of a module ServiceProvider.

\Aero\Search\FacetSettings::registerFacet('stock', 'Stock Status');

The document structure can then be extended to add the facet to the document’s data.

\Aero\Search\Elastic\Documents\ListingDocument::add('string-facets', function ($document) {
    $stock = $document->getModel()->availableStock() > 0;

    return [
        \Aero\Search\Elastic\Facet::create('stock', 'Stock Status', (int) $stock, $stock ? 'In-stock' : 'Out of stock'),


Re-index the documents after any modifications to the document structure.

Articles in this section

Was this article helpful?
0 out of 0 found this helpful