Trying to get stats on object stored inside an array

Hi,

I've walk through a lot of thread to resolve my issue but I think that it's
not possible. Perhaps someone will have an idea :
I got a mapping including an array of objects (perhaps it's my mistake ?):

{
name: Header
detail: [
{
count: 621,
key: key1
}
{
count: 138,
key: key2
}
]
}

With this mapping :

"detail":
{
"dynamic": "true",
"properties":
{
"count":
{
"type": "long"
},
"key":
{
"type": "string",
"index": "not_analyzed"
}
}
},

I try to get for each key the sum of the of the count field. So
I've tried a terms_stats :

  "terms_stats": {
    "key_field": "detail.key",
    "value_field": "detail.count",
    "order": "total",
    "size": 0
  }

But the result is not what I'm expected. The count, min, max, total is not
grouped by the key field but is the count of every objects in the array

{
term: key1
count: 2
total_count: 2
min: 138
max: 621
total: 759
mean: 379.5
}
{
term: key2
count: 2
total_count: 2
min: 138
max: 621
total: 759
mean: 379.5
}

I've also tried the value_script :

"terms_stats": {
"key_field": "detail.key",
"value_script": "doc['detail.count'].value",
"order": "total",
"size": 0
}

But again it's not what I'm trying to get. Here the result :

{
term: key1
count: 1
total_count: 1
min: 1
max: 1
total: 1
mean:1
}
{
term: key2
count: 1
total_count: 1
min: 1
max: 1
total: 1
mean:1
}

Someone could tell me if I'm completly getting wrong using these mapping or
if there is an other solution ?
Thanks

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.