# Path: app/mappings.py
# class RepoInfoDoc(DocType):
#     owner_id = Keyword()
#     owner_username = Keyword()
#     owner_type = Keyword()
#     name = Text(text_analyzer, fields={'raw': Keyword()})
#     full_name = Text(text_analyzer, fields={'raw': Keyword()})
#     description = Text(text_analyzer)
#     language = Keyword()
#     created_at = Date()
#     updated_at = Date()
#     pushed_at = Date()
#     homepage = Keyword()
#     size = Integer()
#     stargazers_count = Integer()
#     forks_count = Integer()
#     subscribers_count = Integer()
#     fork = Boolean()
#     has_issues = Boolean()
#     has_projects = Boolean()
#     has_downloads = Boolean()
#     has_wiki = Boolean()
#     has_pages = Boolean()
#     open_issues_count = Integer()
#     topics = Keyword(multi=True)
# 
#     class Meta:
#         index = repo_index._name
# 
#     @classmethod
#     def bulk_save(cls, documents):
#         dicts = (d.to_dict(include_meta=True) for d in documents)
#         return bulk(client, dicts)
# 
#     def save(self, **kwargs):
#         return super(RepoInfoDoc, self).save(**kwargs)
# 
# Path: app/models.py
# class RepoInfo(models.Model):
#     owner_id = models.IntegerField()
#     owner_username = models.CharField(max_length=39)
#     owner_type = models.CharField(max_length=16)
#     name = models.CharField(max_length=100)
#     full_name = models.CharField(max_length=140, unique=True)
#     description = models.TextField(max_length=191)
#     language = models.CharField(max_length=32)
#     created_at = models.DateTimeField()
#     updated_at = models.DateTimeField()
#     pushed_at = models.DateTimeField()
#     homepage = models.URLField(max_length=255, null=True, blank=True)
#     size = models.IntegerField()
#     stargazers_count = models.IntegerField()
#     forks_count = models.IntegerField()
#     subscribers_count = models.IntegerField()
#     fork = models.BooleanField()
#     has_issues = models.BooleanField()
#     has_projects = models.BooleanField()
#     has_downloads = models.BooleanField()
#     has_wiki = models.BooleanField()
#     has_pages = models.BooleanField()
#     open_issues_count = models.IntegerField()
#     topics = ListTextField(base_field=models.CharField(max_length=255))
# 
#     def __str__(self):
#         return self.full_name
# 
#     @staticmethod
#     def create_one(repo_dict):
#         repo = RepoInfo()
#         try:
#             repo.id = repo_dict['id']
#             repo.owner_id = repo_dict['owner']['id']
#             repo.owner_username = repo_dict['owner']['login']
#             repo.owner_type = repo_dict['owner']['type']
#             repo.name = repo_dict['name']
#             repo.full_name = repo_dict['full_name']
#             repo.description = repo_dict['description']
#             repo.language = repo_dict['language']
#             repo.created_at = repo_dict['created_at']
#             repo.updated_at = repo_dict['updated_at']
#             repo.pushed_at = repo_dict['pushed_at']
#             repo.homepage = repo_dict['homepage']
#             repo.size = repo_dict['size']
#             repo.subscribers_count = repo_dict['subscribers_count']
#             repo.stargazers_count = repo_dict['stargazers_count']
#             repo.forks_count = repo_dict['forks_count']
#             repo.fork = repo_dict['fork']
#             repo.has_issues = repo_dict['has_issues']
#             repo.has_projects = repo_dict['has_projects']
#             repo.has_downloads = repo_dict['has_downloads']
#             repo.has_wiki = repo_dict['has_wiki']
#             repo.has_pages = repo_dict['has_pages']
#             repo.open_issues_count = repo_dict['open_issues_count']
#             repo.topics = repo_dict['topics']
#         except (KeyError, TypeError) as e:
#             print(e)
#             print(repo_dict)
#             return
# 
#         try:
#             repo.save()
#         except IntegrityError:
#             pass


from django.core.management.base import BaseCommand
from app.mappings import RepoInfoDoc
from app.models import RepoInfo
            documents = []
            for repo_info in qs_chunk:
                repo_info_doc = RepoInfoDoc()
                repo_info_doc.meta.id = repo_info.id
                repo_info_doc.owner_id = repo_info.owner_id
                repo_info_doc.owner_username = repo_info.owner_username
                repo_info_doc.owner_type = repo_info.owner_type
                repo_info_doc.name = repo_info.name
                repo_info_doc.full_name = repo_info.full_name
                repo_info_doc.description = repo_info.description
                repo_info_doc.language = repo_info.language
                repo_info_doc.created_at = repo_info.created_at
                repo_info_doc.updated_at = repo_info.updated_at
                repo_info_doc.pushed_at = repo_info.pushed_at
                repo_info_doc.homepage = repo_info.homepage
                repo_info_doc.size = repo_info.size
                repo_info_doc.stargazers_count = repo_info.stargazers_count
                repo_info_doc.forks_count = repo_info.forks_count
                repo_info_doc.subscribers_count = repo_info.subscribers_count
                repo_info_doc.fork = repo_info.fork
                repo_info_doc.has_issues = repo_info.has_issues
                repo_info_doc.has_projects = repo_info.has_projects
                repo_info_doc.has_downloads = repo_info.has_downloads
                repo_info_doc.has_wiki = repo_info.has_wiki
                repo_info_doc.has_pages = repo_info.has_pages
                repo_info_doc.open_issues_count = repo_info.open_issues_count
                repo_info_doc.topics = repo_info.topics

                documents.append(repo_info_doc)


# Path: app/mappings.py
# class RepoInfoDoc(DocType):
#     owner_id = Keyword()
#     owner_username = Keyword()
#     owner_type = Keyword()
#     name = Text(text_analyzer, fields={'raw': Keyword()})
#     full_name = Text(text_analyzer, fields={'raw': Keyword()})
#     description = Text(text_analyzer)
#     language = Keyword()
#     created_at = Date()
#     updated_at = Date()
#     pushed_at = Date()
#     homepage = Keyword()
#     size = Integer()
#     stargazers_count = Integer()
#     forks_count = Integer()
#     subscribers_count = Integer()
#     fork = Boolean()
#     has_issues = Boolean()
#     has_projects = Boolean()
#     has_downloads = Boolean()
#     has_wiki = Boolean()
#     has_pages = Boolean()
#     open_issues_count = Integer()
#     topics = Keyword(multi=True)
# 
#     class Meta:
#         index = repo_index._name
# 
#     @classmethod
#     def bulk_save(cls, documents):
#         dicts = (d.to_dict(include_meta=True) for d in documents)
#         return bulk(client, dicts)
# 
#     def save(self, **kwargs):
#         return super(RepoInfoDoc, self).save(**kwargs)
# 
# Path: app/models.py
# class RepoInfo(models.Model):
#     owner_id = models.IntegerField()
#     owner_username = models.CharField(max_length=39)
#     owner_type = models.CharField(max_length=16)
#     name = models.CharField(max_length=100)
#     full_name = models.CharField(max_length=140, unique=True)
#     description = models.TextField(max_length=191)
#     language = models.CharField(max_length=32)
#     created_at = models.DateTimeField()
#     updated_at = models.DateTimeField()
#     pushed_at = models.DateTimeField()
#     homepage = models.URLField(max_length=255, null=True, blank=True)
#     size = models.IntegerField()
#     stargazers_count = models.IntegerField()
#     forks_count = models.IntegerField()
#     subscribers_count = models.IntegerField()
#     fork = models.BooleanField()
#     has_issues = models.BooleanField()
#     has_projects = models.BooleanField()
#     has_downloads = models.BooleanField()
#     has_wiki = models.BooleanField()
#     has_pages = models.BooleanField()
#     open_issues_count = models.IntegerField()
#     topics = ListTextField(base_field=models.CharField(max_length=255))
# 
#     def __str__(self):
#         return self.full_name
# 
#     @staticmethod
#     def create_one(repo_dict):
#         repo = RepoInfo()
#         try:
#             repo.id = repo_dict['id']
#             repo.owner_id = repo_dict['owner']['id']
#             repo.owner_username = repo_dict['owner']['login']
#             repo.owner_type = repo_dict['owner']['type']
#             repo.name = repo_dict['name']
#             repo.full_name = repo_dict['full_name']
#             repo.description = repo_dict['description']
#             repo.language = repo_dict['language']
#             repo.created_at = repo_dict['created_at']
#             repo.updated_at = repo_dict['updated_at']
#             repo.pushed_at = repo_dict['pushed_at']
#             repo.homepage = repo_dict['homepage']
#             repo.size = repo_dict['size']
#             repo.subscribers_count = repo_dict['subscribers_count']
#             repo.stargazers_count = repo_dict['stargazers_count']
#             repo.forks_count = repo_dict['forks_count']
#             repo.fork = repo_dict['fork']
#             repo.has_issues = repo_dict['has_issues']
#             repo.has_projects = repo_dict['has_projects']
#             repo.has_downloads = repo_dict['has_downloads']
#             repo.has_wiki = repo_dict['has_wiki']
#             repo.has_pages = repo_dict['has_pages']
#             repo.open_issues_count = repo_dict['open_issues_count']
#             repo.topics = repo_dict['topics']
#         except (KeyError, TypeError) as e:
#             print(e)
#             print(repo_dict)
#             return
# 
#         try:
#             repo.save()
#         except IntegrityError:
#             pass


# Path: app/management/commands/sync_data_to_es.py
from django.core.management.base import BaseCommand
from app.mappings import RepoInfoDoc
from app.models import RepoInfo

            documents = []
            for repo_info in qs_chunk:
                repo_info_doc = RepoInfoDoc()
                repo_info_doc.meta.id = repo_info.id
                repo_info_doc.owner_id = repo_info.owner_id
                repo_info_doc.owner_username = repo_info.owner_username
                repo_info_doc.owner_type = repo_info.owner_type
                repo_info_doc.name = repo_info.name
                repo_info_doc.full_name = repo_info.full_name
                repo_info_doc.description = repo_info.description
                repo_info_doc.language = repo_info.language
                repo_info_doc.created_at = repo_info.created_at
                repo_info_doc.updated_at = repo_info.updated_at
                repo_info_doc.pushed_at = repo_info.pushed_at
                repo_info_doc.homepage = repo_info.homepage
                repo_info_doc.size = repo_info.size
                repo_info_doc.stargazers_count = repo_info.stargazers_count
                repo_info_doc.forks_count = repo_info.forks_count
                repo_info_doc.subscribers_count = repo_info.subscribers_count
                repo_info_doc.fork = repo_info.fork
                repo_info_doc.has_issues = repo_info.has_issues
                repo_info_doc.has_projects = repo_info.has_projects
                repo_info_doc.has_downloads = repo_info.has_downloads
                repo_info_doc.has_wiki = repo_info.has_wiki
                repo_info_doc.has_pages = repo_info.has_pages
                repo_info_doc.open_issues_count = repo_info.open_issues_count
                repo_info_doc.topics = repo_info.topics

                documents.append(repo_info_doc)


            RepoInfoDoc.bulk_save(documents)