Inlude ID when bulk indexing documents through bulk_index helper
This commit is contained in:
@@ -41,7 +41,7 @@ def bulk_index(client, docs, chunk_size=500, stats_only=False, **kwargs):
|
|||||||
for d in chunk:
|
for d in chunk:
|
||||||
action = {'index': {}}
|
action = {'index': {}}
|
||||||
for key in ('_index', '_parent', '_percolate', '_routing',
|
for key in ('_index', '_parent', '_percolate', '_routing',
|
||||||
'_timestamp', '_ttl', '_type', '_version',):
|
'_timestamp', '_ttl', '_type', '_version', '_id'):
|
||||||
if key in d:
|
if key in d:
|
||||||
action['index'][key] = d.pop(key)
|
action['index'][key] = d.pop(key)
|
||||||
|
|
||||||
@@ -53,14 +53,16 @@ def bulk_index(client, docs, chunk_size=500, stats_only=False, **kwargs):
|
|||||||
|
|
||||||
resp = client.bulk(bulk_actions, **kwargs)
|
resp = client.bulk(bulk_actions, **kwargs)
|
||||||
|
|
||||||
for item in resp['items']:
|
for req, item in zip(bulk_actions[::2], resp['items']):
|
||||||
|
# TODO: better reporting
|
||||||
|
act = 'index' if '_id' in req['index'] else 'create'
|
||||||
if stats_only:
|
if stats_only:
|
||||||
if item['create']['ok']:
|
if item[act]['ok']:
|
||||||
success += 1
|
success += 1
|
||||||
else:
|
else:
|
||||||
failed += 1
|
failed += 1
|
||||||
else:
|
else:
|
||||||
if item['create']['ok']:
|
if item[act]['ok']:
|
||||||
success.append(item)
|
success.append(item)
|
||||||
else:
|
else:
|
||||||
failed.append(item)
|
failed.append(item)
|
||||||
|
|||||||
Reference in New Issue
Block a user