django-es / django-elasticsearch-dsl

This is a package that allows indexing of django models in elasticsearch with elasticsearch-dsl-py.
Other
1.01k stars 262 forks source link

Multiple websites using ElasticSearch on the same server #108

Open archatas opened 6 years ago

archatas commented 6 years ago

Can you please update the README explaining how to set up several websites using ElasticSearch so that the indexes don't clash (or should I add website-related prefixes to the documents myself)?

barseghyanartur commented 6 years ago

@archatas:

Briefly covered here.

You basically override ELASTICSEARCH_INDEX_NAMES setting for your environments. Prefixing works fine for me.

dev

ELASTICSEARCH_INDEX_NAMES = {
    'search_indexes.documents.address': 'address',
    'search_indexes.documents.author': 'author',
    'search_indexes.documents.book': 'book',
    'search_indexes.documents.city': 'city',
    'search_indexes.documents.publisher': 'publisher',
}

prod

ELASTICSEARCH_INDEX_NAMES = {
    'search_indexes.documents.address': 'prod_address',
    'search_indexes.documents.author': 'prod_author',
    'search_indexes.documents.book': 'prod_book',
    'search_indexes.documents.city': 'prod_city',
    'search_indexes.documents.publisher': 'prod_publisher',
}
archatas commented 6 years ago

Does the command to rebuild index work well in a case of multiple websites indexed with different index prefixes? For example, I might want to rebuild index for example.com. but not for example.org, where these are different Django projects deployed on the same server.

If I run

python manage.py search_index --rebuild

on one website, will it keep the indexes from another website?

barseghyanartur commented 6 years ago

It will remove only indexes listed in the ELASTICSEARCH_INDEX_NAMES. It's also a good way of separating your test environment from dev (or any other).

https://github.com/barseghyanartur/django-elasticsearch-dsl-drf/blob/master/examples/simple/settings/testing.py

Allan-Nava commented 4 years ago

Is possible to have more elasticsearch servers in conf?