Skip to content

Commit 0866358

Browse files
Address review comments
1 parent bc438eb commit 0866358

File tree

3 files changed

+61
-68
lines changed

3 files changed

+61
-68
lines changed

docs/reference/ml/df-analytics/apis/dfanalyticsresources.asciidoc

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
which fields will be included in the analysis. If `analyzed_fields` is not set,
2121
only the relevant fields will be included. For example, all the numeric fields
2222
for {oldetection}. For the supported field types, see <<ml-put-dfanalytics-supported-fields>>.
23-
Also see {ref}/explain-dfanalytics.html[_explain API] which helps understand
24-
field selection.
23+
Also see the <<explain-dfanalytics>> which helps understand field selection.
2524

2625
`includes`:::
2726
(Optional, array) An array of strings that defines the fields that will be included in

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/dataframe/DataFrameAnalyticsSource.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public boolean isFieldExcluded(String path) {
190190

191191
// First we check in the excludes as they are applied last
192192
for (String exclude : sourceFiltering.excludes()) {
193-
if (patternMatchesFieldPath(exclude, path)) {
193+
if (pathMatchesSourcePattern(path, exclude)) {
194194
return true;
195195
}
196196
}
@@ -203,25 +203,26 @@ public boolean isFieldExcluded(String path) {
203203
}
204204

205205
for (String include : sourceFiltering.includes()) {
206-
if (patternMatchesFieldPath(include, path)) {
206+
if (pathMatchesSourcePattern(path, include)) {
207207
return false;
208208
}
209209
}
210210
return true;
211211
}
212212

213-
private static boolean patternMatchesFieldPath(String pattern, String path) {
214-
if (Regex.isSimpleMatchPattern(pattern)) {
215-
return Regex.simpleMatch(pattern, path);
216-
} else {
217-
if (pattern.equals(path)) {
218-
return true;
219-
} else {
220-
// include as a concrete field name.
221-
// Let us take "foo" as an example.
222-
// Fields that are "foo.*" will also be included.
223-
return Regex.simpleMatch(pattern + ".*", path);
224-
}
213+
private static boolean pathMatchesSourcePattern(String path, String sourcePattern) {
214+
if (sourcePattern.equals(path)) {
215+
return true;
225216
}
217+
218+
if (Regex.isSimpleMatchPattern(sourcePattern)) {
219+
return Regex.simpleMatch(sourcePattern, path);
220+
}
221+
222+
// At this stage sourcePattern is a concrete field name and path is not equal to it.
223+
// We should check if path is a nested field of pattern.
224+
// Let us take "foo" as an example.
225+
// Fields that are "foo.*" should also be matched.
226+
return Regex.simpleMatch(sourcePattern + ".*", path);
226227
}
227228
}

0 commit comments

Comments
 (0)