algoliasearch-django-example.
- Compatible with Python 3.8 or later.
- Supports Django 4 and 5.
Install
Configure Django settings for Algolia
In your Django settings, addalgoliasearch_django to INSTALLED_APPS and add these two settings:
Python
-
INDEX_PREFIXA prefix for all indices. Use it to separate different indices, likesite1_Productsandsite2_Products. -
INDEX_SUFFIXA suffix for all indices. Use it to differentiate development and production environments, such asLocation_devandLocation_prod. -
AUTO_INDEXINGIf true (default), models are automatically synced with Algolia. -
RAISE_EXCEPTIONSRaise exceptions for network errors instead of logging them (defaults to the value ofsettings.DEBUG).
Define your index
Create anindex.py in each app with the models you want to index.
Inside this file, call algoliasearch.register() for each model:
Python
AlgoliaIndex and using the register decorator:
Python
Connection errors
If you get one of these errors:Impossible to connect, Unable to connect,
or Unreachable hosts:
- Ensure you’re using the correct application ID and API key. You can find your credentials on your Algolia dashboard.
- Check for recent changes in your code.
- Check the status of your data center provider.
If you’re using Firebase, you can only access Algolia from a paid Firebase tier.
- The name of your framework integration (Django) and its version number
- A code snippet to reproduce the issue
- Error message or stack trace (if applicable)
- The name of the Algolia index that’s causing problems
- The exact UTC time of the event
-
If you can’t connect to the Algolia API from your browser, send the output from
community.algolia.com/diag. -
If you can’t connect to the Algolia API from your servers, send the output from the following command (run on any affected server):
Replace
ALGOLIA_APPLICATION_ID with your Algolia application ID.Handle indexing errors
AnyRecord at the position XX objectID=XX is too big errors during indexing are because you exceeded the size limit for records.
Trim oversized records to fit the record size limit, then retry indexing.