Created
May 23, 2016 23:54
-
-
Save bryder/9f186f69573044583947bd1055d86687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transform_some_stuff(data, idx_and_doc_type): | |
# This is mostly copied out of expand_action in the elasticserarch helpers thing - | |
# which is why there's a bunch of keys I don't use in there. | |
# But I'm just leaving them in anyways | |
data = data.copy() | |
op_type = data.pop('_op_type', 'index') | |
action = {op_type: {}} | |
for key in ('_index', '_parent', '_percolate', '_routing', '_timestamp', | |
'_ttl', '_type', '_version', '_version_type', '_id', '_retry_on_conflict'): | |
if key in data: | |
action[op_type][key] = data.pop(key) | |
action[op_type]['_type'] = idx_and_doc_type | |
source = data['_source'] | |
# do stuff to the source document here | |
return action, source | |
transform_some_stuff_with_version = partial(transform_some_stuff, idx_and_doc_type=index_config['idx_and_doc_type']) | |
res = elasticsearch.helpers.reindex(es, source_index_name, destination_index_name, chunk_size=500, | |
bulk_kwargs={'expand_action_callback': transform_some_stuff_with_version}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment