def test_insert_tree_without_mapping(self): # with explicit nested initial_agg_1 = Aggs( { "week": { "date_histogram": { "field": "date", "format": "yyyy-MM-dd", "interval": "1w", } } }, ) self.assertEqual({n.identifier for n in initial_agg_1.list()}, {"week"}) pasted_agg_1 = Aggs( { "nested_below_week": { "nested": {"path": "local_metrics"}, "aggs": { "local_metrics.field_class.name": { "terms": { "field": "local_metrics.field_class.name", "size": 10, } } }, } } ) self.assertEqual( to_id_set(pasted_agg_1.list()), {"nested_below_week", "local_metrics.field_class.name"}, ) initial_agg_1.insert_tree(pasted_agg_1, "week") self.assertEqual( to_id_set(initial_agg_1.list()), {"week", "nested_below_week", "local_metrics.field_class.name"}, ) self.assertEqual( initial_agg_1.to_dict(), { "week": { "date_histogram": { "field": "date", "format": "yyyy-MM-dd", "interval": "1w", }, "aggs": { "nested_below_week": { "nested": {"path": "local_metrics"}, "aggs": { "local_metrics.field_class.name": { "terms": { "field": "local_metrics.field_class.name", "size": 10, } } }, } }, } }, )
def test_paste_tree_with_mapping(self): # with explicit nested initial_agg_1 = Aggs( { "week": { "date_histogram": { "field": "date", "format": "yyyy-MM-dd", "interval": "1w", } } }, mapping=MAPPING, ) self.assertEqual(to_id_set(initial_agg_1.list()), {"week"}) pasted_agg_1 = Aggs( { "nested_below_week": { "nested": {"path": "local_metrics"}, "aggs": { "local_metrics.field_class.name": { "terms": { "field": "local_metrics.field_class.name", "size": 10, } } }, } } ) self.assertEqual( to_id_set(pasted_agg_1.list()), {"nested_below_week", "local_metrics.field_class.name"}, ) initial_agg_1.insert_tree(pasted_agg_1, "week") self.assertEqual( to_id_set(initial_agg_1.list()), {"week", "nested_below_week", "local_metrics.field_class.name"}, ) self.assertEqual( initial_agg_1.to_dict(), { "week": { "date_histogram": { "field": "date", "format": "yyyy-MM-dd", "interval": "1w", }, "aggs": { "nested_below_week": { "nested": {"path": "local_metrics"}, "aggs": { "local_metrics.field_class.name": { "terms": { "field": "local_metrics.field_class.name", "size": 10, } } }, } }, } }, ) # without explicit nested initial_agg_2 = Aggs( { "week": { "date_histogram": { "field": "date", "format": "yyyy-MM-dd", "interval": "1w", } } }, mapping=MAPPING, nested_autocorrect=True, ) self.assertEqual(to_id_set(initial_agg_2.list()), {"week"}) pasted_agg_2 = Aggs( { "local_metrics.field_class.name": { "terms": {"field": "local_metrics.field_class.name", "size": 10} } } ) self.assertEqual( to_id_set(pasted_agg_2.list()), {"local_metrics.field_class.name"} ) initial_agg_2.insert_tree(pasted_agg_2, "week") self.assertEqual( to_id_set(initial_agg_2.list()), {"week", "nested_below_week", "local_metrics.field_class.name"}, ) self.assertEqual( initial_agg_2.to_dict(), { "week": { "date_histogram": { "field": "date", "format": "yyyy-MM-dd", "interval": "1w", }, "aggs": { "nested_below_week": { "nested": {"path": "local_metrics"}, "aggs": { "local_metrics.field_class.name": { "terms": { "field": "local_metrics.field_class.name", "size": 10, } } }, } }, } }, )