How to access nested docs in scripted_metric after nested aggregation

How can i access nested docs in scripted_metric after nested aggregation?

I make request

{
  "query": {
	"match_all": {}
  },
  "aggs": {
	"q1": {
		"nested": {
			"path": "pp"
		},
		"aggs": {
			"q2": {
				"scripted_metric": {
					"init_script": "state.transactions = []", 
					"map_script": "state.transactions.add(doc['pp.id'])",
					"combine_script": "return state.transactions",
					"reduce_script": "return states"
				}
			}
		}
	}
  }
}

This is just example, in more complex query i will add filter aggs to filter nested docs. And then i will process only matched nested docs.

I would like to process in map_script all nested docs that current level of aggs use. But doc['pp.id'] returns only value of one nested doc from row. And any other i try returns error - doc['pp[0].id'] or for (item in doc['pp'])

I don't know why, but doc['pp.id'] returns some thing unpredictable (seems to be any value across all nested docs in matched outer doc).
But doc['pp.id'].get(0) return exacly i expected - value of pp.id of each matched nested doc.

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