Skip to content

Commit c90699e

Browse files
authored
Make each analysis report desired field mappings to be copied (#50219)
1 parent 6c02f3d commit c90699e

File tree

18 files changed

+444
-245
lines changed

18 files changed

+444
-245
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ public Map<String, Long> getFieldCardinalityLimits() {
246246
return Collections.singletonMap(dependentVariable, 2L);
247247
}
248248

249+
@Override
250+
public Map<String, String> getExplicitlyMappedFields(String resultsFieldName) {
251+
return new HashMap<>() {{
252+
put(resultsFieldName + "." + predictionFieldName, dependentVariable);
253+
put(resultsFieldName + ".top_classes.class_name", dependentVariable);
254+
}};
255+
}
256+
249257
@Override
250258
public boolean supportsMissingValues() {
251259
return true;

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

+11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ public interface DataFrameAnalysis extends ToXContentObject, NamedWriteable {
4141
*/
4242
Map<String, Long> getFieldCardinalityLimits();
4343

44+
/**
45+
* Returns fields for which the mappings should be copied from source index to destination index.
46+
* Each entry of the returned {@link Map} is of the form:
47+
* key - field path in the destination index
48+
* value - field path in the source index from which the mapping should be taken
49+
*
50+
* @param resultsFieldName name of the results field under which all the results are stored
51+
* @return {@link Map} containing fields for which the mappings should be copied from source index to destination index
52+
*/
53+
Map<String, String> getExplicitlyMappedFields(String resultsFieldName);
54+
4455
/**
4556
* @return {@code true} if this analysis supports data frame rows with missing values
4657
*/

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

+5
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ public Map<String, Long> getFieldCardinalityLimits() {
229229
return Collections.emptyMap();
230230
}
231231

232+
@Override
233+
public Map<String, String> getExplicitlyMappedFields(String resultsFieldName) {
234+
return Collections.emptyMap();
235+
}
236+
232237
@Override
233238
public boolean supportsMissingValues() {
234239
return false;

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

+5
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ public Map<String, Long> getFieldCardinalityLimits() {
186186
return Collections.emptyMap();
187187
}
188188

189+
@Override
190+
public Map<String, String> getExplicitlyMappedFields(String resultsFieldName) {
191+
return Collections.singletonMap(resultsFieldName + "." + predictionFieldName, dependentVariable);
192+
}
193+
189194
@Override
190195
public boolean supportsMissingValues() {
191196
return true;

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/dataframe/analyses/ClassificationTests.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import java.util.Map;
2424
import java.util.Set;
2525

26+
import static org.hamcrest.Matchers.anEmptyMap;
2627
import static org.hamcrest.Matchers.containsString;
28+
import static org.hamcrest.Matchers.empty;
2729
import static org.hamcrest.Matchers.equalTo;
2830
import static org.hamcrest.Matchers.is;
2931
import static org.hamcrest.Matchers.not;
@@ -162,8 +164,16 @@ public void testGetParams() {
162164
"prediction_field_type", "string")));
163165
}
164166

165-
public void testFieldCardinalityLimitsIsNonNull() {
166-
assertThat(createTestInstance().getFieldCardinalityLimits(), is(not(nullValue())));
167+
public void testRequiredFieldsIsNonEmpty() {
168+
assertThat(createTestInstance().getRequiredFields(), is(not(empty())));
169+
}
170+
171+
public void testFieldCardinalityLimitsIsNonEmpty() {
172+
assertThat(createTestInstance().getFieldCardinalityLimits(), is(not(anEmptyMap())));
173+
}
174+
175+
public void testFieldMappingsToCopyIsNonEmpty() {
176+
assertThat(createTestInstance().getExplicitlyMappedFields(""), is(not(anEmptyMap())));
167177
}
168178

169179
public void testToXContent_GivenVersionBeforeRandomizeSeedWasIntroduced() throws IOException {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/dataframe/analyses/OutlierDetectionTests.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import java.io.IOException;
1313
import java.util.Map;
1414

15+
import static org.hamcrest.Matchers.anEmptyMap;
1516
import static org.hamcrest.Matchers.closeTo;
17+
import static org.hamcrest.Matchers.empty;
1618
import static org.hamcrest.Matchers.equalTo;
1719
import static org.hamcrest.Matchers.is;
18-
import static org.hamcrest.Matchers.not;
19-
import static org.hamcrest.Matchers.nullValue;
2020

2121
public class OutlierDetectionTests extends AbstractSerializingTestCase<OutlierDetection> {
2222

@@ -84,8 +84,16 @@ public void testGetParams_GivenExplicitValues() {
8484
assertThat(params.get(OutlierDetection.STANDARDIZATION_ENABLED.getPreferredName()), is(false));
8585
}
8686

87-
public void testFieldCardinalityLimitsIsNonNull() {
88-
assertThat(createTestInstance().getFieldCardinalityLimits(), is(not(nullValue())));
87+
public void testRequiredFieldsIsEmpty() {
88+
assertThat(createTestInstance().getRequiredFields(), is(empty()));
89+
}
90+
91+
public void testFieldCardinalityLimitsIsEmpty() {
92+
assertThat(createTestInstance().getFieldCardinalityLimits(), is(anEmptyMap()));
93+
}
94+
95+
public void testFieldMappingsToCopyIsEmpty() {
96+
assertThat(createTestInstance().getExplicitlyMappedFields(""), is(anEmptyMap()));
8997
}
9098

9199
public void testGetStateDocId() {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/dataframe/analyses/RegressionTests.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.util.Collections;
2020
import java.util.Map;
2121

22+
import static org.hamcrest.Matchers.anEmptyMap;
2223
import static org.hamcrest.Matchers.containsString;
24+
import static org.hamcrest.Matchers.empty;
2325
import static org.hamcrest.Matchers.equalTo;
2426
import static org.hamcrest.Matchers.is;
2527
import static org.hamcrest.Matchers.not;
@@ -99,8 +101,16 @@ public void testGetParams() {
99101
equalTo(Map.of("dependent_variable", "foo", "prediction_field_name", "foo_prediction")));
100102
}
101103

102-
public void testFieldCardinalityLimitsIsNonNull() {
103-
assertThat(createTestInstance().getFieldCardinalityLimits(), is(not(nullValue())));
104+
public void testRequiredFieldsIsNonEmpty() {
105+
assertThat(createTestInstance().getRequiredFields(), is(not(empty())));
106+
}
107+
108+
public void testFieldCardinalityLimitsIsEmpty() {
109+
assertThat(createTestInstance().getFieldCardinalityLimits(), is(anEmptyMap()));
110+
}
111+
112+
public void testFieldMappingsToCopyIsNonEmpty() {
113+
assertThat(createTestInstance().getExplicitlyMappedFields(""), is(not(anEmptyMap())));
104114
}
105115

106116
public void testGetStateDocId() {

0 commit comments

Comments
 (0)