Skip to content

Commit 9234619

Browse files
committed
Make each analysis report desired field mappings to be copied
1 parent 05996bf commit 9234619

File tree

18 files changed

+447
-246
lines changed

18 files changed

+447
-246
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ public Map<String, Long> getFieldCardinalityLimits() {
246246
return Collections.singletonMap(dependentVariable, 2L);
247247
}
248248

249+
@Override
250+
public Map<String, String> getFieldMappingsToCopy(String resultsFieldName) {
251+
return Map.of(
252+
resultsFieldName + "." + predictionFieldName, dependentVariable,
253+
resultsFieldName + ".top_classes.class_name", dependentVariable);
254+
}
255+
249256
@Override
250257
public boolean supportsMissingValues() {
251258
return true;

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

Lines changed: 11 additions & 0 deletions
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 field mappings to 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 field mappings to be copied from source index to destination index
52+
*/
53+
Map<String, String> getFieldMappingsToCopy(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

Lines changed: 5 additions & 0 deletions
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> getFieldMappingsToCopy(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

Lines changed: 5 additions & 0 deletions
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> getFieldMappingsToCopy(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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
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;
3032
import static org.hamcrest.Matchers.notNullValue;
31-
import static org.hamcrest.Matchers.nullValue;
3233

3334
public class ClassificationTests extends AbstractSerializingTestCase<Classification> {
3435

@@ -162,8 +163,16 @@ public void testGetParams() {
162163
"prediction_field_type", "string")));
163164
}
164165

165-
public void testFieldCardinalityLimitsIsNonNull() {
166-
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().getFieldMappingsToCopy(""), is(not(anEmptyMap())));
167176
}
168177

169178
public void testToXContent_GivenVersionBeforeRandomizeSeedWasIntroduced() throws IOException {

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

Lines changed: 12 additions & 4 deletions
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().getFieldMappingsToCopy(""), is(anEmptyMap()));
8997
}
9098

9199
public void testGetStateDocId() {

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
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;
2628
import static org.hamcrest.Matchers.notNullValue;
27-
import static org.hamcrest.Matchers.nullValue;
2829

2930
public class RegressionTests extends AbstractSerializingTestCase<Regression> {
3031

@@ -99,8 +100,16 @@ public void testGetParams() {
99100
equalTo(Map.of("dependent_variable", "foo", "prediction_field_name", "foo_prediction")));
100101
}
101102

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

106115
public void testGetStateDocId() {

0 commit comments

Comments
 (0)