[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.
This commit is contained in:
Benjamin Trent 2020-10-08 08:53:26 -04:00 committed by GitHub
parent e022b78198
commit a9be4181c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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);
}
}