I already spent way too much time on this. I have this aggregation that I can't get to work like it should.
I have a ton of documents with a structure like this (I've ommited some of the parts that aren't relevant for this agg):
{
"url": "THE_URL",
"url_params": {},
"title": "Het Nieuwsblad",
"referrer": null,
"time": "2015-08-25T08:35:15.729Z",
"referrerHost": null,
"timeOnSite": 16,
"blocks": [{
"viewTime": 11,
"click": 0,
"view": 1,
"block": "gentenaar__gentenaar-header"
}, {
"viewTime": 11,
"click": 0,
"view": 1,
"block": "gentenaar__gentenaar-headline"
}, ..., {
"viewTime": 11,
"click": 0,
"view": 1,
"block": "news__fast-news-sidebar-4-left"
}, {
"viewTime": 11,
"click": 0,
"view": 1,
"block": "news__fast-news-sidebar-4-right"
}, {
"viewTime": 1,
"click": 0,
"view": 1,
"block": "news__fast-news-sidebar-5"
}, {
"viewTime": 0,
"click": 0,
"view": 0,
"block": "news__fast-news-sidebar-6-left"
}, ...],
"activeAds": [{
"viewed": 1,
"clicked": 0,
"type": "button",
"width": 317,
"height": 75,
"timeViewed": 10
}, {
"viewed": 1,
"clicked": 0,
"type": "xlleaderboard",
"width": 990,
"height": 122,
"timeViewed": 10
}, ...]...
}
It's the blocks array that I'm having problems with. I want to know per block the sum of clicks, views and viewTime.
I'm trying to use this query:
{
"size": 0,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"range": {
"dt": {
"from": "2015-08-25T00:00:00+00:00",
"to": "2015-08-26T23:59:59+00:00"
}
}
},
{
"term": {
"url": "http://www.nieuwsblad.be/"
}
}
]
}
}
}
},
"aggs": {
"per_block": {
"terms": {
"field": "blocks.block"
},
"aggs": {
"clicks": {
"sum": {
"field": "blocks.click"
}
}
}
}
}
}
For the activeAds, I'm using nearly identical code but there it's working perfectly:
{
"size": 0,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"range": {
"dt": {
"from": "2015-08-25T00:00:00+00:00",
"to": "2015-08-26T23:59:59+00:00"
}
}
},
{
"terms": {
"page.page_type": [
"home"
]
}
}
],
"must_not": {
"term": {
"activeAds.timeViewed": 0
}
}
}
}
}
},
"aggs": {
"per_ad": {
"terms": {
"field": "activeAds.type"
},
"aggs": {
"clicks": {
"sum": {
"field": "activeAds.clicked"
}
},
"views": {
"sum": {
"field": "activeAds.viewed"
}
},
"total_time_viewed": {
"sum": {
"field": "activeAds.timeViewed"
}
}
}
}
}
}
Anyone have any idea on what I'm doing wrong?