def list(self, request, *args, **kwargs): ec = ElasticCore() response = super(IndexViewSet, self).list(request, *args, **kwargs) data = response.data # Get the paginated and sorted queryset results. open_indices = [index for index in data if index["is_open"]] mappings = ec.es.indices.get_mapping() # Doing a stats request with no indices causes trouble. if open_indices: stats = ec.get_index_stats() # Update the paginated and sorted queryset results. for index in response.data: name = index["name"] is_open = index["is_open"] if is_open: has_texta_facts_mapping = self._check_for_facts( index_mappings=mappings, index_name=name) if name in stats: index.update( **stats[name], has_validated_facts=has_texta_facts_mapping) else: index.update(has_validated_facts=False) else: # For the sake of courtesy on the front-end, make closed indices values zero. index.update(size=0, doc_count=0, has_validated_facts=False) return response
def retrieve(self, request, *args, **kwargs): ec = ElasticCore() response = super(IndexViewSet, self).retrieve(*args, *kwargs) if response.data["is_open"]: index_name = response.data["name"] mapping = ec.es.indices.get_mapping(index_name) has_validated_facts = self._check_for_facts(mapping, index_name) stats = ec.get_index_stats() response.data.update(**stats[index_name], has_validated_facts=has_validated_facts) else: response.data.update(size=0, doc_count=0, has_validated_facts=False) return response