{
  "script": {
    "lang": "mustache",
    "source": """
		 {
			"_source": {
				"includes": [
					"{{aggComponentName}}",
					"usage"
				]
			},
			"query": {
				"bool": {
					"must": [
						{
							"range": {
								"timestamp": {
									"gte": "{{gte}}",
									"lte": "{{lte}}",
									"format": "epoch_millis"
								}
							}
						},
						{
							"match_phrase": {
								"network_id.keyword": {
									"query": "{{networkId}}"
								}
							}
						},
						{
							"match_phrase": {
								"network_group_id.keyword": {
									"query": "{{networkGroupId}}"
								}
							}
						}
						{{#componentName}},
						 
						  {
							"match_phrase": {
								"{{componentName}}": {
									"query": "{{componentValue}}"
								}
							}
					  	
						}
						{{/componentName}}
						,
						{
							"bool": {
								"should": [
									{
										"match_phrase": {
											"usage_type.keyword": "usage.ingress.tx"
										}
									},
									{
										"match_phrase": {
											"usage_type.keyword": "usage.egress.tx"
										}
									}
								],
								"minimum_should_match": 1
							}
						}
					]
				}
			},
			"size": "{{size}}",
			"aggs": {
				"unique_items": {
					"terms": {
						"field": "{{aggComponentName}}",
						"size": "{{aggTermSize}}",
						"order": {
							"item_sum": "desc"
						}
					},
					"aggs": {
						"item_sum": {
							"sum": {
								"field": "usage"
							}
						}
					}
				}
			}
		}
		"""
  }
}