{
  "script": {
    "lang": "mustache",
    "source": """
		{
			"_source": {
				"includes": [
					"{{aggComponentName}}",
					"usage"
				]
			},
			"query": {
				"bool": {
					"must": [
						{
							"match_phrase": {
								"network_id.keyword": {
									"query": "{{networkId}}"
								}
							}
						},
						{
							"match_phrase": {
								"network_group_id.keyword": {
									"query": "{{networkGroupId}}"
								}
							}
						},
						{
							"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": "{{gte}}",
									"lte": "{{lte}}",
									"format": "epoch_millis"
								}
							}
						}
						
						{{#componentName}},
						 
						  {
							"match_phrase": {
								"{{componentName}}": {
									"query": "{{componentValue}}"
								}
							}
					  	
						}
						{{/componentName}}
						
					],
					"filter": {
						"bool": {
							"must": [
								{
									"match_all": {}
								}
								
								{{#attributes}},
								{
									"terms": {
									"attributes.keyword": {{#toJson}}attributes{{/toJson}}
										
									}
								}
							 {{/attributes}}
								
								
							]
						}
					}
				}
			},
			"size": "{{size}}",
			"aggs": {
				"items": {
					"terms": {
						"field": "{{aggComponentName}}",
						"size": "{{aggTermSize}}",
						"order": {
							"item_sum": "desc"
						}
					},
					"aggs": {
						"item_sum": {
							"sum": {
								"field": "usage"
							}
						}
					}
				}
			}
		}
		"""
  }
}