#NEWLINE# def flatten_aggregation_hierarchy( self , root , hierarchy_tuple = ( ) ) : #NEWLINE# #INDENT# ' For nested aggregations, the results come back in the following format:\n            {\n            "aggregations" : {\n                "filtered" : {\n                  "doc_count" : 37,\n                  "values" : {\n                    "doc_count_error_upper_bound" : 0,\n                    "sum_other_doc_count" : 0,\n                    "buckets" : [ {\n                      "key" : "1.1.1.1", # IP address (root)\n                      "doc_count" : 13,\n                      "values" : {\n                        "doc_count_error_upper_bound" : 0,\n                        "sum_other_doc_count" : 0,\n                        "buckets" : [ {\n                          "key" : "80",    # Port (sub-aggregation)\n                          "doc_count" : 3,\n                          "values" : {\n                            "doc_count_error_upper_bound" : 0,\n                            "sum_other_doc_count" : 0,\n                            "buckets" : [ {\n                              "key" : "ack",  # Reason (sub-aggregation, leaf-node)\n                              "doc_count" : 3\n                            }, {\n                              "key" : "syn",  # Reason (sub-aggregation, leaf-node)\n                              "doc_count" : 1\n                            } ]\n                          }\n                        }, {\n                          "key" : "82",    # Port (sub-aggregation)\n                          "doc_count" : 3,\n                          "values" : {\n                            "doc_count_error_upper_bound" : 0,\n                            "sum_other_doc_count" : 0,\n                            "buckets" : [ {\n                              "key" : "ack",  # Reason (sub-aggregation, leaf-node)\n                              "doc_count" : 3\n                            }, {\n                              "key" : "syn",  # Reason (sub-aggregation, leaf-node)\n                              "doc_count" : 3\n                            } ]\n                          }\n                        } ]\n                      }\n                    }, {\n                      "key" : "2.2.2.2", # IP address (root)\n                      "doc_count" : 4,\n                      "values" : {\n                        "doc_count_error_upper_bound" : 0,\n                        "sum_other_doc_count" : 0,\n                        "buckets" : [ {\n                          "key" : "443",    # Port (sub-aggregation)\n                          "doc_count" : 3,\n                          "values" : {\n                            "doc_count_error_upper_bound" : 0,\n                            "sum_other_doc_count" : 0,\n                            "buckets" : [ {\n                              "key" : "ack",  # Reason (sub-aggregation, leaf-node)\n                              "doc_count" : 3\n                            }, {\n                              "key" : "syn",  # Reason (sub-aggregation, leaf-node)\n                              "doc_count" : 3\n                            } ]\n                          }\n                        } ]\n                      }\n                    } ]\n                  }\n                }\n              }\n            }\n\n            Each level will either have more values and buckets, or it will be a leaf node\n            We\'ll ultimately return a flattened list with the hierarchies appended as strings,\n            e.g the above snippet would yield a list with:\n\n            [\n             (\'1.1.1.1\', \'80\', \'ack\'),\n             (\'1.1.1.1\', \'80\', \'syn\'),\n             (\'1.1.1.1\', \'82\', \'ack\'),\n             (\'1.1.1.1\', \'82\', \'syn\'),\n             (\'2.2.2.2\', \'443\', \'ack\'),\n             (\'2.2.2.2\', \'443\', \'syn\')\n            ]\n\n            A similar formatting will be performed in the add_data method and used as the basis for comparison\n\n        ' #NEWLINE# results = [ ] #NEWLINE# if ( 'values' in root ) : #NEWLINE# #INDENT# results += self . flatten_aggregation_hierarchy ( root [ 'values' ] [ 'buckets' ] , ( hierarchy_tuple + ( root [ 'key' ] , ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for node in root : #NEWLINE# #INDENT# if ( 'values' in node ) : #NEWLINE# #INDENT# results += self . flatten_aggregation_hierarchy ( node , hierarchy_tuple ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# results . append ( ( hierarchy_tuple + ( node [ 'key' ] , ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return results