Skip to content

Commit 14d95aa

Browse files
authored
[7.x] Make each analysis report desired field mappings to be copied (#50219) (#50428)
1 parent af8bed1 commit 14d95aa

File tree

18 files changed

+456
-246
lines changed

18 files changed

+456
-246
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
@@ -248,6 +248,14 @@ public Map<String, Long> getFieldCardinalityLimits() {
248248
return Collections.singletonMap(dependentVariable, 2L);
249249
}
250250

251+
@Override
252+
public Map<String, String> getExplicitlyMappedFields(String resultsFieldName) {
253+
return new HashMap<String, String>() {{
254+
put(resultsFieldName + "." + predictionFieldName, dependentVariable);
255+
put(resultsFieldName + ".top_classes.class_name", dependentVariable);
256+
}};
257+
}
258+
251259
@Override
252260
public boolean supportsMissingValues() {
253261
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
@@ -25,7 +25,9 @@
2525
import java.util.Map;
2626
import java.util.Set;
2727

28+
import static org.hamcrest.Matchers.anEmptyMap;
2829
import static org.hamcrest.Matchers.containsString;
30+
import static org.hamcrest.Matchers.empty;
2931
import static org.hamcrest.Matchers.equalTo;
3032
import static org.hamcrest.Matchers.hasEntry;
3133
import static org.hamcrest.Matchers.is;
@@ -161,8 +163,16 @@ public void testGetParams() {
161163
hasEntry("prediction_field_type", "string")));
162164
}
163165

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

168178
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

2121
import static org.hamcrest.Matchers.allOf;
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.hasEntry;
2527
import static org.hamcrest.Matchers.is;
@@ -100,8 +102,16 @@ public void testGetParams() {
100102
allOf(hasEntry("dependent_variable", "foo"), hasEntry("prediction_field_name", "foo_prediction")));
101103
}
102104

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

107117
public void testGetStateDocId() {

0 commit comments

Comments
 (0)