code: def dict_to_op(d, index_name, doc_type, op_type='index'):
      
      if d is None:
          return d
  
      op_types = ('create', 'delete', 'index', 'update')
      if op_type not in op_types:
          msg = 'Unknown operation type "{}", must be one of: {}'
          raise Exception(msg.format(op_type, ', '.join(op_types)))
  
      if 'id' not in d:
          raise Exception('"id" key not found')
  
      operation = {
          '_op_type': op_type,
          '_index': index_name,
          '_type': doc_type,
          '_id': d.pop('id'),
      }
      operation.update(d)
  
      return operation
docs: Create a bulk-indexing operation from the given dictionary.