def build(self): """Returns a reindexer that will return either all domains with case search enabled, or a single domain if passed in """ limit_to_db = self.options.pop('limit_to_db', None) domain = self.options.pop('domain', None) limit_db_aliases = [limit_to_db] if limit_to_db else None initialize_index_and_mapping(get_es_new(), CASE_SEARCH_INDEX_INFO) try: if domain is not None: if not domain_needs_search_index(domain): raise CaseSearchNotEnabledException( "{} does not have case search enabled".format(domain)) domains = [domain] else: # return changes for all enabled domains domains = domains_needing_search_index() change_provider = get_domain_case_change_provider( domains=domains, limit_db_aliases=limit_db_aliases) except ProgrammingError: # The db hasn't been intialized yet, so skip this reindex and complain. return _fail_gracefully_and_tell_admins() else: return PillowChangeProviderReindexer( get_case_search_processor(), change_provider=change_provider, )
def build(self): limit_to_db = self.options.pop('limit_to_db', None) domain = self.options.pop('domain') if not domain_needs_search_index(domain): raise CaseSearchNotEnabledException( "{} does not have case search enabled".format(domain)) iteration_key = "CaseSearchResumableToElasticsearchPillow_{}_reindexer_{}_{}".format( CASE_SEARCH_INDEX_INFO.index, limit_to_db or 'all', domain or 'all') limit_db_aliases = [limit_to_db] if limit_to_db else None accessor = CaseReindexAccessor(domain=domain, limit_db_aliases=limit_db_aliases) doc_provider = SqlDocumentProvider(iteration_key, accessor) return ResumableBulkElasticPillowReindexer( doc_provider, elasticsearch=get_es_new(), index_info=CASE_SEARCH_INDEX_INFO, doc_transform=transform_case_for_elasticsearch, **self.options)
def get_case_search_reindexer(domain=None): """Returns a reindexer that will return either all domains with case search enabled, or a single domain if passed in """ initialize_index_and_mapping(get_es_new(), CASE_SEARCH_INDEX_INFO) try: if domain is not None: if not case_search_enabled_for_domain(domain): raise CaseSearchNotEnabledException( "{} does not have case search enabled".format(domain)) domains = [domain] else: # return changes for all enabled domains domains = case_search_enabled_domains() change_provider = get_domain_case_change_provider(domains=domains) except ProgrammingError: # The db hasn't been intialized yet, so skip this reindex and complain. return _fail_gracefully_and_tell_admins() else: return PillowChangeProviderReindexer( get_case_search_to_elasticsearch_pillow(), change_provider=change_provider)