Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Workplace Search Analytics - Weekly User Retention
{
"size": 0,
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{ "match": { "event.action": "SearchMetrics.query" } }
]
}
},
"aggs": {
"date_ranges": {
"date_histogram": {
"field": "@timestamp",
"interval": "week"
},
"aggs": {
"unique_users": {
"cardinality": {
"field": "source.user.id"
}
},
"weekly_user_retention": {
"moving_fn": {
"buckets_path": "unique_users",
"window": 2,
"script": "return values.length > 1 ? values[1]/values[0] : Double.NaN"
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment