{
	"script": {
		"lang": "mustache",
		"source":
		"""
		 {
			"_source": {
				"includes": [
					"{{agg_field_query_param}}",
					"usage"
				]
			},
			"query": {
				"bool": {
					"must": [
						{
							"range": {
								"timestamp": {
									"gte": "{{timestamp_greater_than_equal_query_param}}",
									"lte": "{{timestamp_lesser_than_equal_query_param}}",
									"format": "epoch_millis"
								}
							}
						},
						{
							"match_phrase": {
								"network_id.keyword": {
									"query": "{{network_id_query_param}}"
								}
							}
						},
						{
							"match_phrase": {
								"network_group_id.keyword": {
									"query": "{{network_group_id_query_param}}"
								}
							}
						}
						
						{{#match_phrase_condition_query_param}},
						 
						  {
							"match_phrase": {
								"{{phrase_name_query_param}}": {
									"query": "{{phrase_name_value_query_param}}"
								}
							}
					  	
						}
						{{/match_phrase_condition_query_param}}
						,
						{
							"bool": {
								"should": [
									{
										"match_phrase": {
											"usage_type.keyword": "usage.ingress.tx"
										}
									},
									{
										"match_phrase": {
											"usage_type.keyword": "usage.egress.tx"
										}
									}
								],
								"minimum_should_match": 1
							}
						}
					]
				}
			},
			"size": "{{size_query_param}}",
			"aggs": {
				"unique_items": {
					"terms": {
						"field": "{{agg_field_query_param}}",
						"size": "{{agg_term_size_query_param}}",
						"order": {
							"item_sum": "desc"
						}
					},
					"aggs": {
						"item_sum": {
							"sum": {
								"field": "usage"
							}
						}
					}
				}
			}
		}
		"""
	}
}