def expand_action(data):
 if isinstance(data, string_types):
  return (u'{"index":{}}', data)
 data = data.copy()
 op_type = data.pop(u'_op_type', u'index')
 action = {op_type: {}}
 for key in (u'_index', u'_parent', u'_percolate', u'_routing', u'_timestamp', u'_ttl', u'_type', u'_version', u'_version_type', u'_id', u'_retry_on_conflict'):
  if (key in data):
   action[op_type][key] = data.pop(key)
 if (op_type == u'delete'):
  return (action, None)
 return (action, data.get(u'_source', data))

def expand_action ( data ) : if isinstance ( data , string_types ) : return ( u'{"index":{}}' , data ) data = data . copy ( ) op_type = data . pop ( u'_op_type' , u'index' ) action = { op_type : { } } for key in ( u'_index' , u'_parent' , u'_percolate' , u'_routing' , u'_timestamp' , u'_ttl' , u'_type' , u'_version' , u'_version_type' , u'_id' , u'_retry_on_conflict' ) : if ( key in data ) : action [ op_type ] [ key ] = data . pop ( key ) if ( op_type == u'delete' ) : return ( action , None ) return ( action , data . get ( u'_source' , data ) )
from one document or action definition passed in by the user extract the action/data lines needed for elasticsearchs :meth:~elasticsearch .