Commit 78eb4d29 by Tim Babych Committed by Oleg Marshev

create-index command

parent ae383066
from optparse import make_option
from django.conf import settings
from django.core.management.base import BaseCommand
from elasticutils.contrib.django import get_es
from notesapi.v1.models import NoteMappingType
class Command(BaseCommand):
help = 'Creates the mapping in the index.'
help = 'Creates index and the mapping.'
option_list = BaseCommand.option_list + (
make_option('--drop',
action='store_true',
dest='drop',
default=False,
help='Recreate index'),
)
def handle(self, *args, **options):
#TODO: cretate mapping using elasticutils
pass
if options['drop']:
# drop existing
get_es().indices.delete(index=settings.ES_INDEXES['default'], ignore=404)
get_es().indices.create(
index=settings.ES_INDEXES['default'],
body={
'mappings': {
NoteMappingType.get_mapping_type_name(): NoteMappingType.get_mapping()
}
},
ignore=400 # ignore when present
)
......@@ -111,10 +111,10 @@ class NoteMappingType(MappingType, Indexable):
'user': charfield,
'course_id': charfield,
'usage_id': charfield,
'text': {'type': 'string', 'index': 'snowball', 'store': True},
'quote': {'type': 'string', 'index': 'snowball', 'store': True},
'created': charfield,
'updated': charfield,
'text': {'type': 'string', 'analyzer': 'snowball', 'store': True},
'quote': {'type': 'string', 'analyzer': 'snowball', 'store': True},
'created': {'type': 'date', 'store': True},
'updated': {'type': 'date', 'store': True},
}
}
......
......@@ -15,6 +15,7 @@ from rest_framework.test import APITestCase
from elasticutils.contrib.django import get_es
from .helpers import get_id_token
from notesapi.v1.models import NoteMappingType, note_searcher
from notesapi.management.commands.create_index import Command as CreateIndexCommand
TEST_USER = "test_user_id"
......@@ -73,14 +74,14 @@ class BaseAnnotationViewTests(APITestCase):
@classmethod
def setUpClass(cls):
get_es().indices.create(index=settings.ES_INDEXES['default'], ignore=400)
CreateIndexCommand().handle(drop=True)
get_es().indices.refresh()
get_es().cluster.health(wait_for_status='yellow')
@classmethod
def tearDownClass(cls):
"""
* deletes the test index
deletes the test index
"""
get_es().indices.delete(index=settings.ES_INDEXES['default'])
get_es().indices.refresh()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment