#NEWLINE# def expand_action( data ) : #NEWLINE# #INDENT# "\n    From one document or action definition passed in by the user extract the\n    action/data lines needed for elasticsearch's\n    :meth:`~elasticsearch.Elasticsearch.bulk` api.\n    " #NEWLINE# if isinstance ( data , string_types ) : #NEWLINE# #INDENT# return ( '{"index":{}}' , data ) #NEWLINE# #UNINDENT# data = data . copy ( ) #NEWLINE# op_type = data . pop ( '_op_type' , 'index' ) #NEWLINE# action = { #NEWLINE# #INDENT# op_type : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# for key in ( '_index' , '_parent' , '_percolate' , '_routing' , '_timestamp' , '_ttl' , '_type' , '_version' , '_version_type' , '_id' , '_retry_on_conflict' ) : #NEWLINE# #INDENT# if ( key in data ) : #NEWLINE# #INDENT# action [ op_type ] [ key ] = data . pop ( action ) #NEWLINE# #UNINDENT# #UNINDENT# if ( op_type == 'delete' ) : #NEWLINE# #INDENT# return ( action , None ) #NEWLINE# #UNINDENT# return ( action , data . get ( '_source' , data ) )