def test_bucket_sort_agg_only_trnunc(): bucket_sort_agg = aggs.BucketSort(**{"from": 1, "size": 1}) assert bucket_sort_agg.to_dict() == {"bucket_sort": {"from": 1, "size": 1}} a = aggs.DateHistogram(field="date", interval="month") a.bucket("bucket_truncate", "bucket_sort", **{"from": 1, "size": 1}) assert { "date_histogram": {"field": "date", "interval": "month"}, "aggs": {"bucket_truncate": {"bucket_sort": {"from": 1, "size": 1}}}, } == a.to_dict()
def test_bucket_sort_agg(): bucket_sort_agg = aggs.BucketSort(sort=[{ "total_sales": { "order": "desc" } }], size=3) assert bucket_sort_agg.to_dict() == { "bucket_sort": { "sort": [{ "total_sales": { "order": "desc" } }], "size": 3 } } a = aggs.DateHistogram(field="date", interval="month") a.bucket("total_sales", "sum", field="price") a.bucket( "sales_bucket_sort", "bucket_sort", sort=[{ "total_sales": { "order": "desc" } }], size=3, ) assert { "date_histogram": { "field": "date", "interval": "month" }, "aggs": { "total_sales": { "sum": { "field": "price" } }, "sales_bucket_sort": { "bucket_sort": { "sort": [{ "total_sales": { "order": "desc" } }], "size": 3 } }, }, } == a.to_dict()
def test_bucket_sort_agg(): bucket_sort_agg = aggs.BucketSort(sort=[{ "total_sales": { "order": "desc" } }], size=3) assert bucket_sort_agg.to_dict() == { "bucket_sort": { "sort": [{ "total_sales": { "order": "desc" } }], "size": 3 } } a = aggs.DateHistogram(field='date', interval='month') a.bucket('total_sales', 'sum', field='price') a.bucket('sales_bucket_sort', 'bucket_sort', sort=[{ "total_sales": { "order": "desc" } }], size=3) assert { "date_histogram": { "field": "date", "interval": "month" }, "aggs": { "total_sales": { "sum": { "field": "price" } }, "sales_bucket_sort": { "bucket_sort": { "sort": [{ "total_sales": { "order": "desc" } }], "size": 3 } } } } == a.to_dict()
def test_bucket_sort_agg_only_trnunc(): bucket_sort_agg = aggs.BucketSort(**{'from': 1, 'size': 1}) assert bucket_sort_agg.to_dict() == {"bucket_sort": {"from": 1, "size": 1}} a = aggs.DateHistogram(field='date', interval='month') a.bucket('bucket_truncate', 'bucket_sort', **{'from': 1, 'size': 1}) assert { "date_histogram": { "field": "date", "interval": "month" }, "aggs": { "bucket_truncate": { "bucket_sort": { "from": 1, "size": 1 } } } } == a.to_dict()