From a9be4181c61a4efc0569fa6d27700bef32d5b5fc Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Thu, 8 Oct 2020 08:53:26 -0400 Subject: [PATCH] [ML] fix grabbing the doc value limit setting in _explain (#63402) (#63471) Getting the doc value settings shouldn't use the API callers headers. We only use this value internally. --- .../integration/ExplainDataFrameAnalyticsRestIT.java | 6 ++---- .../dataframe/extractor/ExtractedFieldsDetector.java | 6 ++++-- .../extractor/ExtractedFieldsDetectorFactory.java | 10 +++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/ExplainDataFrameAnalyticsRestIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/ExplainDataFrameAnalyticsRestIT.java index d7a451cf96d..279efcb10da 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/ExplainDataFrameAnalyticsRestIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/ExplainDataFrameAnalyticsRestIT.java @@ -117,8 +117,7 @@ public class ExplainDataFrameAnalyticsRestIT extends ESRestTestCase { addSecondaryAuthHeader(options, ML_ADMIN); explain.setOptions(options); // Should throw - ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(explain)); - assertThat(ex.getResponse().getStatusLine().getStatusCode(), equalTo(403)); + expectThrows(ResponseException.class, () -> client().performRequest(explain)); } { // request with secondary headers with perms Request explain = explainRequestViaConfig(config); @@ -160,8 +159,7 @@ public class ExplainDataFrameAnalyticsRestIT extends ESRestTestCase { addSecondaryAuthHeader(options, ML_ADMIN); explain.setOptions(options); // Should throw - ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(explain)); - assertThat(ex.getResponse().getStatusLine().getStatusCode(), equalTo(403)); + expectThrows(ResponseException.class, () -> client().performRequest(explain)); } { // request with secondary headers with perms Request explain = explainRequestConfigId(configId); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java index 82e106a66d6..0904570d4db 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java @@ -376,8 +376,10 @@ public class ExtractedFieldsDetector { if (preferSource) { extractedFields = fetchFromSourceIfSupported(extractedFields); if (extractedFields.getDocValueFields().size() > docValueFieldsLimit) { - throw ExceptionsHelper.badRequestException("[{}] fields must be retrieved from doc_values but the limit is [{}]; " + - "please adjust the index level setting [{}]", extractedFields.getDocValueFields().size(), docValueFieldsLimit, + throw ExceptionsHelper.badRequestException( + "[{}] fields must be retrieved from doc_values and this is greater than the configured limit. " + + "Please adjust the index level setting [{}]", + extractedFields.getDocValueFields().size(), IndexSettings.MAX_DOCVALUE_FIELDS_SEARCH_SETTING.getKey()); } } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorFactory.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorFactory.java index 04a5251a4ff..2d2bb689d4c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorFactory.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorFactory.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; import org.elasticsearch.action.fieldcaps.FieldCapabilities; @@ -45,6 +46,9 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN; +import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin; + /** * A factory that retrieves all the parts necessary to build a {@link ExtractedFieldsDetector}. */ @@ -138,7 +142,7 @@ public class ExtractedFieldsDetectorFactory { } SearchRequest searchRequest = new SearchRequest(index).source(searchSourceBuilder); ClientHelper.executeWithHeadersAsync( - config.getHeaders(), ClientHelper.ML_ORIGIN, client, SearchAction.INSTANCE, searchRequest, searchListener); + config.getHeaders(), ML_ORIGIN, client, SearchAction.INSTANCE, searchRequest, searchListener); } private void buildFieldCardinalitiesMap(DataFrameAnalyticsConfig config, SearchResponse searchResponse, @@ -168,7 +172,7 @@ public class ExtractedFieldsDetectorFactory { fieldCapabilitiesRequest.fields("*"); LOGGER.debug(() -> new ParameterizedMessage( "[{}] Requesting field caps for index {}", config.getId(), Arrays.toString(index))); - ClientHelper.executeWithHeaders(config.getHeaders(), ClientHelper.ML_ORIGIN, client, () -> { + ClientHelper.executeWithHeaders(config.getHeaders(), ML_ORIGIN, client, () -> { client.execute(FieldCapabilitiesAction.INSTANCE, fieldCapabilitiesRequest, listener); // This response gets discarded - the listener handles the real response return null; @@ -205,6 +209,6 @@ public class ExtractedFieldsDetectorFactory { getSettingsRequest.indices(index); getSettingsRequest.includeDefaults(true); getSettingsRequest.names(IndexSettings.MAX_DOCVALUE_FIELDS_SEARCH_SETTING.getKey()); - client.admin().indices().getSettings(getSettingsRequest, settingsListener); + executeAsyncWithOrigin(client, ML_ORIGIN, GetSettingsAction.INSTANCE, getSettingsRequest, settingsListener); } }