def migrate(self, mapping, index, doc_type):
old_mapping = self.get_doctype(index, doc_type)<EOL>if not old_mapping:<EOL><INDENT>self.connection.indices.put_mapping(doc_type=doc_type, mapping=mapping, indices=index)<EOL>return mapping<EOL><DEDENT>mapping_diff = old_mapping.get_diff(mapping)<EOL>if not mapping_diff:<EOL><INDENT>return None<EOL><DEDENT>from pprint import pprint<EOL>pprint(mapping_diff.as_dict())<EOL>mapping_diff.connection = old_mapping.connection<EOL>mapping_diff.save()<EOL>
Migrate a ES mapping


:param mapping: new mapping
:param index: index of old mapping
:param doc_type: type of old mapping
:return: The diff mapping