struggling with this, so any help would be much appreciated!
I have an aggregation that provides counts of documents grouped by role, gender and age within date histogram buckets:
"aggs": {
"period": {
"date_histogram": {
"field": "timestamp",
"fixed_interval": "15m",
"time_zone": "America/Los_Angeles",
"order": {
"_key": "desc"
}
},
"aggs": {
"role": {
"terms": {
"field": "role",
"size": 3
},
"aggs": {
"gender": {
"terms": {
"field": "gender",
"size": 3
},
"aggs": {
"age": {
"terms": {
"field": "age",
"size": 10
}
}
}
}
}
}
}
}
}
Each document has a visitorId, there may be many documents within the same date histogram bucket with the same visitorId.
I would like only unique visitorId's to be included in each date histogram bucket. Effectively I want to avoid double / triple etc counting where it's the same visitor. Is that possible?
If only for each visitor role, gender & age are same then below query (adding a cardinality sub-aggregation on visitorId) should work: