How to Configure Facets in a Views REST Export

Last updated on
23 October 2024

1. Install Required Modules

Install the Drupal Rest facets (facets_rest) submodule. This will automatically install the Drupal RESTful Web Services (rest) core module if it's not already present.

2. Create a Drupal View

Create a new Drupal View and select the Search API index you want to use. Ensure you click on "Provide a REST export".

3. Configure View Format

In the Format section, select Facets Serializer. If you access the settings, you'll notice that "Show facets in the output" is enabled by default. This allows you to view a list of facets with related URLs in your REST API endpoint.

4. Set Up View Details

Configure your view with the required fields and specify a path to access the API endpoint. Don't forget to save your view.

5. Add a New Facet

Navigate to BASEURL/admin/config/search/facets to add a new facet. Ensure you select your previously created REST export as the Facet source.

6. Configure the Facet

Choose the field you want to use as a facet and give it a name. After saving, go to the Edit page and select "Array with raw results" as the Widget.

7. Test Your API Endpoint

Visit your API endpoint. You should now see an array of facets that you can utilize in your application.

Help improve this page

Page status: No known problems

You can: