Skip to content

Commit

Permalink
Merge pull request #4216 from Jmennius/provision-elasticsearch-command
Browse files Browse the repository at this point in the history
Add provision_elasticsearch command
  • Loading branch information
ericholscher authored Jun 12, 2018
2 parents 7d37f48 + 2cc0723 commit 8a5ce2b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
14 changes: 1 addition & 13 deletions docs/custom_installs/elasticsearch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down
33 changes: 33 additions & 0 deletions readthedocs/core/management/commands/provision_elasticsearch.py
Original file line number Diff line number Diff line change
@@ -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!")

0 comments on commit 8a5ce2b

Please sign in to comment.