{
	"script": {
		"lang": "mustache",
		"source": {
			"_source": {
				"includes": [
					"usage_type.keyword",
					"usage"
				]
			},
			"query": {
				"bool": {
					"must": [
						{
							"match_phrase": {
								"network_id": {
									"query": "{{network_id_query_param}}"
								}
							}
						},
						{
							"match_phrase": {
								"organizationId": {
									"query": "{{organizationId_query_param}}"
								}
							}
						},
						{
							"bool": {
								"should": [
									{
										"match_phrase": {
											"usage_type.keyword": "usage.ingress.tx"
										}
									},
									{
										"match_phrase": {
											"usage_type.keyword": "usage.egress.tx"
										}
									}
								],
								"minimum_should_match": 1
							}
						},
						{
							"range": {
								"@timestamp": {
									"gte": "{{timestamp_greater_than_equal_query_param}}",
									"lte": "{{timestamp_lesser_than_equal_query_param}}",
									"format": "epoch_millis"
								}
							}
						}
					],
					"filter": {
						"bool": {
							"must": [
								{
									"match_all": {}
								}
							]
						}
					}
				}
			},
			"size": "{{size_query_param}}",
			"aggs": {
				"timebuckets": {
					"date_histogram": {
						"field": "timestamp",
						"interval": "{{timestamp_interval_query_param}}",
						"time_zone": "{{timezone_query_param}}",
						"min_doc_count": 1
					},
					"aggs": {
						"usage_sums": {
							"terms": {
								"field": "usage_type.keyword",
								"size": "{{agg_term_size_query_param}}",
								"order": {
									"usage_bytes": "desc"
								}
							},
							"aggs": {
								"usage_bytes": {
									"sum": {
										"field": "usage"
									}
								}
							}
						}
					}
				}
			}
		}
	}
}