Nested aggregation query for max number of employees

Hi All,

I have a below scenario of requirement.
Need top 10 companies with maximum number of employees.
Below is my Elasticsearch query without nested fields.

{
    "size": 0,
    "_source": false,
    "stored_fields": "_none_",
    "aggregations": {
        "groupby": {
            "composite": {
                "size": 10,
                "sources": [
                    {
                        "269": {
                            "terms": {
                                "field": "typeCode",
                                "missing_bucket": false,
                                "order": "asc"
                            }
                        }
                    }
                ]
            }
        }
    }
}

Above query is working fine. But I need this to be working with nested field i.e.,

{
	"size": 0,
	"_source": false,
	"stored_fields": "_none_",
	"aggs": {
		"industryCodes_path": {
			"nested": {
				"path": "codeTypes"
			},
			"aggregations": {
				"groupby": {
					"composite": {
						"size": 10,
						"sources": [{
							"860": {
								"terms": {
									"field": "typeCode",
									"order": "asc"
								}
							}
						}]
					}
				}
			}
		}
	}
}

Above is with nested field, which is failing with below error message,

[composite] aggregation cannot be used with a parent aggregation

Could someone please help me on how to solve this issue.

Thanks,
Ram G

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