Skip to content

Instantly share code, notes, and snippets.

@markjhoy
Created January 26, 2021 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markjhoy/a338439af2bc84330aeff63ca4e93f3c to your computer and use it in GitHub Desktop.
Save markjhoy/a338439af2bc84330aeff63ca4e93f3c to your computer and use it in GitHub Desktop.
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