Elasticsearch query to calculate yearly percentage growth

Hi All,

I would like to calculate yearly percentage growth of a particular field.
Below is my sample doc for your reference.

{
	"stdFin": {
		"fin": {
			"numberOfStatements": 5,
			"statements": [{
					"stdViewRef": [{
						"bal": {
							"sales": 38600
						}
					}],
					"statementToDate": "2016-12-31",
					"isLatest": true
				},
				{
					"stdViewRef": [{
						"bal": {
							"sales": 3800
						}
					}],
					"statementToDate": "2015-11-11"
				},
				{
					"stdViewRef": [{
						"bal": {
							"sales": 3600
						}
					}],
					"statementToDate": "2014-01-10"
				},
			    {
					"stdViewRef": [{
						"bal": {
							"sales": 8600
						}
					}],
					"statementToDate": "2013-02-13"
				}
			]
		}
	}
}

In the above sample elasticsearch doc, "statementToDate" which is date field belongs to "statements" nested object, and "sales" field belongs to "stdViewRef" nested object.
I have to calculate yearly growth of sales like, (sales_2016 - sales_2015)/sales_2015 * 100.

Could someone please help me on writing elasticsearch query.

Thanks,
Ram

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.