Range aggregation query inside each range aggregation

Hi All,

I have a requirement like, I need to get the documents count for two fields based on the given ranges. Like, first field having ranges like 0-50,51-100 and second field having ranges like 0-500,501-1000. Now, as we get documents count for each range of first field along with that for each range of first field we need to get documents count for each range of second field.
Below is my sample query.

{
	"aggs": {
		"nested_aggr_noofemp": {
			"nested": {
				"path": "numberOfEmployees"
			},
			"aggs": {
				"noofemp_ranges": {
					"range": {
						"field": "numberOfEmployees.value",
						"ranges": [{
								"to": 100
							},
							{
								"from": 100,
								"to": 200
							},
							{
								"from": 200
							}
						]
					},
					"nested_aggr_solvencyRatio": {
						"nested": {
							"path": "standardisedViewReferenceCurrency"
						},
						"aggs": {
							"solvencyRatio_range": {
								"range": {
									"field": "standardisedViewReferenceCurrency.derivedFinancialItems.solvencyRatio",
									"ranges": [{
											"to": 50
										},
										{
											"from": 51,
											"to": 100
										},
										{
											"from": 101
										}
									]
								}
							}
						}
					}
				}
			}
		}
	}
}

But with the above query, I am getting below error msg:

{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "Found two aggregation type definitions in [noofemp_ranges]: [range] and [nested_aggr_solvencyRatio]",
"line": 23,
"col": 35
}
],
"type": "parsing_exception",
"reason": "Found two aggregation type definitions in [noofemp_ranges]: [range] and [nested_aggr_solvencyRatio]",
"line": 23,
"col": 35
},
"status": 400
}

Please let me know where I did mistake.

Thanks,
Ram Prasad G

A small update which fixed the above issue, below is the updated query,

{
	"aggs": {
		"nested_aggr_noofemp": {
			"nested": {
				"path": "standardisedFinancials.identification.numberOfEmployees"
			},
			"aggs": {
				"noofemp_ranges": {
					"range": {
						"field": "standardisedFinancials.identification.numberOfEmployees.value",
						"ranges": [{
								"to": 100
							},
							{
								"from": 100,
								"to": 200
							},
							{
								"from": 200
							}
						]
					},
					"aggs": {
						"nested_aggr_solvencyRatio": {
							"nested": {
								"path": "standardisedFinancials.financials.latestFinancials.standardisedViewReferenceCurrency"
							},
							"aggs": {
								"solvencyRatio_range": {
									"range": {
										"field": "standardisedFinancials.financials.latestFinancials.standardisedViewReferenceCurrency.derivedFinancialItems.solvencyRatio",
										"ranges": [{
												"to": 50
											},
											{
												"from": 51,
												"to": 100
											},
											{
												"from": 101
											}
										]
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

But the above query giving wrong results, like count 0 for sub-bucket ranges.
Kindly help me with my query please.

Thanks,
Ram Prasad G

Any suggestions please.

Hello does anyone got chance to look into this issue. I need this, as I got stuck with my implementation. Please please help me.

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