About Elasticsearch Indices

When using django-elasticsearch-dsl, create the names of your indices combined of:

  • project name, e.g. "myproject"
  • environment name, e.g. "staging"
  • app name (optionally) and model name, e.g. "blog_post"

Just like this:

1
2
3
4
5
6
7
8
9
@registry.register_document
class BlogPostDocument(Document):
    class Index:
        name = f"myproject_{settings.ENVIRONMENT}_blog_post"
        settings = {
            "number_of_shards": 1,
            "number_of_replicas": 0,
        }
    # …

This way, you can share the same Elasticsearch server for different projects or project environments.

Tips and Tricks Programming Architecture Development Django 5.x Django 4.2 Django 3.2 Elasticsearch