Skip to content

Commit 174cc0c

Browse files
committed
[DOCS] Clarify interval, frequency, and bucket span in ML APIs and example (#51280)
1 parent 8ddf918 commit 174cc0c

File tree

4 files changed

+54
-63
lines changed

4 files changed

+54
-63
lines changed

docs/reference/ml/anomaly-detection/aggregations.asciidoc

+37-28
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,28 @@ distributes these calculations across your cluster. You can then feed this
1111
aggregated data into the {ml-features} instead of raw results, which
1212
reduces the volume of data that must be considered while detecting anomalies.
1313

14-
There are some limitations to using aggregations in {dfeeds}, however.
15-
Your aggregation must include a `date_histogram` aggregation, which in turn must
16-
contain a `max` aggregation on the time field. This requirement ensures that the
17-
aggregated data is a time series and the timestamp of each bucket is the time
18-
of the last record in the bucket. If you use a terms aggregation and the
19-
cardinality of a term is high, then the aggregation might not be effective and
20-
you might want to just use the default search and scroll behavior.
14+
TIP: If you use a terms aggregation and the cardinality of a term is high, the
15+
aggregation might not be effective and you might want to just use the default
16+
search and scroll behavior.
17+
18+
There are some limitations to using aggregations in {dfeeds}. Your aggregation
19+
must include a `date_histogram` aggregation, which in turn must contain a `max`
20+
aggregation on the time field. This requirement ensures that the aggregated data
21+
is a time series and the timestamp of each bucket is the time of the last record
22+
in the bucket.
23+
24+
You must also consider the interval of the date histogram aggregation carefully.
25+
The bucket span of your {anomaly-job} must be divisible by the value of the
26+
`calendar_interval` or `fixed_interval` in your aggregation (with no remainder).
27+
If you specify a `frequency` for your {dfeed}, it must also be divisible by this
28+
interval.
29+
30+
TIP: As a rule of thumb, if your detectors use <<ml-metric-functions,metric>> or
31+
<<ml-sum-functions,sum>> analytical functions, set the date histogram
32+
aggregation interval to a tenth of the bucket span. This suggestion creates
33+
finer, more granular time buckets, which are ideal for this type of analysis. If
34+
your detectors use <<ml-count-functions,count>> or <<ml-rare-functions,rare>>
35+
functions, set the interval to the same value as the bucket span.
2136

2237
When you create or update an {anomaly-job}, you can include the names of
2338
aggregations, for example:
@@ -143,9 +158,9 @@ pipeline aggregation to find the first order derivative of the counter
143158
----------------------------------
144159
// NOTCONSOLE
145160

146-
{dfeeds-cap} not only supports multi-bucket aggregations, but also single bucket aggregations.
147-
The following shows two `filter` aggregations, each gathering the number of unique entries for
148-
the `error` field.
161+
{dfeeds-cap} not only supports multi-bucket aggregations, but also single bucket
162+
aggregations. The following shows two `filter` aggregations, each gathering the
163+
number of unique entries for the `error` field.
149164

150165
[source,js]
151166
----------------------------------
@@ -225,14 +240,15 @@ When you define an aggregation in a {dfeed}, it must have the following form:
225240
----------------------------------
226241
// NOTCONSOLE
227242

228-
The top level aggregation must be either a {ref}/search-aggregations-bucket.html[Bucket Aggregation]
229-
containing as single sub-aggregation that is a `date_histogram` or the top level aggregation
230-
is the required `date_histogram`. There must be exactly 1 `date_histogram` aggregation.
243+
The top level aggregation must be either a
244+
{ref}/search-aggregations-bucket.html[bucket aggregation] containing as single
245+
sub-aggregation that is a `date_histogram` or the top level aggregation is the
246+
required `date_histogram`. There must be exactly 1 `date_histogram` aggregation.
231247
For more information, see
232-
{ref}/search-aggregations-bucket-datehistogram-aggregation.html[Date Histogram Aggregation].
248+
{ref}/search-aggregations-bucket-datehistogram-aggregation.html[Date histogram aggregation].
233249

234-
NOTE: The `time_zone` parameter in the date histogram aggregation must be set to `UTC`,
235-
which is the default value.
250+
NOTE: The `time_zone` parameter in the date histogram aggregation must be set to
251+
`UTC`, which is the default value.
236252

237253
Each histogram bucket has a key, which is the bucket start time. This key cannot
238254
be used for aggregations in {dfeeds}, however, because they need to know the
@@ -269,16 +285,9 @@ By default, {es} limits the maximum number of terms returned to 10000. For high
269285
cardinality fields, the query might not run. It might return errors related to
270286
circuit breaking exceptions that indicate that the data is too large. In such
271287
cases, do not use aggregations in your {dfeed}. For more
272-
information, see {ref}/search-aggregations-bucket-terms-aggregation.html[Terms Aggregation].
273-
274-
You can also optionally specify multiple sub-aggregations.
275-
The sub-aggregations are aggregated for the buckets that were created by their
276-
parent aggregation. For more information, see
277-
{ref}/search-aggregations.html[Aggregations].
288+
information, see
289+
{ref}/search-aggregations-bucket-terms-aggregation.html[Terms aggregation].
278290

279-
TIP: If your detectors use metric or sum analytical functions, set the
280-
`interval` of the date histogram aggregation to a tenth of the `bucket_span`
281-
that was defined in the job. This suggestion creates finer, more granular time
282-
buckets, which are ideal for this type of analysis. If your detectors use count
283-
or rare functions, set `interval` to the same value as `bucket_span`. For more
284-
information about analytical functions, see <<ml-functions>>.
291+
You can also optionally specify multiple sub-aggregations. The sub-aggregations
292+
are aggregated for the buckets that were created by their parent aggregation.
293+
For more information, see {ref}/search-aggregations.html[Aggregations].

docs/reference/ml/anomaly-detection/apis/put-datafeed.asciidoc

+6-25
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ cluster privileges to use this API. See
2626
[[ml-put-datafeed-desc]]
2727
==== {api-description-title}
2828

29-
You can associate only one {dfeed} to each {anomaly-job}.
29+
{ml-docs}/ml-dfeeds.html[{dfeeds-cap}] retrieve data from {es} for analysis by
30+
an {anomaly-job}. You can associate only one {dfeed} to each {anomaly-job}.
31+
32+
The {dfeed} contains a query that runs at a defined interval (`frequency`). If
33+
you are concerned about delayed data, you can add a delay (`query_delay`) at
34+
each interval. See {ml-docs}/ml-delayed-data-detection.html[Handling delayed data].
3035

3136
[IMPORTANT]
3237
====
@@ -64,11 +69,6 @@ include::{docdir}/ml/ml-shared.asciidoc[tag=delayed-data-check-config]
6469
`frequency`::
6570
(Optional, <<time-units, time units>>)
6671
include::{docdir}/ml/ml-shared.asciidoc[tag=frequency]
67-
+
68-
--
69-
To learn more about the relationship between time related settings, see
70-
<<ml-put-datafeed-time-related-settings>>.
71-
--
7272

7373
`indices`::
7474
(Required, array)
@@ -89,11 +89,6 @@ include::{docdir}/ml/ml-shared.asciidoc[tag=query]
8989
`query_delay`::
9090
(Optional, <<time-units, time units>>)
9191
include::{docdir}/ml/ml-shared.asciidoc[tag=query-delay]
92-
+
93-
--
94-
To learn more about the relationship between time related settings, see
95-
<<ml-put-datafeed-time-related-settings>>.
96-
--
9792

9893
`script_fields`::
9994
(Optional, object)
@@ -103,20 +98,6 @@ include::{docdir}/ml/ml-shared.asciidoc[tag=script-fields]
10398
(Optional, unsigned integer)
10499
include::{docdir}/ml/ml-shared.asciidoc[tag=scroll-size]
105100

106-
107-
[[ml-put-datafeed-time-related-settings]]
108-
===== Interaction between time-related settings
109-
110-
Time-related settings have the following relationships:
111-
112-
* Queries run at `query_delay` after the end of
113-
each `frequency`.
114-
115-
* When `frequency` is shorter than `bucket_span` of the associated job, interim
116-
results for the last (partial) bucket are written, and then overwritten by the
117-
full bucket results eventually.
118-
119-
120101
[[ml-put-datafeed-example]]
121102
==== {api-examples-title}
122103

docs/reference/ml/anomaly-detection/apis/put-job.asciidoc

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ include::{docdir}/ml/ml-shared.asciidoc[tag=analysis-config]
4949
`analysis_config`.`bucket_span`:::
5050
(<<time-units,time units>>)
5151
include::{docdir}/ml/ml-shared.asciidoc[tag=bucket-span]
52-
+
53-
--
54-
To learn more about the relationship between time related settings, see
55-
<<ml-put-datafeed-time-related-settings>>.
56-
--
5752

5853
`analysis_config`.`categorization_field_name`:::
5954
(string)

docs/reference/ml/ml-shared.asciidoc

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tag::aggregations[]
22
If set, the {dfeed} performs aggregation searches. Support for aggregations is
3-
limited and should only be used with low cardinality data. For more information,
3+
limited and should be used only with low cardinality data. For more information,
44
see
55
{ml-docs}/ml-configuring-aggregation.html[Aggregating data for faster performance].
66
end::aggregations[]
@@ -148,8 +148,10 @@ end::background-persist-interval[]
148148

149149
tag::bucket-span[]
150150
The size of the interval that the analysis is aggregated into, typically between
151-
`5m` and `1h`. The default value is `5m`. For more information about time units,
152-
see <<time-units>>.
151+
`5m` and `1h`. The default value is `5m`. If the {anomaly-job} uses a {dfeed}
152+
with {ml-docs}/ml-configuring-aggregation.html[aggregations], this value must be
153+
divisible by the interval of the date histogram aggregation. For more
154+
information, see {ml-docs}/ml-buckets.html[Buckets].
153155
end::bucket-span[]
154156

155157
tag::bucket-span-results[]
@@ -603,7 +605,10 @@ tag::frequency[]
603605
The interval at which scheduled queries are made while the {dfeed} runs in real
604606
time. The default value is either the bucket span for short bucket spans, or,
605607
for longer bucket spans, a sensible fraction of the bucket span. For example:
606-
`150s`.
608+
`150s`. When `frequency` is shorter than the bucket span, interim results for
609+
the last (partial) bucket are written then eventually overwritten by the full
610+
bucket results. If the {dfeed} uses aggregations, this value must be divisible
611+
by the interval of the date histogram aggregation.
607612
end::frequency[]
608613

609614
tag::from[]
@@ -938,7 +943,8 @@ The number of seconds behind real time that data is queried. For example, if
938943
data from 10:04 a.m. might not be searchable in {es} until 10:06 a.m., set this
939944
property to 120 seconds. The default value is randomly selected between `60s`
940945
and `120s`. This randomness improves the query performance when there are
941-
multiple jobs running on the same node.
946+
multiple jobs running on the same node. For more information, see
947+
{ml-docs}/ml-delayed-data-detection.html[Handling delayed data].
942948
end::query-delay[]
943949

944950
tag::randomize-seed[]

0 commit comments

Comments
 (0)