How to Delete Taxonomies from Algolia

Posted on

At Geekflare, I use Algolia for search, and while testing a few things around Polylang for translation, I noticed translated posts started appearing on the search results.

algolia-search-result-french

This was unpleasant, and we needed to find a way to delete these records from Algolia.

When I logged into the Algolia dashboard, I could see translated posts have taxonomies as Francais.

algolia-taxonomies

But there is no way to delete records from the dashboard. Algolia’s dashboard is minimal; they recommend using their API to manage the records.

After some research, I found a way to delete these entries. You can use cURL or an HTTP client like Postman.

You need the following details as a prerequisite:

  • Algolia application ID
  • Admin API key
  • Index name

The above details are under Settings >> API Keys on the Algolia dashboard.

First, let’s query to confirm you are getting expected records to ensure you don’t delete something else.

curl -X POST 
     -H "X-Algolia-API-Key: ADMIN_API_KEY" 
     -H "X-Algolia-Application-Id: APPLICATION_ID" 
     "https://APPLICATION_ID.algolia.net/1/indexes/INDEX_NAME/query" 
     --data '{"query": "", "filters": "taxonomies.language: Français"}'

Don’t forget to replace ADMIN_API_KEY, APPLICATION_ID, INDEX_NAME with your actual ones.

The above query was able to return the desired records. Now, I am confident to delete the records by using the below query.

curl -X POST 
     -H "X-Algolia-API-Key: ADMIN_API_KEY" 
     -H "X-Algolia-Application-Id: APPLICATION_ID" 
     "https://APPLICATION_ID.algolia.net/1/indexes/INDEX_NAME/deleteByQuery" 
     --data '{"query": "", "filters": "taxonomies.language: Français"}'

If you decide to use Postman, you can add the below headers.

  • X-Algolia-Application-Id
  • X-Algolia-API-Key
postman-algolia-headers

And, here is the successful results.

algolia-delete-records

My requirement was to delete taxonomies but through Algolia API you can manage pretty much everything. You can explore the official delete records API reference for more ideas.