#NEWLINE# def get_report_script_field( field_path , is_known = False ) : #NEWLINE# #INDENT# "\n    Generate a script field string for easier querying.\n    field_path: is the path.to.property.name in the _source\n    is_known: if true, then query as is, if false, then it's a dynamically mapped item,\n    so put on the #value property at the end.\n    " #NEWLINE# property_split = field_path . split ( '.' ) #NEWLINE# property_path = ( '_source%s' % '' . join ( ( ( "['%s']" % x ) for x in property_split ) ) ) #NEWLINE# if is_known : #NEWLINE# #INDENT# script_string = property_path #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# full_script_path = ( "%s['#value']" % property_path ) #NEWLINE# script_string = ( 'if (%(prop_path)s != null) { %(value_path)s; }\n        else { null; }' % { #NEWLINE# #INDENT# 'prop_path' : property_path , #NEWLINE# 'value_path' : full_script_path , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# ret = { #NEWLINE# #INDENT# 'script' : script_string , #NEWLINE# #UNINDENT# } #NEWLINE# return ret