Aggregating across multiple sub documents?

I have a following documents

Document 1:
    {
      "county" : "Santa Clara",
      "city": "San Jose",
      "date" : 123432342342,
      "user" : {
        "0" : {
          "name" : "abc",
          "metrics" : {
            "m1" : 100.0,
            "m2" : 200.0
          }
        },
        "1" : {
          "name" : "abc1",
          "metrics" : {
            "m1" : 100.0,
            "m2" : 200.0
          }
        }
      }
    }
    Document2:
       {
          "county" : "Santa Clara",
          "city": "Sunnyvale",
          "date" : 123432342342,
          "user" : {
            "0" : {
              "name" : "abc",
              "metrics" : {
                "m1" : 100.0,
                "m2" : 200.0
              }
            },
            "1" : {
              "name" : "abc1",
              "metrics" : {
                "m1" : 100.0,
                "m2" : 200.0
              }
            }
          }
        }

What I want is to aggregate m1 metric of user 0 and user 1 across various cities in a county and get an average/mean/percentile and so on of it.
so basically values of:

document1.user.0.metric.m1 + user.1.metric.m1 + document2.user.0.metric.m1 + document2.user.1.metric.m1 ...

How to achieve this in ES query ?

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