Skip to content

Instantly share code, notes, and snippets.

@benwtrent
Last active October 15, 2020 12:53
Show Gist options
  • Save benwtrent/d1585589c225cc2e3e325cab8c196fe5 to your computer and use it in GitHub Desktop.
Save benwtrent/d1585589c225cc2e3e325cab8c196fe5 to your computer and use it in GitHub Desktop.
Calculating the percent true and using it in a job
{
"indices" : [
"kibana_sample_data_flights"
],
"query" : {
"bool" : {
"must" : [
{
"match_all" : { }
}
]
}
},
"aggregations" : {
"buckets" : {
"date_histogram" : {
"field" : "timestamp",
"fixed_interval" : "15m"
},
"aggs" : {
"timestamp" : {
"max" : {
"field" : "timestamp"
}
},
"num_true" : {
"sum" : {
"field" : "Cancelled"
}
},
"total" : {
"value_count" : {
"field" : "timestamp"
}
},
"percent_true" : {
"bucket_script" : {
"buckets_path" : {
"num_true" : "num_true",
"total" : "total"
},
"script" : {
"source" : "params.num_true/params.total"
}
}
}
}
}
}
}
{
"description" : "",
"analysis_config" : {
"bucket_span" : "15m",
"summary_count_field_name" : "doc_count",
"detectors" : [
{
"detector_description" : "mean(percent_true)",
"function" : "mean",
"field_name" : "percent_true",
"detector_index" : 0
}
],
"influencers" : [ ]
},
"analysis_limits" : {
"model_memory_limit" : "11mb",
"categorization_examples_limit" : 4
},
"data_description" : {
"time_field" : "timestamp",
"time_format" : "epoch_ms"
},
"model_plot_config" : {
"enabled" : true,
"annotations_enabled" : false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment