How to Configure Facets in a Views REST Export
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
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.