def handle(self, *args, **kwargs): elastic = ES(settings.SEARCH_HOSTS) pp = pprint.PrettyPrinter(indent=4) pp.pprint(elastic.get_indices()) elastic.connection.close()
def handle(self, *args, **kwargs): delete_all = kwargs.get('all') elastic = ES(settings.SEARCH_HOSTS) indices = [] if delete_all: indices.extend(elastic.get_indices(True)) indices.extend(elastic.get_closed_indices()) for index in indices: elastic.delete_index_if_exists(index) else: for source_name in args: indices_aliased = [index for index in elastic.get_alias(source_name) if index == source_name] elastic.delete_index_if_exists(source_name) if indices_aliased: elastic.delete_alias(source_name, indices_aliased) for index in indices_aliased: elastic.delete_index_if_exists(index) if len(indices) and len(args): elastic.connection.close() self.stdout.write("Successfully deleted indicies & aliases.\n") elastic.connection.close()
def count_documents(): num_docs = cache.get('website.documents_count') if not num_docs: elastic = ES(settings.SEARCH_HOSTS) indices = elastic.get_indices() elastic.connection.close() indices = indices.values() num_docs = 0 for item in indices: num_docs += item['num_docs'] cache.set('website.documents_count', num_docs) return num_docs