Skip to content

Commit 67b710d

Browse files
authored
[DOCS] Updates datafeed related runtime field examples (#73725) (#73887)
1 parent 7ad3cdd commit 67b710d

File tree

1 file changed

+38
-94
lines changed

1 file changed

+38
-94
lines changed

docs/reference/ml/anomaly-detection/ml-configuring-transform.asciidoc

Lines changed: 38 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ If your {dfeed} defines runtime fields, you can use those fields in your
1212
functions in one or more detectors. Runtime fields can impact search performance
1313
based on the computation defined in the runtime script.
1414

15+
[NOTE]
16+
===============================
17+
Some of these examples use regular expressions. By default, regular
18+
expressions are disabled because they circumvent the protection that Painless
19+
provides against long running and memory hungry scripts. For more information,
20+
see {ref}/modules-scripting-painless.html[Painless scripting language].
21+
22+
{ml-cap} analysis is case sensitive. For example, "John" is considered to be
23+
different than "john". This is one reason you might consider using scripts that
24+
convert your strings to upper or lowercase letters.
25+
===============================
26+
1527
* <<ml-configuring-transform1>>
1628
* <<ml-configuring-transform2>>
1729
* <<ml-configuring-transform3>>
@@ -31,46 +43,22 @@ PUT /my-index-000001
3143
{
3244
"mappings":{
3345
"properties": {
34-
"@timestamp": {
35-
"type": "date"
36-
},
37-
"aborted_count": {
38-
"type": "long"
39-
},
40-
"another_field": {
41-
"type": "keyword" <1>
42-
},
43-
"clientip": {
44-
"type": "keyword"
45-
},
46+
"@timestamp": { "type": "date" },
47+
"aborted_count": { "type": "long" },
48+
"another_field": { "type": "keyword" }, <1>
49+
"clientip": { "type": "keyword" },
4650
"coords": {
4751
"properties": {
48-
"lat": {
49-
"type": "keyword"
50-
},
51-
"lon": {
52-
"type": "keyword"
53-
}
52+
"lat": { "type": "keyword" },
53+
"lon": { "type": "keyword" }
5454
}
5555
},
56-
"error_count": {
57-
"type": "long"
58-
},
59-
"query": {
60-
"type": "keyword"
61-
},
62-
"some_field": {
63-
"type": "keyword"
64-
},
65-
"tokenstring1":{
66-
"type":"keyword"
67-
},
68-
"tokenstring2":{
69-
"type":"keyword"
70-
},
71-
"tokenstring3":{
72-
"type":"keyword"
73-
}
56+
"error_count": { "type": "long" },
57+
"query": { "type": "keyword" },
58+
"some_field": { "type": "keyword" },
59+
"tokenstring1":{ "type":"keyword" },
60+
"tokenstring2":{ "type":"keyword" },
61+
"tokenstring3":{ "type":"keyword" }
7462
}
7563
}
7664
}
@@ -113,14 +101,12 @@ PUT _ml/anomaly_detectors/test1
113101
"detectors":[
114102
{
115103
"function":"mean",
116-
"field_name": "total_error_count", <1>
117-
"detector_description": "Custom script field transformation"
104+
"field_name": "total_error_count" <1>
118105
}
119106
]
120107
},
121108
"data_description": {
122-
"time_field":"@timestamp",
123-
"time_format":"epoch_ms"
109+
"time_field":"@timestamp"
124110
}
125111
}
126112
@@ -130,11 +116,6 @@ PUT _ml/datafeeds/datafeed-test1
130116
"indices": [
131117
"my-index-000001"
132118
],
133-
"query": {
134-
"match_all": {
135-
"boost": 1
136-
}
137-
},
138119
"runtime_mappings": {
139120
"total_error_count": { <2>
140121
"type": "long",
@@ -194,24 +175,6 @@ use the **Edit JSON** tab. For example:
194175
image::images/ml-runtimefields.jpg[Using runtime_mappings in {dfeed} config via {kib}]
195176

196177

197-
[[ml-configuring-transform-examples]]
198-
== Common runtime field examples
199-
200-
While the possibilities are limitless, there are a number of common scenarios
201-
where you might use runtime fields in your {dfeeds}.
202-
203-
[NOTE]
204-
===============================
205-
Some of these examples use regular expressions. By default, regular
206-
expressions are disabled because they circumvent the protection that Painless
207-
provides against long running and memory hungry scripts. For more information,
208-
see {ref}/modules-scripting-painless.html[Painless scripting language].
209-
210-
{ml-cap} analysis is case sensitive. For example, "John" is considered to be
211-
different than "john". This is one reason you might consider using scripts that
212-
convert your strings to upper or lowercase letters.
213-
===============================
214-
215178
[[ml-configuring-transform2]]
216179
.Example 2: Concatenating strings
217180

@@ -224,26 +187,19 @@ PUT _ml/anomaly_detectors/test2
224187
"detectors":[
225188
{
226189
"function":"low_info_content",
227-
"field_name":"my_runtime_field", <1>
228-
"detector_description": "Custom script field transformation"
190+
"field_name":"my_runtime_field" <1>
229191
}
230192
]
231193
},
232194
"data_description": {
233-
"time_field":"@timestamp",
234-
"time_format":"epoch_ms"
195+
"time_field":"@timestamp"
235196
}
236197
}
237198
238199
PUT _ml/datafeeds/datafeed-test2
239200
{
240201
"job_id": "test2",
241202
"indices": ["my-index-000001"],
242-
"query": {
243-
"match_all": {
244-
"boost": 1
245-
}
246-
},
247203
"runtime_mappings": {
248204
"my_runtime_field": {
249205
"type": "keyword",
@@ -469,7 +425,7 @@ The preview {dfeed} API returns the following results, which show that
469425

470426
[source,console]
471427
--------------------------------------------------
472-
PUT _ml/anomaly_detectors/test4
428+
PUT _ml/anomaly_detectors/test3
473429
{
474430
"analysis_config":{
475431
"bucket_span": "10m",
@@ -481,20 +437,14 @@ PUT _ml/anomaly_detectors/test4
481437
]
482438
},
483439
"data_description": {
484-
"time_field":"@timestamp",
485-
"time_format":"epoch_ms"
440+
"time_field":"@timestamp"
486441
}
487442
}
488443
489-
PUT _ml/datafeeds/datafeed-test4
444+
PUT _ml/datafeeds/datafeed-test3
490445
{
491-
"job_id": "test4",
446+
"job_id": "test3",
492447
"indices": ["my-index-000001"],
493-
"query": {
494-
"match_all": {
495-
"boost": 1
496-
}
497-
},
498448
"runtime_mappings": {
499449
"my_coordinates": {
500450
"type": "keyword",
@@ -505,7 +455,7 @@ PUT _ml/datafeeds/datafeed-test4
505455
}
506456
}
507457
508-
GET _ml/datafeeds/datafeed-test4/_preview
458+
GET _ml/datafeeds/datafeed-test3/_preview
509459
--------------------------------------------------
510460
// TEST[skip:needs-licence]
511461

@@ -534,7 +484,7 @@ The preview {dfeed} API returns the following results, which show that
534484
535485
[source,console]
536486
--------------------------------------------------
537-
PUT _ml/anomaly_detectors/test3
487+
PUT _ml/anomaly_detectors/test4
538488
{
539489
"description":"DNS tunneling",
540490
"analysis_config":{
@@ -550,20 +500,14 @@ PUT _ml/anomaly_detectors/test3
550500
]
551501
},
552502
"data_description": {
553-
"time_field":"@timestamp",
554-
"time_format":"epoch_ms"
503+
"time_field":"@timestamp"
555504
}
556505
}
557506
558-
PUT _ml/datafeeds/datafeed-test3
507+
PUT _ml/datafeeds/datafeed-test4
559508
{
560-
"job_id": "test3",
509+
"job_id": "test4",
561510
"indices": ["my-index-000001"],
562-
"query": {
563-
"match_all": {
564-
"boost": 1
565-
}
566-
},
567511
"script_fields":{
568512
"sub":{
569513
"script":"return domainSplit(doc['query'].value).get(0);"
@@ -574,7 +518,7 @@ PUT _ml/datafeeds/datafeed-test3
574518
}
575519
}
576520
577-
GET _ml/datafeeds/datafeed-test3/_preview
521+
GET _ml/datafeeds/datafeed-test4/_preview
578522
--------------------------------------------------
579523
// TEST[skip:needs-licence]
580524

0 commit comments

Comments
 (0)