Skip to content

Instantly share code, notes, and snippets.

@bracki
Created January 30, 2012 21:34
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bracki/1706856 to your computer and use it in GitHub Desktop.
Save bracki/1706856 to your computer and use it in GitHub Desktop.
Simple reindex for elasticsearch using pyes
>>> import pyes
>>> conn = pyes.es.ES("localhost:9200")
>>> all = conn.scan(pyes.query.MatchAllQuery(), 'index', 'type')
>>> for a in all:
... hits = a['hits']['hits']
... for hit in hits:
... conn.index(hit['_source'], 'new_index', 'type', hit['_id'], bulk=True)
@guerrysemones
Copy link

Awesome, thanks, just what I was looking for.

@yinchunxiang
Copy link

Why I have this error:
AttributeError: 'ES' object has no attribute 'scan'

@liujoey
Copy link

liujoey commented Jul 7, 2015

new version:

import pyes
conn = pyes.es.ES("localhost:9200")
all = conn.search(pyes.query.MatchAllQuery(), 'index', 'type', scan=True)
for a in all:
    conn.index(a, 'new_index', 'type', a.get_id(), bulk=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment