Skip to content

Commit

Permalink
Remove too_many_fields upgrade check (#82809)
Browse files Browse the repository at this point in the history
This check issues a warning if the cluster contains an index that has more
than 1024 fields, and no default_field set for searching. However, the 1024
boolean clause limit is no longer relevant with #81850, and in any case this
isn't something that would have prevented a successful upgrade from 7.17 to
8.0, so we can remove the check entirely.

Fixes #81539
  • Loading branch information
romseygeek committed Jan 20, 2022
1 parent 1704a5f commit 520b0a0
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ private static Set<Setting<Boolean>> getAllDeprecatedNodeRolesSettings() {
static List<BiFunction<ClusterState, IndexMetadata, DeprecationIssue>> INDEX_SETTINGS_CHECKS = Collections.unmodifiableList(
Arrays.asList(
(clusterState, indexMetadata) -> IndexDeprecationChecks.oldIndicesCheck(indexMetadata),
(clusterState, indexMetadata) -> IndexDeprecationChecks.tooManyFieldsCheck(indexMetadata),
(clusterState, indexMetadata) -> IndexDeprecationChecks.chainedMultiFieldsCheck(indexMetadata),
(clusterState, indexMetadata) -> IndexDeprecationChecks.chainedMultiFieldsDynamicTemplateCheck(indexMetadata),
(clusterState, indexMetadata) -> IndexDeprecationChecks.boostMappingCheck(indexMetadata),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand Down Expand Up @@ -193,38 +192,6 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata) {
return null;
}

static DeprecationIssue tooManyFieldsCheck(IndexMetadata indexMetadata) {
if (indexMetadata.getSettings().get(IndexSettings.DEFAULT_FIELD_SETTING.getKey()) == null) {
AtomicInteger fieldCount = new AtomicInteger(0);

fieldLevelMappingIssue(
indexMetadata,
((mappingMetadata, sourceAsMap) -> { fieldCount.addAndGet(countFieldsRecursively(mappingMetadata.type(), sourceAsMap)); })
);

// We can't get to the setting `indices.query.bool.max_clause_count` from here, so just check the default of that setting.
// It's also much better practice to set `index.query.default_field` than `indices.query.bool.max_clause_count` - there's a
// reason we introduced the limit.
if (fieldCount.get() > 1024) {
return new DeprecationIssue(
DeprecationIssue.Level.WARNING,
"Number of fields exceeds automatic field expansion limit",
"https://ela.st/es-deprecation-7-number-of-auto-expanded-fields",
"This index has "
+ fieldCount.get()
+ " fields, which exceeds the automatic field expansion limit (1024). Set "
+ IndexSettings.DEFAULT_FIELD_SETTING.getKey()
+ " to prevent queries that support automatic field expansion from "
+ "failing if no fields are specified. Otherwise, you must explicitly specify fields in all query_string, "
+ "simple_query_string, and multi_match queries.",
false,
null
);
}
}
return null;
}

static DeprecationIssue deprecatedDateTimeFormat(IndexMetadata indexMetadata) {
Version createdWith = indexMetadata.getCreationVersion();
if (createdWith.before(Version.V_7_0_0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.cluster.routing.allocation.DataTier;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexModule;
Expand Down Expand Up @@ -41,7 +40,6 @@
import java.util.stream.Stream;

import static java.util.Collections.singletonList;
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_EXCLUDE_SETTING;
import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_INCLUDE_SETTING;
import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING;
Expand Down Expand Up @@ -83,87 +81,6 @@ public void testOldIndicesCheck() {
assertEquals(singletonList(expected), issues);
}

public void testTooManyFieldsCheck() throws IOException {
String simpleMapping = "{\n"
+ " \"properties\": {\n"
+ " \"some_field\": {\n"
+ " \"type\": \"text\"\n"
+ " },\n"
+ " \"other_field\": {\n"
+ " \"type\": \"text\",\n"
+ " \"properties\": {\n"
+ " \"raw\": {\"type\": \"keyword\"}\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";

IndexMetadata simpleIndex = IndexMetadata.builder(randomAlphaOfLengthBetween(5, 10))
.settings(settings(Version.V_7_0_0))
.numberOfShards(randomIntBetween(1, 100))
.numberOfReplicas(randomIntBetween(1, 100))
.putMapping("_doc", simpleMapping)
.build();
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(
INDEX_SETTINGS_CHECKS,
c -> c.apply(ClusterState.EMPTY_STATE, simpleIndex)
);
assertEquals(0, noIssues.size());

// Test that it catches having too many fields
int fieldCount = randomIntBetween(1025, 10_000); // 10_000 is arbitrary

XContentBuilder mappingBuilder = jsonBuilder();
mappingBuilder.startObject();
{
mappingBuilder.startObject("properties");
{
addRandomFields(fieldCount, mappingBuilder);
}
mappingBuilder.endObject();
}
mappingBuilder.endObject();

IndexMetadata tooManyFieldsIndex = IndexMetadata.builder(randomAlphaOfLengthBetween(5, 10))
.settings(settings(Version.V_7_0_0))
.numberOfShards(randomIntBetween(1, 100))
.numberOfReplicas(randomIntBetween(1, 100))
.putMapping("_doc", Strings.toString(mappingBuilder))
.build();
DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.WARNING,
"Number of fields exceeds automatic field expansion limit",
"https://ela.st/es-deprecation-7-number-of-auto-expanded-fields",
"This index has "
+ fieldCount
+ " fields, which exceeds the automatic field expansion limit (1024). Set "
+ IndexSettings.DEFAULT_FIELD_SETTING.getKey()
+ " to prevent queries that support automatic field expansion from failing "
+ "if no fields are specified. Otherwise, you must explicitly specify fields in all query_string, simple_query_string, and "
+ "multi_match queries.",
false,
null
);
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(
INDEX_SETTINGS_CHECKS,
c -> c.apply(ClusterState.EMPTY_STATE, tooManyFieldsIndex)
);
assertEquals(singletonList(expected), issues);

// Check that it's okay to have too many fields as long as `index.query.default_field` is set
IndexMetadata tooManyFieldsOk = IndexMetadata.builder(randomAlphaOfLengthBetween(5, 10))
.settings(settings(Version.V_7_0_0).put(IndexSettings.DEFAULT_FIELD_SETTING.getKey(), randomAlphaOfLength(5)))
.numberOfShards(randomIntBetween(1, 100))
.numberOfReplicas(randomIntBetween(1, 100))
.putMapping("_doc", Strings.toString(mappingBuilder))
.build();
List<DeprecationIssue> withDefaultFieldIssues = DeprecationChecks.filterChecks(
INDEX_SETTINGS_CHECKS,
c -> c.apply(ClusterState.EMPTY_STATE, tooManyFieldsOk)
);
assertEquals(0, withDefaultFieldIssues.size());
}

public void testChainedMultiFields() throws IOException {
XContentBuilder xContent = XContentFactory.jsonBuilder();
xContent.startObject();
Expand Down

0 comments on commit 520b0a0

Please sign in to comment.