1+ [role="xpack"]
12[[ml-count-functions]]
2- === Count Functions
3+ === Count functions
34
45Count functions detect anomalies when the number of events in a bucket is
56anomalous.
@@ -21,7 +22,7 @@ The {xpackml} features include the following count functions:
2122
2223[float]
2324[[ml-count]]
24- ===== Count, High_count, Low_count
25+ ===== Count, high_count, low_count
2526
2627The `count` function detects anomalies when the number of events in a bucket is
2728anomalous.
@@ -44,8 +45,20 @@ see {ref}/ml-job-resource.html#ml-detectorconfig[Detector Configuration Objects]
4445.Example 1: Analyzing events with the count function
4546[source,js]
4647--------------------------------------------------
47- { "function" : "count" }
48+ PUT _xpack/ml/anomaly_detectors/example1
49+ {
50+ "analysis_config": {
51+ "detectors": [{
52+ "function" : "count"
53+ }]
54+ },
55+ "data_description": {
56+ "time_field":"timestamp",
57+ "time_format": "epoch_ms"
58+ }
59+ }
4860--------------------------------------------------
61+ // CONSOLE
4962
5063This example is probably the simplest possible analysis. It identifies
5164time buckets during which the overall count of events is higher or lower than
@@ -57,12 +70,22 @@ and detects when the event rate is unusual compared to its past behavior.
5770.Example 2: Analyzing errors with the high_count function
5871[source,js]
5972--------------------------------------------------
73+ PUT _xpack/ml/anomaly_detectors/example2
6074{
61- "function" : "high_count",
62- "by_field_name" : "error_code",
63- "over_field_name": "user"
75+ "analysis_config": {
76+ "detectors": [{
77+ "function" : "high_count",
78+ "by_field_name" : "error_code",
79+ "over_field_name": "user"
80+ }]
81+ },
82+ "data_description": {
83+ "time_field":"timestamp",
84+ "time_format": "epoch_ms"
85+ }
6486}
6587--------------------------------------------------
88+ // CONSOLE
6689
6790If you use this `high_count` function in a detector in your job, it
6891models the event rate for each error code. It detects users that generate an
@@ -72,11 +95,21 @@ unusually high count of error codes compared to other users.
7295.Example 3: Analyzing status codes with the low_count function
7396[source,js]
7497--------------------------------------------------
98+ PUT _xpack/ml/anomaly_detectors/example3
7599{
76- "function" : "low_count",
77- "by_field_name" : "status_code"
100+ "analysis_config": {
101+ "detectors": [{
102+ "function" : "low_count",
103+ "by_field_name" : "status_code"
104+ }]
105+ },
106+ "data_description": {
107+ "time_field":"timestamp",
108+ "time_format": "epoch_ms"
109+ }
78110}
79111--------------------------------------------------
112+ // CONSOLE
80113
81114In this example, the function detects when the count of events for a
82115status code is lower than usual.
@@ -88,22 +121,30 @@ compared to its past behavior.
88121.Example 4: Analyzing aggregated data with the count function
89122[source,js]
90123--------------------------------------------------
124+ PUT _xpack/ml/anomaly_detectors/example4
91125{
92- "summary_count_field_name" : "events_per_min",
93- "detectors" [
94- { "function" : "count" }
95- ]
96- }
126+ "analysis_config": {
127+ "summary_count_field_name" : "events_per_min",
128+ "detectors": [{
129+ "function" : "count"
130+ }]
131+ },
132+ "data_description": {
133+ "time_field":"timestamp",
134+ "time_format": "epoch_ms"
135+ }
136+ }
97137--------------------------------------------------
138+ // CONSOLE
98139
99140If you are analyzing an aggregated `events_per_min` field, do not use a sum
100141function (for example, `sum(events_per_min)`). Instead, use the count function
101- and the `summary_count_field_name` property.
102- //TO-DO: For more information, see <<aggreggations.asciidoc >>.
142+ and the `summary_count_field_name` property. For more information, see
143+ <<ml-configuring-aggregation >>.
103144
104145[float]
105146[[ml-nonzero-count]]
106- ===== Non_zero_count, High_non_zero_count, Low_non_zero_count
147+ ===== Non_zero_count, high_non_zero_count, low_non_zero_count
107148
108149The `non_zero_count` function detects anomalies when the number of events in a
109150bucket is anomalous, but it ignores cases where the bucket count is zero. Use
@@ -144,11 +185,21 @@ The `non_zero_count` function models only the following data:
144185.Example 5: Analyzing signatures with the high_non_zero_count function
145186[source,js]
146187--------------------------------------------------
188+ PUT _xpack/ml/anomaly_detectors/example5
147189{
148- "function" : "high_non_zero_count",
149- "by_field_name" : "signaturename"
190+ "analysis_config": {
191+ "detectors": [{
192+ "function" : "high_non_zero_count",
193+ "by_field_name" : "signaturename"
194+ }]
195+ },
196+ "data_description": {
197+ "time_field":"timestamp",
198+ "time_format": "epoch_ms"
199+ }
150200}
151201--------------------------------------------------
202+ // CONSOLE
152203
153204If you use this `high_non_zero_count` function in a detector in your job, it
154205models the count of events for the `signaturename` field. It ignores any buckets
@@ -163,7 +214,7 @@ data is sparse, use the `count` functions, which are optimized for that scenario
163214
164215[float]
165216[[ml-distinct-count]]
166- ===== Distinct_count, High_distinct_count, Low_distinct_count
217+ ===== Distinct_count, high_distinct_count, low_distinct_count
167218
168219The `distinct_count` function detects anomalies where the number of distinct
169220values in one field is unusual.
@@ -187,11 +238,21 @@ see {ref}/ml-job-resource.html#ml-detectorconfig[Detector Configuration Objects]
187238.Example 6: Analyzing users with the distinct_count function
188239[source,js]
189240--------------------------------------------------
241+ PUT _xpack/ml/anomaly_detectors/example6
190242{
191- "function" : "distinct_count",
192- "field_name" : "user"
243+ "analysis_config": {
244+ "detectors": [{
245+ "function" : "distinct_count",
246+ "field_name" : "user"
247+ }]
248+ },
249+ "data_description": {
250+ "time_field":"timestamp",
251+ "time_format": "epoch_ms"
252+ }
193253}
194254--------------------------------------------------
255+ // CONSOLE
195256
196257This `distinct_count` function detects when a system has an unusual number
197258of logged in users. When you use this function in a detector in your job, it
@@ -201,12 +262,22 @@ users is unusual compared to the past.
201262.Example 7: Analyzing ports with the high_distinct_count function
202263[source,js]
203264--------------------------------------------------
265+ PUT _xpack/ml/anomaly_detectors/example7
204266{
205- "function" : "high_distinct_count",
206- "field_name" : "dst_port",
207- "over_field_name": "src_ip"
267+ "analysis_config": {
268+ "detectors": [{
269+ "function" : "high_distinct_count",
270+ "field_name" : "dst_port",
271+ "over_field_name": "src_ip"
272+ }]
273+ },
274+ "data_description": {
275+ "time_field":"timestamp",
276+ "time_format": "epoch_ms"
277+ }
208278}
209279--------------------------------------------------
280+ // CONSOLE
210281
211282This example detects instances of port scanning. When you use this function in a
212283detector in your job, it models the distinct count of ports. It also detects the
0 commit comments