From 2cc0723b29f8eae9fd6ed16f2c7072aa6ca95b40 Mon Sep 17 00:00:00 2001 From: Yevgeny Popovych Date: Wed, 6 Jun 2018 22:24:10 +0300 Subject: [PATCH] Add provision_elasticsearch command This will aid automatic bootstrapping of RTD and improve maintainability of this approach. Signed-off-by: Yevgeny Popovych --- docs/custom_installs/elasticsearch.rst | 14 +------- .../commands/provision_elasticsearch.py | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 readthedocs/core/management/commands/provision_elasticsearch.py diff --git a/docs/custom_installs/elasticsearch.rst b/docs/custom_installs/elasticsearch.rst index 5c2cc68496f..3612374594a 100644 --- a/docs/custom_installs/elasticsearch.rst +++ b/docs/custom_installs/elasticsearch.rst @@ -99,19 +99,7 @@ Index the data available at RTD database You need to create the indexes:: - from readthedocs.search.indexes import Index, ProjectIndex, PageIndex, SectionIndex - - index = Index() - index_name = index.timestamped_index() - index.create_index(index_name) - index.update_aliases(index_name) - # Update mapping - proj = ProjectIndex() - proj.put_mapping() - page = PageIndex() - page.put_mapping() - sec = SectionIndex() - sec.put_mapping() + $ python manage.py provision_elasticsearch In order to search through the RTD database, you need to index it into the elasticsearch index:: diff --git a/readthedocs/core/management/commands/provision_elasticsearch.py b/readthedocs/core/management/commands/provision_elasticsearch.py new file mode 100644 index 00000000000..9f29fa37a9e --- /dev/null +++ b/readthedocs/core/management/commands/provision_elasticsearch.py @@ -0,0 +1,33 @@ +"""Provision Elastic Search""" + +from __future__ import absolute_import +import logging + +from django.core.management.base import BaseCommand + +from readthedocs.search.indexes import Index, PageIndex, ProjectIndex, SectionIndex + +log = logging.getLogger(__name__) + + +class Command(BaseCommand): + + help = __doc__ + + def handle(self, *args, **options): + """Provision new ES instance""" + index = Index() + index_name = index.timestamped_index() + + log.info("Creating indexes..") + index.create_index(index_name) + index.update_aliases(index_name) + + log.info("Updating mappings..") + proj = ProjectIndex() + proj.put_mapping() + page = PageIndex() + page.put_mapping() + sec = SectionIndex() + sec.put_mapping() + log.info("Done!")