From 85bb5a7f46705035454f8b81b309051035c160bc Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Tue, 19 Mar 2019 10:52:35 -0600 Subject: [PATCH] Only count some fields types for deprecation check (#40166) Some field types are not used for queries which use auto-expansion, in particular, `binary`, `geo_point`, and `geo_shape`. This was causing the count returned by the deprecation check and the count returned by the query-time deprecation warning to be misaligned for indices with fields of those types, with the count returned by the deprecation check being larger. --- .../deprecation/IndexDeprecationChecks.java | 18 ++++++++++++++++-- .../IndexDeprecationChecksTests.java | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index a0cdbaee3b4..4a56cb78dd1 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -14,8 +14,11 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiConsumer; import java.util.function.Function; @@ -112,6 +115,15 @@ public class IndexDeprecationChecks { return null; } + + private static final Set TYPES_THAT_DONT_COUNT; + static { + HashSet typesThatDontCount = new HashSet<>(); + typesThatDontCount.add("binary"); + typesThatDontCount.add("geo_point"); + typesThatDontCount.add("geo_shape"); + TYPES_THAT_DONT_COUNT = Collections.unmodifiableSet(typesThatDontCount); + } /* Counts the number of fields in a mapping, designed to count the as closely as possible to * org.elasticsearch.index.search.QueryParserHelper#checkForTooManyFields */ @@ -125,7 +137,8 @@ public class IndexDeprecationChecks { for (Map.Entry entry : properties.entrySet()) { Map valueMap = (Map) entry.getValue(); if (valueMap.containsKey("type") - && (valueMap.get("type").equals("object") && valueMap.containsKey("properties") == false) == false) { + && (valueMap.get("type").equals("object") && valueMap.containsKey("properties") == false) == false + && (TYPES_THAT_DONT_COUNT.contains(valueMap.get("type")) == false)) { fields++; } @@ -133,7 +146,8 @@ public class IndexDeprecationChecks { if (values != null) { for (Map.Entry multifieldEntry : values.entrySet()) { Map multifieldValueMap = (Map) multifieldEntry.getValue(); - if (multifieldValueMap.containsKey("type")) { + if (multifieldValueMap.containsKey("type") + && (TYPES_THAT_DONT_COUNT.contains(valueMap.get("type")) == false)) { fields++; } if (multifieldValueMap.containsKey("properties")) { diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java index 9eb27cb127c..4896bf715a9 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java @@ -138,7 +138,7 @@ public class IndexDeprecationChecksTests extends ESTestCase { } mappingBuilder.endObject(); } else { - mappingBuilder.field("type", randomFrom("array", "binary", "range", "boolean", "date", "ip", "keyword", "text")); + mappingBuilder.field("type", randomFrom("array", "range", "boolean", "date", "ip", "keyword", "text")); fieldCount.incrementAndGet(); } }