Statistics
| Branch: | Revision:

root / core / management / commands / index_tickets.py @ 77c65646

History | View | Annotate | Download (1.3 kB)

1
# -*- coding: utf-8 -*- vim:encoding=utf-8:
2
# vim: tabstop=4:shiftwidth=4:softtabstop=4:expandtab
3

    
4
from django.core.management.base import BaseCommand, CommandError
5
from django.conf import settings
6
from pyelasticsearch import ElasticSearch
7
from core.jiramodels import *
8

    
9
class Command(BaseCommand):
10
    args = ''
11
    help = 'Fetches all Jira Tickets and updates indexer'
12

    
13
    def handle(self, *args, **options):
14
        
15
        tickets = JiraIssue.objects.all()
16
        es = ElasticSearch(settings.ELASTIC_SEARCH_SERVER_LOCATION)
17
        try:
18
            es.create_index("%s" %settings.ELASTIC_SEARCH_INDEX)
19
        except Exception as e:
20
            print e
21
        # Take care of mappings
22
        if settings.CUSTOMFIELD_MAPPING:
23
            for mapping in settings.CUSTOMFIELD_MAPPING:
24
                try:
25
                    es.put_mapping("%s" %settings.ELASTIC_SEARCH_INDEX, "issue", {"issue":{"properties":mapping}})
26
                except Exception as e:
27
                    print e
28
        for t in tickets:
29
            print "Parsing %s, %s" %(t.id, t.key)
30
            try:
31
                es.index("%s" %settings.ELASTIC_SEARCH_INDEX, "issue", t.__dict__, id=int(t.id), overwrite_existing=True)
32
            except Exception as e:
33
                    print e
34
            #print "Indexed"
35
        es.refresh("%s" %settings.ELASTIC_SEARCH_INDEX)
36
        print "Done"