Skip to content

Instantly share code, notes, and snippets.

@alecklandgraf
Forked from anonymous/file1.py
Last active August 29, 2015 14:17
Show Gist options
  • Save alecklandgraf/a8a64b3a25fa1399eab5 to your computer and use it in GitHub Desktop.
Save alecklandgraf/a8a64b3a25fa1399eab5 to your computer and use it in GitHub Desktop.
def reindex_orgs(org_ids):
from seed.services import es_search_query
from elasticsearch import Elasticsearch
s = es_search_query()
s = s.filter('terms', building_snapshot__super_organization=org_ids)
from seed.services import elasticsearch_client
es = elasticsearch_client()
es.delete_by_query(index=settings.ES_INDEX, doc_type='canonical_building', body=s.to_dict())
from seed.utils.seed_elasticsearch import canon_serializer
import itertools
from seed.utils.generic import queryset_iterator_v2
from elasticsearch.helpers import bulk
es = Elasticsearch([{'host': settings.ES_HOST}], timeout=120, index='buildingenergy')
bulk(es, itertools.imap(canon_serializer,queryset_iterator_v2(CanonicalBuilding.objects.filter(canonical_snapshot__super_organization__in=org_ids))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment