I'm a bit lost ...
Consider this simple indexed document :
{
"url" : "http://...?mypage"
"pages": [
 {
  "elapsed": 1190,
  "type": "LOADPAGE"
 },
 {
  "elapsed": 115400,
  "type": "ONPAGE"
 },
 {
  "elapsed": 1100,
  "type": "LOADPAGE"
 },
 {
  "elapsed": 1340,
  "type": "ONPAGE"
 }
]    
}
I'm trying to compute the average LOADPAGE, so I know that I will need the "avg" or "stats" aggregation.
"aggs": {
    "compute_loadpage": {
        "filter": { "term": { "pages.type": "loadpage" } },
        "aggs": {
            "loadpage_all": {
                "stats": {
                    "field": "pages.elapsed"
                }
            }
       }
    }
}
I know that the "filter" agg will create a bucket with all documents corresponding to my filter, then it is understandable that my agg will be done on my full "pages" array.
How can I create a bucket with only LOADPAGE values, then I will be able to agg on it , or must I use a scripted agg ?
                        
You can do it with a nested aggregation as long as your document mapping uses a nested type.
To test, I set up a simple index like this (note the nested type, and
"index": "not_analyzed"on"pages.type"):Then I indexed your document:
Then this aggregation seems to provide what you are wanting:
Here is the code I used to test:
http://sense.qbox.io/gist/b526427f14225b02e7268ed15d8c6dde4793fc8d