ElasticSearch - issue with sub term aggregation with array fields
Elasticsearch will flatten the nested objects, so internally you will get:
{ "title":"The Judge","year":2014,"casting.name": ["Robert Downey Jr.","Robert Duvall"],"casting.category": ["Producer", "Actor"]}
if you want to keep the relationship you'll need to use either nested objects or a parent child relationship
To do a nested mapping you'd need to do something like this:
"mappings": { "movies": { "properties": { "title" : { "type": "string" }, "year" : { "type": "integer" }, "casting": { "type": "nested", "properties": { "name": { "type": "string" }, "category": { "type": "string" } } } } } }