Scripted metric aggregation over nested docs

I'm trying to do scripted metric aggregation
using Groovy with Elasticsearch 1.4.4
I've a document model where each parent document can have 0-n nested
documents and I need to list distinct values and count their occurrences.

How can I access nested document field values in a script?
With this map_script fragment:
for (r in doc['_source.nested']) { _agg.agg.add('abc') }

I get an error saying:
"No field found for [_source.nested] in mapping with types [foo]"

I've also tried omitting "_source" from the field name and also doing a
doc.containsKey check for the field but neither seem to work.


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
To view this discussion on the web visit
For more options, visit