From 1ae920cb90047d3e2a908fc5526de069e0542442 Mon Sep 17 00:00:00 2001 From: Peter Dyson Date: Mon, 22 Jan 2018 18:39:21 +1000 Subject: [PATCH 1/8] Provide explanation of dangling indices, fixes #26008 (#26999) * Provide explanation of dangling indices, fixes #26008 Adjusted from PR review comments * updates to suggested wording and minor typo fix. --- docs/reference/modules/gateway.asciidoc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/reference/modules/gateway.asciidoc b/docs/reference/modules/gateway.asciidoc index 0af0d31fba2..76e08407939 100644 --- a/docs/reference/modules/gateway.asciidoc +++ b/docs/reference/modules/gateway.asciidoc @@ -48,3 +48,12 @@ as long as the following conditions are met: Recover as long as this many data nodes have joined the cluster. NOTE: These settings only take effect on a full cluster restart. + +=== Dangling indices + +When a node joins the cluster, any shards stored in its local data directory +directory which do not already exist in the cluster will be imported into the +cluster. This functionality is intended as a best effort to help users who +lose all master nodes. If a new master node is started which is unaware of +the other indices in the cluster, adding the old nodes will cause the old +indices to be imported, instead of being deleted. From 119b1b5c2b26a6adc2df7a95396da7b2411b5f09 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Mon, 22 Jan 2018 09:52:57 +0100 Subject: [PATCH 2/8] Add information when master node left to DiscoveryNodes' shortSummary() (#28197) This commit changes `DiscoveryNodes.Delta.shortSummary()` in order to add information to the summary when the master node left. --- .../cluster/node/DiscoveryNodes.java | 92 +++++++++---------- .../cluster/node/DiscoveryNodesTests.java | 7 +- 2 files changed, 45 insertions(+), 54 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index 4373069a5f7..057d37d5999 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -39,6 +39,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; /** * This class holds all {@link DiscoveryNode} in the cluster and provides convenience methods to @@ -205,12 +206,14 @@ public class DiscoveryNodes extends AbstractDiffable implements } /** - * Get the master node - * - * @return master node + * Returns the master node, or {@code null} if there is no master node */ + @Nullable public DiscoveryNode getMasterNode() { - return nodes.get(masterNodeId); + if (masterNodeId != null) { + return nodes.get(masterNodeId); + } + return null; } /** @@ -385,27 +388,20 @@ public class DiscoveryNodes extends AbstractDiffable implements * Returns the changes comparing this nodes to the provided nodes. */ public Delta delta(DiscoveryNodes other) { - List removed = new ArrayList<>(); - List added = new ArrayList<>(); + final List removed = new ArrayList<>(); + final List added = new ArrayList<>(); for (DiscoveryNode node : other) { - if (!this.nodeExists(node)) { + if (this.nodeExists(node) == false) { removed.add(node); } } for (DiscoveryNode node : this) { - if (!other.nodeExists(node)) { + if (other.nodeExists(node) == false) { added.add(node); } } - DiscoveryNode previousMasterNode = null; - DiscoveryNode newMasterNode = null; - if (masterNodeId != null) { - if (other.masterNodeId == null || !other.masterNodeId.equals(masterNodeId)) { - previousMasterNode = other.getMasterNode(); - newMasterNode = getMasterNode(); - } - } - return new Delta(previousMasterNode, newMasterNode, localNodeId, Collections.unmodifiableList(removed), + + return new Delta(other.getMasterNode(), getMasterNode(), localNodeId, Collections.unmodifiableList(removed), Collections.unmodifiableList(added)); } @@ -429,8 +425,8 @@ public class DiscoveryNodes extends AbstractDiffable implements public static class Delta { private final String localNodeId; - private final DiscoveryNode previousMasterNode; - private final DiscoveryNode newMasterNode; + @Nullable private final DiscoveryNode previousMasterNode; + @Nullable private final DiscoveryNode newMasterNode; private final List removed; private final List added; @@ -448,13 +444,15 @@ public class DiscoveryNodes extends AbstractDiffable implements } public boolean masterNodeChanged() { - return newMasterNode != null; + return Objects.equals(newMasterNode, previousMasterNode) == false; } + @Nullable public DiscoveryNode previousMasterNode() { return previousMasterNode; } + @Nullable public DiscoveryNode newMasterNode() { return newMasterNode; } @@ -476,51 +474,45 @@ public class DiscoveryNodes extends AbstractDiffable implements } public String shortSummary() { - StringBuilder sb = new StringBuilder(); - if (!removed() && masterNodeChanged()) { - if (newMasterNode.getId().equals(localNodeId)) { - // we are the master, no nodes we removed, we are actually the first master - sb.append("new_master ").append(newMasterNode()); - } else { - // we are not the master, so we just got this event. No nodes were removed, so its not a *new* master - sb.append("detected_master ").append(newMasterNode()); + final StringBuilder summary = new StringBuilder(); + if (masterNodeChanged()) { + summary.append("master node changed {previous ["); + if (previousMasterNode() != null) { + summary.append(previousMasterNode()); } - } else { - if (masterNodeChanged()) { - sb.append("master {new ").append(newMasterNode()); - if (previousMasterNode() != null) { - sb.append(", previous ").append(previousMasterNode()); - } - sb.append("}"); + summary.append("], current ["); + if (newMasterNode() != null) { + summary.append(newMasterNode()); } - if (removed()) { - if (masterNodeChanged()) { - sb.append(", "); - } - sb.append("removed {"); - for (DiscoveryNode node : removedNodes()) { - sb.append(node).append(','); - } - sb.append("}"); + summary.append("]}"); + } + if (removed()) { + if (summary.length() > 0) { + summary.append(", "); } + summary.append("removed {"); + for (DiscoveryNode node : removedNodes()) { + summary.append(node).append(','); + } + summary.append("}"); } if (added()) { // don't print if there is one added, and it is us if (!(addedNodes().size() == 1 && addedNodes().get(0).getId().equals(localNodeId))) { - if (removed() || masterNodeChanged()) { - sb.append(", "); + if (summary.length() > 0) { + summary.append(", "); } - sb.append("added {"); + summary.append("added {"); for (DiscoveryNode node : addedNodes()) { if (!node.getId().equals(localNodeId)) { // don't print ourself - sb.append(node).append(','); + summary.append(node).append(','); } } - sb.append("}"); + summary.append("}"); } } - return sb.toString(); + return summary.toString(); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java index 9200e04c712..6bfb78a2ade 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -140,15 +140,14 @@ public class DiscoveryNodesTests extends ESTestCase { DiscoveryNodes.Delta delta = discoNodesB.delta(discoNodesA); - if (masterB == null || Objects.equals(masterAId, masterBId)) { + if (Objects.equals(masterAId, masterBId)) { assertFalse(delta.masterNodeChanged()); assertThat(delta.previousMasterNode(), nullValue()); assertThat(delta.newMasterNode(), nullValue()); } else { assertTrue(delta.masterNodeChanged()); - assertThat(delta.newMasterNode().getId(), equalTo(masterBId)); - assertThat(delta.previousMasterNode() != null ? delta.previousMasterNode().getId() : null, - equalTo(masterAId)); + assertThat(delta.newMasterNode() != null ? delta.newMasterNode().getId() : null, equalTo(masterBId)); + assertThat(delta.previousMasterNode() != null ? delta.previousMasterNode().getId() : null, equalTo(masterAId)); } Set newNodes = new HashSet<>(nodesB); From 700d9ecc953fa30df0d12d086f0e9d9322446459 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Mon, 22 Jan 2018 12:03:07 +0100 Subject: [PATCH 3/8] Remove the `update_all_types` option. (#28288) This option is not useful in 7.x since no indices may have more than one type anymore. --- .../org/elasticsearch/client/Request.java | 8 -- .../elasticsearch/client/RequestTests.java | 8 -- .../migration/migrate_7_0/mappings.asciidoc | 6 +- .../index/mapper/ScaledFloatFieldMapper.java | 8 +- .../index/mapper/TokenCountFieldMapper.java | 4 +- .../mapper/TokenCountFieldMapperTests.java | 4 +- .../join/mapper/ParentIdFieldMapper.java | 4 +- .../join/mapper/ParentJoinFieldMapper.java | 8 +- .../mapper/ParentJoinFieldMapperTests.java | 34 ++++---- .../join/query/HasChildQueryBuilderTests.java | 2 +- .../query/HasParentQueryBuilderTests.java | 2 +- .../LegacyHasChildQueryBuilderTests.java | 4 +- .../LegacyHasParentQueryBuilderTests.java | 6 +- .../LegacyParentIdQueryBuilderTests.java | 4 +- .../join/query/ParentIdQueryBuilderTests.java | 2 +- .../percolator/CandidateQueryTests.java | 4 +- .../PercolateQueryBuilderTests.java | 4 +- .../PercolatorFieldMapperTests.java | 10 +-- .../ICUCollationKeywordFieldMapper.java | 8 +- .../ICUCollationKeywordFieldMapperTests.java | 4 +- .../index/mapper/size/SizeFieldMapper.java | 2 +- .../index/mapper/size/SizeMappingTests.java | 2 +- .../rest-api-spec/api/indices.create.json | 4 - .../api/indices.put_mapping.json | 4 - .../CreateIndexClusterStateUpdateRequest.java | 10 +-- .../indices/create/CreateIndexRequest.java | 21 ++--- .../create/CreateIndexRequestBuilder.java | 6 -- .../create/TransportCreateIndexAction.java | 2 +- .../PutMappingClusterStateUpdateRequest.java | 11 --- .../mapping/put/PutMappingRequest.java | 20 ++--- .../mapping/put/PutMappingRequestBuilder.java | 6 -- .../put/TransportPutMappingAction.java | 1 - .../rollover/TransportRolloverAction.java | 2 +- .../indices/shrink/TransportResizeAction.java | 2 +- .../metadata/MetaDataCreateIndexService.java | 2 +- .../metadata/MetaDataIndexAliasesService.java | 2 +- .../MetaDataIndexTemplateService.java | 2 +- .../metadata/MetaDataIndexUpgradeService.java | 2 +- .../metadata/MetaDataMappingService.java | 8 +- .../index/mapper/CompletionFieldMapper.java | 8 +- .../index/mapper/DateFieldMapper.java | 8 +- .../index/mapper/DocumentMapper.java | 4 +- .../index/mapper/DocumentParser.java | 4 +- .../index/mapper/FieldMapper.java | 9 +- .../index/mapper/FieldNamesFieldMapper.java | 11 --- .../index/mapper/FieldTypeLookup.java | 83 ++++--------------- .../index/mapper/GeoPointFieldMapper.java | 4 +- .../index/mapper/GeoShapeFieldMapper.java | 17 +--- .../index/mapper/IdFieldMapper.java | 2 +- .../index/mapper/IndexFieldMapper.java | 2 +- .../index/mapper/IpFieldMapper.java | 4 +- .../index/mapper/KeywordFieldMapper.java | 8 +- .../index/mapper/MappedFieldType.java | 23 +---- .../elasticsearch/index/mapper/Mapper.java | 2 +- .../index/mapper/MapperService.java | 35 ++++---- .../elasticsearch/index/mapper/Mapping.java | 8 +- .../index/mapper/MetadataFieldMapper.java | 4 +- .../index/mapper/NumberFieldMapper.java | 4 +- .../index/mapper/ObjectMapper.java | 11 ++- .../index/mapper/ParentFieldMapper.java | 4 +- .../index/mapper/ParsedDocument.java | 2 +- .../index/mapper/RangeFieldMapper.java | 27 +----- .../index/mapper/RootObjectMapper.java | 8 +- .../index/mapper/RoutingFieldMapper.java | 2 +- .../index/mapper/SeqNoFieldMapper.java | 2 +- .../index/mapper/SourceFieldMapper.java | 2 +- .../index/mapper/TextFieldMapper.java | 29 +------ .../index/mapper/TypeFieldMapper.java | 2 +- .../index/mapper/UidFieldMapper.java | 2 +- .../index/mapper/VersionFieldMapper.java | 2 +- .../index/shard/StoreRecovery.java | 2 +- .../elasticsearch/indices/IndicesService.java | 2 +- .../admin/indices/RestCreateIndexAction.java | 1 - .../admin/indices/RestPutMappingAction.java | 1 - .../admin/indices/create/CreateIndexIT.java | 2 +- .../metadata/IndexCreationTaskTests.java | 4 +- .../index/mapper/AllFieldMapperTests.java | 2 +- .../index/mapper/BooleanFieldMapperTests.java | 2 +- .../index/mapper/CopyToMapperTests.java | 20 ++--- .../index/mapper/DateFieldMapperTests.java | 6 +- .../mapper/DocumentMapperMergeTests.java | 34 ++++---- .../index/mapper/DynamicMappingTests.java | 12 +-- .../index/mapper/ExternalMapper.java | 2 +- .../index/mapper/FakeStringFieldMapper.java | 4 +- .../mapper/FieldNamesFieldMapperTests.java | 6 +- .../index/mapper/FieldTypeLookupTests.java | 56 ++++--------- .../mapper/GeoShapeFieldMapperTests.java | 6 +- .../index/mapper/IdFieldMapperTests.java | 4 +- .../mapper/JavaMultiFieldMergeTests.java | 16 ++-- .../index/mapper/KeywordFieldMapperTests.java | 6 +- .../index/mapper/MapperServiceTests.java | 36 ++++---- .../index/mapper/NestedObjectMapperTests.java | 16 ++-- .../index/mapper/ObjectMapperTests.java | 4 +- .../index/mapper/ParentFieldMapperTests.java | 12 +-- ...angeFieldQueryStringQueryBuilderTests.java | 2 +- .../index/mapper/RootObjectMapperTests.java | 24 +++--- .../index/mapper/SourceFieldMapperTests.java | 10 +-- .../mapper/StoredNumericValuesTests.java | 2 +- .../index/mapper/TextFieldMapperTests.java | 4 +- .../index/mapper/TypeFieldMapperTests.java | 6 +- .../index/mapper/UidFieldMapperTests.java | 4 +- .../index/mapper/UpdateMappingTests.java | 30 +++---- .../index/query/MatchQueryBuilderTests.java | 2 +- .../index/query/NestedQueryBuilderTests.java | 2 +- .../query/QueryStringQueryBuilderTests.java | 4 +- .../index/query/RangeQueryRewriteTests.java | 4 +- .../query/TermsSetQueryBuilderTests.java | 2 +- .../index/search/MultiMatchQueryTests.java | 2 +- .../mapping/UpdateMappingIntegrationIT.java | 1 - .../search/child/ParentFieldLoadingIT.java | 1 - .../index/engine/TranslogHandler.java | 2 +- .../index/mapper/FieldTypeTestCase.java | 46 ++++------ .../index/shard/IndexShardTestCase.java | 4 +- .../test/AbstractQueryTestCase.java | 4 +- 114 files changed, 368 insertions(+), 620 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java index e55204c3d94..cc3b0deff52 100755 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java @@ -173,7 +173,6 @@ public final class Request { parameters.withTimeout(createIndexRequest.timeout()); parameters.withMasterTimeout(createIndexRequest.masterNodeTimeout()); parameters.withWaitForActiveShards(createIndexRequest.waitForActiveShards()); - parameters.withUpdateAllTypes(createIndexRequest.updateAllTypes()); HttpEntity entity = createEntity(createIndexRequest, REQUEST_BODY_CONTENT_TYPE); return new Request(HttpPut.METHOD_NAME, endpoint, parameters.getParams(), entity); @@ -585,13 +584,6 @@ public final class Request { return putParam("timeout", timeout); } - Params withUpdateAllTypes(boolean updateAllTypes) { - if (updateAllTypes) { - return putParam("update_all_types", Boolean.TRUE.toString()); - } - return this; - } - Params withVersion(long version) { if (version != Versions.MATCH_ANY) { return putParam("version", Long.toString(version)); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java index 56848a905a1..49667a3dee2 100755 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java @@ -310,14 +310,6 @@ public class RequestTests extends ESTestCase { setRandomMasterTimeout(createIndexRequest, expectedParams); setRandomWaitForActiveShards(createIndexRequest::waitForActiveShards, expectedParams); - if (randomBoolean()) { - boolean updateAllTypes = randomBoolean(); - createIndexRequest.updateAllTypes(updateAllTypes); - if (updateAllTypes) { - expectedParams.put("update_all_types", Boolean.TRUE.toString()); - } - } - Request request = Request.createIndex(createIndexRequest); assertEquals("/" + indexName, request.getEndpoint()); assertEquals(expectedParams, request.getParameters()); diff --git a/docs/reference/migration/migrate_7_0/mappings.asciidoc b/docs/reference/migration/migrate_7_0/mappings.asciidoc index 215282c49d7..ece9cac5962 100644 --- a/docs/reference/migration/migrate_7_0/mappings.asciidoc +++ b/docs/reference/migration/migrate_7_0/mappings.asciidoc @@ -13,4 +13,8 @@ The `index_options` field for numeric fields has been deprecated in 6 and has n To safeguard against out of memory errors, the number of nested json objects within a single document across all fields has been limited to 10000. This default limit can be changed with -the index setting `index.mapping.nested_objects.limit`. \ No newline at end of file +the index setting `index.mapping.nested_objects.limit`. + +==== The `update_all_types` option has been removed + +This option is useless now that all indices have at most one type. diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java index 96ec29e2aa6..5770c91cfdb 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java @@ -207,8 +207,8 @@ public class ScaledFloatFieldMapper extends FieldMapper { } @Override - public void checkCompatibility(MappedFieldType other, List conflicts, boolean strict) { - super.checkCompatibility(other, conflicts, strict); + public void checkCompatibility(MappedFieldType other, List conflicts) { + super.checkCompatibility(other, conflicts); if (scalingFactor != ((ScaledFloatFieldType) other).getScalingFactor()) { conflicts.add("mapper [" + name() + "] has different [scaling_factor] values"); } @@ -424,8 +424,8 @@ public class ScaledFloatFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); ScaledFloatFieldMapper other = (ScaledFloatFieldMapper) mergeWith; if (other.ignoreMalformed.explicit()) { this.ignoreMalformed = other.ignoreMalformed; diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java index c18b66cf618..7a777963baa 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java @@ -202,8 +202,8 @@ public class TokenCountFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); this.analyzer = ((TokenCountFieldMapper) mergeWith).analyzer; this.enablePositionIncrements = ((TokenCountFieldMapper) mergeWith).enablePositionIncrements; } diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java index 633f1027609..13c4e87f95e 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java @@ -63,7 +63,7 @@ public class TokenCountFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); MapperService mapperService = createIndex("test").mapperService(); DocumentMapper stage1 = mapperService.merge("person", - new CompressedXContent(stage1Mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + new CompressedXContent(stage1Mapping), MapperService.MergeReason.MAPPING_UPDATE); String stage2Mapping = XContentFactory.jsonBuilder().startObject() .startObject("person") @@ -75,7 +75,7 @@ public class TokenCountFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().endObject().string(); DocumentMapper stage2 = mapperService.merge("person", - new CompressedXContent(stage2Mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + new CompressedXContent(stage2Mapping), MapperService.MergeReason.MAPPING_UPDATE); // previous mapper has not been modified assertThat(((TokenCountFieldMapper) stage1.mappers().smartNameFieldMapper("tc")).analyzer(), equalTo("keyword")); diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java index 21078c2763f..8130acac1af 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java @@ -194,8 +194,8 @@ public final class ParentIdFieldMapper extends FieldMapper { @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); ParentIdFieldMapper parentMergeWith = (ParentIdFieldMapper) mergeWith; this.children = parentMergeWith.children; } diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java index b2ec28cf0c8..d3164ae6a12 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java @@ -316,8 +316,8 @@ public final class ParentJoinFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); ParentJoinFieldMapper joinMergeWith = (ParentJoinFieldMapper) mergeWith; List conflicts = new ArrayList<>(); for (ParentIdFieldMapper mapper : parentIdFields) { @@ -347,7 +347,7 @@ public final class ParentJoinFieldMapper extends FieldMapper { conflicts.add("cannot remove child [" + child + "] in join field [" + name() + "]"); } } - ParentIdFieldMapper merged = (ParentIdFieldMapper) self.merge(mergeWithMapper, updateAllTypes); + ParentIdFieldMapper merged = (ParentIdFieldMapper) self.merge(mergeWithMapper); newParentIdFields.add(merged); } } @@ -356,7 +356,7 @@ public final class ParentJoinFieldMapper extends FieldMapper { } this.eagerGlobalOrdinals = joinMergeWith.eagerGlobalOrdinals; this.parentIdFields = Collections.unmodifiableList(newParentIdFields); - this.uniqueFieldMapper = (MetaJoinFieldMapper) uniqueFieldMapper.merge(joinMergeWith.uniqueFieldMapper, updateAllTypes); + this.uniqueFieldMapper = (MetaJoinFieldMapper) uniqueFieldMapper.merge(joinMergeWith.uniqueFieldMapper); uniqueFieldMapper.setFieldMapper(this); } diff --git a/modules/parent-join/src/test/java/org/elasticsearch/join/mapper/ParentJoinFieldMapperTests.java b/modules/parent-join/src/test/java/org/elasticsearch/join/mapper/ParentJoinFieldMapperTests.java index 6bfc9b87b78..285e7e80195 100644 --- a/modules/parent-join/src/test/java/org/elasticsearch/join/mapper/ParentJoinFieldMapperTests.java +++ b/modules/parent-join/src/test/java/org/elasticsearch/join/mapper/ParentJoinFieldMapperTests.java @@ -57,7 +57,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject().string(); IndexService service = createIndex("test"); DocumentMapper docMapper = service.mapperService().merge("type", new CompressedXContent(mapping), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService())); // Doc without join @@ -106,7 +106,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject().string(); IndexService service = createIndex("test"); DocumentMapper docMapper = service.mapperService().merge("type", new CompressedXContent(mapping), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "2", XContentFactory.jsonBuilder().startObject() .startObject("join_field") @@ -141,7 +141,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject().string(); IndexService service = createIndex("test"); DocumentMapper docMapper = service.mapperService().merge("type", new CompressedXContent(mapping), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService())); // Doc without join @@ -221,7 +221,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); IndexService indexService = createIndex("test"); DocumentMapper docMapper = indexService.mapperService().merge("type", new CompressedXContent(mapping), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(indexService.mapperService())); { @@ -235,7 +235,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); IllegalStateException exc = expectThrows(IllegalStateException.class, () -> indexService.mapperService().merge("type", new CompressedXContent(updateMapping), - MapperService.MergeReason.MAPPING_UPDATE, false)); + MapperService.MergeReason.MAPPING_UPDATE)); assertThat(exc.getMessage(), containsString("cannot remove parent [parent] in join field [join_field]")); } @@ -251,7 +251,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); IllegalStateException exc = expectThrows(IllegalStateException.class, () -> indexService.mapperService().merge("type", new CompressedXContent(updateMapping), - MapperService.MergeReason.MAPPING_UPDATE, false)); + MapperService.MergeReason.MAPPING_UPDATE)); assertThat(exc.getMessage(), containsString("cannot remove child [grand_child2] in join field [join_field]")); } @@ -268,7 +268,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); IllegalStateException exc = expectThrows(IllegalStateException.class, () -> indexService.mapperService().merge("type", new CompressedXContent(updateMapping), - MapperService.MergeReason.MAPPING_UPDATE, false)); + MapperService.MergeReason.MAPPING_UPDATE)); assertThat(exc.getMessage(), containsString("cannot create child [parent] from an existing parent")); } @@ -285,7 +285,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); IllegalStateException exc = expectThrows(IllegalStateException.class, () -> indexService.mapperService().merge("type", new CompressedXContent(updateMapping), - MapperService.MergeReason.MAPPING_UPDATE, false)); + MapperService.MergeReason.MAPPING_UPDATE)); assertThat(exc.getMessage(), containsString("cannot create parent [grand_child2] from an existing child]")); } @@ -300,7 +300,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().endObject().string(); docMapper = indexService.mapperService().merge("type", new CompressedXContent(updateMapping), - MapperService.MergeReason.MAPPING_UPDATE, true); + MapperService.MergeReason.MAPPING_UPDATE); assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(indexService.mapperService())); ParentJoinFieldMapper mapper = ParentJoinFieldMapper.getMapper(indexService.mapperService()); assertTrue(mapper.hasChild("child2")); @@ -321,7 +321,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().endObject().string(); docMapper = indexService.mapperService().merge("type", new CompressedXContent(updateMapping), - MapperService.MergeReason.MAPPING_UPDATE, true); + MapperService.MergeReason.MAPPING_UPDATE); assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(indexService.mapperService())); ParentJoinFieldMapper mapper = ParentJoinFieldMapper.getMapper(indexService.mapperService()); assertTrue(mapper.hasParent("other")); @@ -349,7 +349,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { IndexService indexService = createIndex("test"); MapperParsingException exc = expectThrows(MapperParsingException.class, () -> indexService.mapperService().merge("type", new CompressedXContent(mapping), - MapperService.MergeReason.MAPPING_UPDATE, false)); + MapperService.MergeReason.MAPPING_UPDATE)); assertThat(exc.getRootCause().getMessage(), containsString("join field [object.join_field] cannot be added inside an object or in a multi-field")); } @@ -371,7 +371,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { IndexService indexService = createIndex("test"); MapperParsingException exc = expectThrows(MapperParsingException.class, () -> indexService.mapperService().merge("type", new CompressedXContent(mapping), - MapperService.MergeReason.MAPPING_UPDATE, false)); + MapperService.MergeReason.MAPPING_UPDATE)); assertThat(exc.getRootCause().getMessage(), containsString("join field [number.join_field] cannot be added inside an object or in a multi-field")); } @@ -397,7 +397,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().string(); IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("type", - new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false)); + new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE)); assertThat(exc.getMessage(), containsString("Field [_parent_join] is defined twice in [type]")); } @@ -414,7 +414,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().string(); indexService.mapperService().merge("type", - new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); String updateMapping = XContentFactory.jsonBuilder().startObject() .startObject("properties") .startObject("another_join_field") @@ -423,7 +423,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().string(); IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("type", - new CompressedXContent(updateMapping), MapperService.MergeReason.MAPPING_UPDATE, false)); + new CompressedXContent(updateMapping), MapperService.MergeReason.MAPPING_UPDATE)); assertThat(exc.getMessage(), containsString("Field [_parent_join] is defined twice in [type]")); } } @@ -442,7 +442,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject().string(); IndexService service = createIndex("test"); DocumentMapper docMapper = service.mapperService().merge("type", new CompressedXContent(mapping), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService())); assertFalse(service.mapperService().fullName("join_field").eagerGlobalOrdinals()); assertNotNull(service.mapperService().fullName("join_field#parent")); @@ -463,7 +463,7 @@ public class ParentJoinFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().string(); service.mapperService().merge("type", new CompressedXContent(mapping), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); assertFalse(service.mapperService().fullName("join_field").eagerGlobalOrdinals()); assertNotNull(service.mapperService().fullName("join_field#parent")); assertFalse(service.mapperService().fullName("join_field#parent").eagerGlobalOrdinals()); diff --git a/modules/parent-join/src/test/java/org/elasticsearch/join/query/HasChildQueryBuilderTests.java b/modules/parent-join/src/test/java/org/elasticsearch/join/query/HasChildQueryBuilderTests.java index 885c19c6cd4..0ec6bec977e 100644 --- a/modules/parent-join/src/test/java/org/elasticsearch/join/query/HasChildQueryBuilderTests.java +++ b/modules/parent-join/src/test/java/org/elasticsearch/join/query/HasChildQueryBuilderTests.java @@ -132,7 +132,7 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase - mapperService.merge("doc", new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true)); + mapperService.merge("doc", new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), containsString("Mapping definition for [" + fieldName + "] has unsupported parameters: [index : no]")); } @@ -592,7 +592,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { .startObject("query_field2").field("type", "percolator").endObject() .endObject() .endObject().endObject().string(); - mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true); + mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE); QueryBuilder queryBuilder = matchQuery("field", "value"); ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", @@ -623,7 +623,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { .endObject() .endObject() .endObject().endObject().string(); - mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true); + mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE); QueryBuilder queryBuilder = matchQuery("field", "value"); ParsedDocument doc = mapperService.documentMapper(typeName).parse(SourceToParse.source("test", typeName, "1", diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java index f927f920f90..a4502a953db 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java @@ -99,8 +99,8 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper { } @Override - public void checkCompatibility(MappedFieldType otherFT, List conflicts, boolean strict) { - super.checkCompatibility(otherFT, conflicts, strict); + public void checkCompatibility(MappedFieldType otherFT, List conflicts) { + super.checkCompatibility(otherFT, conflicts); CollationFieldType other = (CollationFieldType) otherFT; if (!Objects.equals(collator, other.collator)) { conflicts.add("mapper [" + name() + "] has different [collator]"); @@ -619,8 +619,8 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); List conflicts = new ArrayList<>(); ICUCollationKeywordFieldMapper icuMergeWith = (ICUCollationKeywordFieldMapper) mergeWith; diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java index 060a94a9d27..88f92d0aad8 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java @@ -434,7 +434,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { .field("language", "tr") .field("strength", "primary") .endObject().endObject().endObject().endObject().string(); - indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean()); + indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") @@ -443,7 +443,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().endObject().endObject().string(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("type", - new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, randomBoolean())); + new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE)); assertEquals("Can't merge because of conflicts: [Cannot update language setting for [" + FIELD_TYPE + "], Cannot update strength setting for [" + FIELD_TYPE + "]]", e.getMessage()); } diff --git a/plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java b/plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java index b2974f139fb..d3830ab2106 100644 --- a/plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java +++ b/plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java @@ -183,7 +183,7 @@ public class SizeFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { SizeFieldMapper sizeFieldMapperMergeWith = (SizeFieldMapper) mergeWith; if (sizeFieldMapperMergeWith.enabledState != enabledState && !sizeFieldMapperMergeWith.enabledState.unset()) { this.enabledState = sizeFieldMapperMergeWith.enabledState; diff --git a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java index 2cde1b1bd07..c433f0d256a 100644 --- a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java +++ b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java @@ -110,7 +110,7 @@ public class SizeMappingTests extends ESSingleNodeTestCase { .startObject("_size").field("enabled", false).endObject() .endObject().endObject().string(); docMapper = service.mapperService().merge("type", new CompressedXContent(disabledMapping), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); assertThat(docMapper.metadataMapper(SizeFieldMapper.class).enabled(), is(false)); } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create.json index 1433c893e25..f876df36f88 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create.json @@ -24,10 +24,6 @@ "master_timeout": { "type" : "time", "description" : "Specify timeout for connection to master" - }, - "update_all_types": { - "type": "boolean", - "description": "Whether to update the mapping for all fields with the same name across all types or not" } } }, diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.put_mapping.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.put_mapping.json index 5fce0bcefc8..c6b547914ef 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.put_mapping.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.put_mapping.json @@ -38,10 +38,6 @@ "options" : ["open","closed","none","all"], "default" : "open", "description" : "Whether to expand wildcard expression to concrete indices that are open, closed or both." - }, - "update_all_types": { - "type": "boolean", - "description": "Whether to update the mapping for all fields with the same name across all types or not" } } }, diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexClusterStateUpdateRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexClusterStateUpdateRequest.java index 1734c340bd4..4e2e2578875 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexClusterStateUpdateRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexClusterStateUpdateRequest.java @@ -43,7 +43,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ private final String cause; private final String index; private final String providedName; - private final boolean updateAllTypes; private Index recoverFrom; private ResizeType resizeType; @@ -61,12 +60,10 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT; - public CreateIndexClusterStateUpdateRequest(TransportMessage originalMessage, String cause, String index, String providedName, - boolean updateAllTypes) { + public CreateIndexClusterStateUpdateRequest(TransportMessage originalMessage, String cause, String index, String providedName) { this.originalMessage = originalMessage; this.cause = cause; this.index = index; - this.updateAllTypes = updateAllTypes; this.providedName = providedName; } @@ -155,11 +152,6 @@ public class CreateIndexClusterStateUpdateRequest extends ClusterStateUpdateRequ return recoverFrom; } - /** True if all fields that span multiple types should be updated, false otherwise */ - public boolean updateAllTypes() { - return updateAllTypes; - } - /** * The name that was provided by the user. This might contain a date math expression. * @see IndexMetaData#SETTING_INDEX_PROVIDED_NAME diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java index 17941b582ec..12f9f756194 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java @@ -85,8 +85,6 @@ public class CreateIndexRequest extends AcknowledgedRequest private final Map customs = new HashMap<>(); - private boolean updateAllTypes = false; - private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT; public CreateIndexRequest() { @@ -429,17 +427,6 @@ public class CreateIndexRequest extends AcknowledgedRequest return this.customs; } - /** True if all fields that span multiple types should be updated, false otherwise */ - public boolean updateAllTypes() { - return updateAllTypes; - } - - /** See {@link #updateAllTypes()} */ - public CreateIndexRequest updateAllTypes(boolean updateAllTypes) { - this.updateAllTypes = updateAllTypes; - return this; - } - public ActiveShardCount waitForActiveShards() { return waitForActiveShards; } @@ -499,7 +486,9 @@ public class CreateIndexRequest extends AcknowledgedRequest for (int i = 0; i < aliasesSize; i++) { aliases.add(Alias.read(in)); } - updateAllTypes = in.readBoolean(); + if (in.getVersion().before(Version.V_7_0_0_alpha1)) { + in.readBoolean(); // updateAllTypes + } waitForActiveShards = ActiveShardCount.readFrom(in); } @@ -523,7 +512,9 @@ public class CreateIndexRequest extends AcknowledgedRequest for (Alias alias : aliases) { alias.writeTo(out); } - out.writeBoolean(updateAllTypes); + if (out.getVersion().before(Version.V_7_0_0_alpha1)) { + out.writeBoolean(true); // updateAllTypes + } waitForActiveShards.writeTo(out); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java index fabe269124e..b42b4e9236f 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java @@ -239,12 +239,6 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder im private String source; - private boolean updateAllTypes = false; private Index concreteIndex; public PutMappingRequest() { @@ -290,17 +289,6 @@ public class PutMappingRequest extends AcknowledgedRequest im } } - /** True if all fields that span multiple types should be updated, false otherwise */ - public boolean updateAllTypes() { - return updateAllTypes; - } - - /** See {@link #updateAllTypes()} */ - public PutMappingRequest updateAllTypes(boolean updateAllTypes) { - this.updateAllTypes = updateAllTypes; - return this; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); @@ -312,7 +300,9 @@ public class PutMappingRequest extends AcknowledgedRequest im // we do not know the format from earlier versions so convert if necessary source = XContentHelper.convertToJson(new BytesArray(source), false, false, XContentFactory.xContentType(source)); } - updateAllTypes = in.readBoolean(); + if (in.getVersion().before(Version.V_7_0_0_alpha1)) { + in.readBoolean(); // updateAllTypes + } concreteIndex = in.readOptionalWriteable(Index::new); } @@ -323,7 +313,9 @@ public class PutMappingRequest extends AcknowledgedRequest im indicesOptions.writeIndicesOptions(out); out.writeOptionalString(type); out.writeString(source); - out.writeBoolean(updateAllTypes); + if (out.getVersion().before(Version.V_7_0_0_alpha1)) { + out.writeBoolean(true); // updateAllTypes + } out.writeOptionalWriteable(concreteIndex); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java index 43bfe78c487..7baba39d96a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java @@ -98,10 +98,4 @@ public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder() { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index 2ed5192e6cf..ded01077da2 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -232,7 +232,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction null); - mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY, false); + mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY); } } catch (Exception ex) { // Wrap the inner exception so we have the index name in the exception message diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index 12a56f00bd4..a116bc369b5 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -147,7 +147,7 @@ public class MetaDataMappingService extends AbstractComponent { // we need to create the index here, and add the current mapping to it, so we can merge indexService = indicesService.createIndex(indexMetaData, Collections.emptyList()); removeIndex = true; - indexService.mapperService().merge(indexMetaData, MergeReason.MAPPING_RECOVERY, true); + indexService.mapperService().merge(indexMetaData, MergeReason.MAPPING_RECOVERY); } IndexMetaData.Builder builder = IndexMetaData.builder(indexMetaData); @@ -224,7 +224,7 @@ public class MetaDataMappingService extends AbstractComponent { MapperService mapperService = indicesService.createIndexMapperService(indexMetaData); indexMapperServices.put(index, mapperService); // add mappings for all types, we need them for cross-type validation - mapperService.merge(indexMetaData, MergeReason.MAPPING_RECOVERY, request.updateAllTypes()); + mapperService.merge(indexMetaData, MergeReason.MAPPING_RECOVERY); } } currentState = applyRequest(currentState, request, indexMapperServices); @@ -264,7 +264,7 @@ public class MetaDataMappingService extends AbstractComponent { newMapper = mapperService.parse(request.type(), mappingUpdateSource, existingMapper == null); if (existingMapper != null) { // first, simulate: just call merge and ignore the result - existingMapper.merge(newMapper.mapping(), request.updateAllTypes()); + existingMapper.merge(newMapper.mapping()); } else { // TODO: can we find a better place for this validation? // The reason this validation is here is that the mapper service doesn't learn about @@ -310,7 +310,7 @@ public class MetaDataMappingService extends AbstractComponent { if (existingMapper != null) { existingSource = existingMapper.mappingSource(); } - DocumentMapper mergedMapper = mapperService.merge(mappingType, mappingUpdateSource, MergeReason.MAPPING_UPDATE, request.updateAllTypes()); + DocumentMapper mergedMapper = mapperService.merge(mappingType, mappingUpdateSource, MergeReason.MAPPING_UPDATE); CompressedXContent updatedSource = mergedMapper.mappingSource(); if (existingSource != null) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java index 186334c85cb..0c03e8a551f 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java @@ -324,8 +324,8 @@ public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapp } @Override - public void checkCompatibility(MappedFieldType fieldType, List conflicts, boolean strict) { - super.checkCompatibility(fieldType, conflicts, strict); + public void checkCompatibility(MappedFieldType fieldType, List conflicts) { + super.checkCompatibility(fieldType, conflicts); CompletionFieldType other = (CompletionFieldType)fieldType; if (preservePositionIncrements != other.preservePositionIncrements) { @@ -607,8 +607,8 @@ public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapp } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); CompletionFieldMapper fieldMergeWith = (CompletionFieldMapper) mergeWith; this.maxInputLength = fieldMergeWith.maxInputLength; } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index 3b21a3bd740..00e09112dee 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -219,8 +219,8 @@ public class DateFieldMapper extends FieldMapper { } @Override - public void checkCompatibility(MappedFieldType fieldType, List conflicts, boolean strict) { - super.checkCompatibility(fieldType, conflicts, strict); + public void checkCompatibility(MappedFieldType fieldType, List conflicts) { + super.checkCompatibility(fieldType, conflicts); DateFieldType other = (DateFieldType) fieldType; if (Objects.equals(dateTimeFormatter().format(), other.dateTimeFormatter().format()) == false) { conflicts.add("mapper [" + name() + "] has different [format] values"); @@ -472,8 +472,8 @@ public class DateFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); final DateFieldMapper other = (DateFieldMapper) mergeWith; if (other.ignoreMalformed.explicit()) { this.ignoreMalformed = other.ignoreMalformed; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java index e1e33739ac4..42f842e6128 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java @@ -296,8 +296,8 @@ public class DocumentMapper implements ToXContentFragment { return mapperService.getParentTypes().contains(type); } - public DocumentMapper merge(Mapping mapping, boolean updateAllTypes) { - Mapping merged = this.mapping.merge(mapping, updateAllTypes); + public DocumentMapper merge(Mapping mapping) { + Mapping merged = this.mapping.merge(mapping); return new DocumentMapper(mapperService, merged); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java b/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java index 596581a15a2..aa286b88346 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java @@ -218,7 +218,7 @@ final class DocumentParser { // We can see the same mapper more than once, for example, if we had foo.bar and foo.baz, where // foo did not yet exist. This will create 2 copies in dynamic mappings, which should be identical. // Here we just skip over the duplicates, but we merge them to ensure there are no conflicts. - newMapper.merge(previousMapper, false); + newMapper.merge(previousMapper); continue; } previousMapper = newMapper; @@ -275,7 +275,7 @@ final class DocumentParser { int lastIndex = parentMappers.size() - 1; ObjectMapper withNewMapper = parentMappers.get(lastIndex).mappingUpdate(mapper); if (merge) { - withNewMapper = parentMappers.get(lastIndex).merge(withNewMapper, false); + withNewMapper = parentMappers.get(lastIndex).merge(withNewMapper); } parentMappers.set(lastIndex, withNewMapper); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java index c6e0dd9c00b..f23a8d0ce96 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java @@ -312,17 +312,16 @@ public abstract class FieldMapper extends Mapper implements Cloneable { } @Override - public FieldMapper merge(Mapper mergeWith, boolean updateAllTypes) { + public FieldMapper merge(Mapper mergeWith) { FieldMapper merged = clone(); - merged.doMerge(mergeWith, updateAllTypes); + merged.doMerge(mergeWith); return merged; } /** * Merge changes coming from {@code mergeWith} in place. - * @param updateAllTypes TODO */ - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { if (!this.getClass().equals(mergeWith.getClass())) { String mergedType = mergeWith.getClass().getSimpleName(); if (mergeWith instanceof FieldMapper) { @@ -553,7 +552,7 @@ public abstract class FieldMapper extends Mapper implements Cloneable { if (mergeIntoMapper == null) { newMappersBuilder.put(mergeWithMapper.simpleName(), mergeWithMapper); } else { - FieldMapper merged = mergeIntoMapper.merge(mergeWithMapper, false); + FieldMapper merged = mergeIntoMapper.merge(mergeWithMapper); newMappersBuilder.put(merged.simpleName(), merged); // override previous definition } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java index 8482a94cfc7..ada640f8739 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java @@ -165,17 +165,6 @@ public class FieldNamesFieldMapper extends MetadataFieldMapper { return CONTENT_TYPE; } - @Override - public void checkCompatibility(MappedFieldType fieldType, List conflicts, boolean strict) { - super.checkCompatibility(fieldType, conflicts, strict); - if (strict) { - FieldNamesFieldType other = (FieldNamesFieldType)fieldType; - if (isEnabled() != other.isEnabled()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [enabled] across all types."); - } - } - } - public void setEnabled(boolean enabled) { checkIfFrozen(); this.enabled = enabled; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/FieldTypeLookup.java b/server/src/main/java/org/elasticsearch/index/mapper/FieldTypeLookup.java index fee41e43f2a..069468ddb7a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/FieldTypeLookup.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/FieldTypeLookup.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.regex.Regex; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -39,37 +38,13 @@ class FieldTypeLookup implements Iterable { /** Full field name to field type */ final CopyOnWriteHashMap fullNameToFieldType; - /** Full field name to types containing a mapping for this full name. */ - final CopyOnWriteHashMap> fullNameToTypes; - /** Create a new empty instance. */ FieldTypeLookup() { fullNameToFieldType = new CopyOnWriteHashMap<>(); - fullNameToTypes = new CopyOnWriteHashMap<>(); } - private FieldTypeLookup( - CopyOnWriteHashMap fullName, - CopyOnWriteHashMap> fullNameToTypes) { + private FieldTypeLookup(CopyOnWriteHashMap fullName) { this.fullNameToFieldType = fullName; - this.fullNameToTypes = fullNameToTypes; - } - - private static CopyOnWriteHashMap> addType(CopyOnWriteHashMap> map, String key, String type) { - Set types = map.get(key); - if (types == null) { - return map.copyAndPut(key, Collections.singleton(type)); - } else if (types.contains(type)) { - // noting to do - return map; - } else { - Set newTypes = new HashSet<>(types.size() + 1); - newTypes.addAll(types); - newTypes.add(type); - assert newTypes.size() == types.size() + 1; - newTypes = Collections.unmodifiableSet(newTypes); - return map.copyAndPut(key, newTypes); - } } /** @@ -77,58 +52,41 @@ class FieldTypeLookup implements Iterable { * from the provided fields. If a field already exists, the field type will be updated * to use the new mappers field type. */ - public FieldTypeLookup copyAndAddAll(String type, Collection fieldMappers, boolean updateAllTypes) { + public FieldTypeLookup copyAndAddAll(String type, Collection fieldMappers) { Objects.requireNonNull(type, "type must not be null"); if (MapperService.DEFAULT_MAPPING.equals(type)) { throw new IllegalArgumentException("Default mappings should not be added to the lookup"); } CopyOnWriteHashMap fullName = this.fullNameToFieldType; - CopyOnWriteHashMap> fullNameToTypes = this.fullNameToTypes; for (FieldMapper fieldMapper : fieldMappers) { MappedFieldType fieldType = fieldMapper.fieldType(); MappedFieldType fullNameFieldType = fullName.get(fieldType.name()); - // is the update even legal? - checkCompatibility(type, fieldMapper, updateAllTypes); - - if (fieldType.equals(fullNameFieldType) == false) { + if (fullNameFieldType == null) { + // introduction of a new field fullName = fullName.copyAndPut(fieldType.name(), fieldMapper.fieldType()); + } else { + // modification of an existing field + checkCompatibility(fullNameFieldType, fieldType); + if (fieldType.equals(fullNameFieldType) == false) { + fullName = fullName.copyAndPut(fieldType.name(), fieldMapper.fieldType()); + } } - - fullNameToTypes = addType(fullNameToTypes, fieldType.name(), type); - } - return new FieldTypeLookup(fullName, fullNameToTypes); - } - - private static boolean beStrict(String type, Set types, boolean updateAllTypes) { - assert types.size() >= 1; - if (updateAllTypes) { - return false; - } else if (types.size() == 1 && types.contains(type)) { - // we are implicitly updating all types - return false; - } else { - return true; } + return new FieldTypeLookup(fullName); } /** * Checks if the given field type is compatible with an existing field type. * An IllegalArgumentException is thrown in case of incompatibility. - * If updateAllTypes is true, only basic compatibility is checked. */ - private void checkCompatibility(String type, FieldMapper fieldMapper, boolean updateAllTypes) { - MappedFieldType fieldType = fullNameToFieldType.get(fieldMapper.fieldType().name()); - if (fieldType != null) { - List conflicts = new ArrayList<>(); - final Set types = fullNameToTypes.get(fieldMapper.fieldType().name()); - boolean strict = beStrict(type, types, updateAllTypes); - fieldType.checkCompatibility(fieldMapper.fieldType(), conflicts, strict); - if (conflicts.isEmpty() == false) { - throw new IllegalArgumentException("Mapper for [" + fieldMapper.fieldType().name() + "] conflicts with existing mapping in other types:\n" + conflicts.toString()); - } + private void checkCompatibility(MappedFieldType existingFieldType, MappedFieldType newFieldType) { + List conflicts = new ArrayList<>(); + existingFieldType.checkCompatibility(newFieldType, conflicts); + if (conflicts.isEmpty() == false) { + throw new IllegalArgumentException("Mapper for [" + newFieldType.name() + "] conflicts with existing mapping:\n" + conflicts.toString()); } } @@ -137,15 +95,6 @@ class FieldTypeLookup implements Iterable { return fullNameToFieldType.get(field); } - /** Get the set of types that have a mapping for the given field. */ - public Set getTypes(String field) { - Set types = fullNameToTypes.get(field); - if (types == null) { - types = Collections.emptySet(); - } - return types; - } - /** * Returns a list of the full names of a simple match regex like pattern against full name and index name. */ diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java index 45237eb572d..7b9eb5f067a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java @@ -142,8 +142,8 @@ public class GeoPointFieldMapper extends FieldMapper implements ArrayValueMapper } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); GeoPointFieldMapper gpfmMergeWith = (GeoPointFieldMapper) mergeWith; if (gpfmMergeWith.ignoreMalformed.explicit()) { this.ignoreMalformed = gpfmMergeWith.ignoreMalformed; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java index 68d6ac66678..9e2a17817ac 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java @@ -309,8 +309,8 @@ public class GeoShapeFieldMapper extends FieldMapper { } @Override - public void checkCompatibility(MappedFieldType fieldType, List conflicts, boolean strict) { - super.checkCompatibility(fieldType, conflicts, strict); + public void checkCompatibility(MappedFieldType fieldType, List conflicts) { + super.checkCompatibility(fieldType, conflicts); GeoShapeFieldType other = (GeoShapeFieldType)fieldType; // prevent user from changing strategies if (strategyName().equals(other.strategyName()) == false) { @@ -334,15 +334,6 @@ public class GeoShapeFieldMapper extends FieldMapper { if (precisionInMeters() != other.precisionInMeters()) { conflicts.add("mapper [" + name() + "] has different [precision]"); } - - if (strict) { - if (orientation() != other.orientation()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [orientation] across all types."); - } - if (distanceErrorPct() != other.distanceErrorPct()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [distance_error_pct] across all types."); - } - } } private static int getLevels(int treeLevels, double precisionInMeters, int defaultLevels, boolean geoHash) { @@ -511,8 +502,8 @@ public class GeoShapeFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); GeoShapeFieldMapper gsfm = (GeoShapeFieldMapper)mergeWith; if (gsfm.coerce.explicit()) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java index 41256d3a5bb..e60b27fce72 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java @@ -314,7 +314,7 @@ public class IdFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { // do nothing here, no merging, but also no exception } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java index 1bdb125b4e7..8e92ecc8bf6 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java @@ -189,7 +189,7 @@ public class IndexFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { // nothing to do } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java index bc811d041e3..c10c2339b89 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java @@ -390,8 +390,8 @@ public class IpFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); IpFieldMapper other = (IpFieldMapper) mergeWith; if (other.ignoreMalformed.explicit()) { this.ignoreMalformed = other.ignoreMalformed; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java index cb2c4b6b6fd..76163929e68 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java @@ -187,8 +187,8 @@ public final class KeywordFieldMapper extends FieldMapper { } @Override - public void checkCompatibility(MappedFieldType otherFT, List conflicts, boolean strict) { - super.checkCompatibility(otherFT, conflicts, strict); + public void checkCompatibility(MappedFieldType otherFT, List conflicts) { + super.checkCompatibility(otherFT, conflicts); KeywordFieldType other = (KeywordFieldType) otherFT; if (Objects.equals(normalizer, other.normalizer) == false) { conflicts.add("mapper [" + name() + "] has different [normalizer]"); @@ -352,8 +352,8 @@ public final class KeywordFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); this.ignoreAbove = ((KeywordFieldMapper) mergeWith).ignoreAbove; } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java index 6eab9087534..69189ab1297 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java @@ -157,7 +157,7 @@ public abstract class MappedFieldType extends FieldType { * If strict is true, all properties must be equal. * Otherwise, only properties which must never change in an index are checked. */ - public void checkCompatibility(MappedFieldType other, List conflicts, boolean strict) { + public void checkCompatibility(MappedFieldType other, List conflicts) { checkTypeName(other); boolean indexed = indexOptions() != IndexOptions.NONE; @@ -202,27 +202,6 @@ public abstract class MappedFieldType extends FieldType { if (Objects.equals(similarity(), other.similarity()) == false) { conflicts.add("mapper [" + name() + "] has different [similarity]"); } - - if (strict) { - if (omitNorms() != other.omitNorms()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [omit_norms] across all types."); - } - if (boost() != other.boost()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [boost] across all types."); - } - if (Objects.equals(searchAnalyzer(), other.searchAnalyzer()) == false) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [search_analyzer] across all types."); - } - if (Objects.equals(searchQuoteAnalyzer(), other.searchQuoteAnalyzer()) == false) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [search_quote_analyzer] across all types."); - } - if (Objects.equals(nullValue(), other.nullValue()) == false) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [null_value] across all types."); - } - if (eagerGlobalOrdinals() != other.eagerGlobalOrdinals()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [eager_global_ordinals] across all types."); - } - } } public String name() { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/Mapper.java b/server/src/main/java/org/elasticsearch/index/mapper/Mapper.java index 4f78ec0ad95..051ac9da7f2 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/Mapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/Mapper.java @@ -175,7 +175,7 @@ public abstract class Mapper implements ToXContentFragment, Iterable { /** Return the merge of {@code mergeWith} into this. * Both {@code this} and {@code mergeWith} will be left unmodified. */ - public abstract Mapper merge(Mapper mergeWith, boolean updateAllTypes); + public abstract Mapper merge(Mapper mergeWith); /** * Update the field type of this mapper. This is necessary because some mapping updates diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 51ebe9d980b..a04673eca4c 100755 --- a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -215,7 +215,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { final Map updatedEntries; try { // only update entries if needed - updatedEntries = internalMerge(indexMetaData, MergeReason.MAPPING_RECOVERY, true, true); + updatedEntries = internalMerge(indexMetaData, MergeReason.MAPPING_RECOVERY, true); } catch (Exception e) { logger.warn((org.apache.logging.log4j.util.Supplier) () -> new ParameterizedMessage("[{}] failed to apply mappings", index()), e); throw e; @@ -250,7 +250,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { return requireRefresh; } - public void merge(Map> mappings, MergeReason reason, boolean updateAllTypes) { + public void merge(Map> mappings, MergeReason reason) { Map mappingSourcesCompressed = new LinkedHashMap<>(mappings.size()); for (Map.Entry> entry : mappings.entrySet()) { try { @@ -260,19 +260,18 @@ public class MapperService extends AbstractIndexComponent implements Closeable { } } - internalMerge(mappingSourcesCompressed, reason, updateAllTypes); + internalMerge(mappingSourcesCompressed, reason); } - public void merge(IndexMetaData indexMetaData, MergeReason reason, boolean updateAllTypes) { - internalMerge(indexMetaData, reason, updateAllTypes, false); + public void merge(IndexMetaData indexMetaData, MergeReason reason) { + internalMerge(indexMetaData, reason, false); } - public DocumentMapper merge(String type, CompressedXContent mappingSource, MergeReason reason, boolean updateAllTypes) { - return internalMerge(Collections.singletonMap(type, mappingSource), reason, updateAllTypes).get(type); + public DocumentMapper merge(String type, CompressedXContent mappingSource, MergeReason reason) { + return internalMerge(Collections.singletonMap(type, mappingSource), reason).get(type); } - private synchronized Map internalMerge(IndexMetaData indexMetaData, MergeReason reason, boolean updateAllTypes, - boolean onlyUpdateIfNeeded) { + private synchronized Map internalMerge(IndexMetaData indexMetaData, MergeReason reason, boolean onlyUpdateIfNeeded) { Map map = new LinkedHashMap<>(); for (ObjectCursor cursor : indexMetaData.getMappings().values()) { MappingMetaData mappingMetaData = cursor.value; @@ -285,10 +284,10 @@ public class MapperService extends AbstractIndexComponent implements Closeable { map.put(mappingMetaData.type(), mappingMetaData.source()); } } - return internalMerge(map, reason, updateAllTypes); + return internalMerge(map, reason); } - private synchronized Map internalMerge(Map mappings, MergeReason reason, boolean updateAllTypes) { + private synchronized Map internalMerge(Map mappings, MergeReason reason) { DocumentMapper defaultMapper = null; String defaultMappingSource = null; @@ -336,7 +335,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { } } - return internalMerge(defaultMapper, defaultMappingSource, documentMappers, reason, updateAllTypes); + return internalMerge(defaultMapper, defaultMappingSource, documentMappers, reason); } static void validateTypeName(String type) { @@ -361,7 +360,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { } private synchronized Map internalMerge(@Nullable DocumentMapper defaultMapper, @Nullable String defaultMappingSource, - List documentMappers, MergeReason reason, boolean updateAllTypes) { + List documentMappers, MergeReason reason) { boolean hasNested = this.hasNested; Map fullPathObjectMappers = this.fullPathObjectMappers; FieldTypeLookup fieldTypes = this.fieldTypes; @@ -392,7 +391,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { DocumentMapper oldMapper = mappers.get(mapper.type()); DocumentMapper newMapper; if (oldMapper != null) { - newMapper = oldMapper.merge(mapper.mapping(), updateAllTypes); + newMapper = oldMapper.merge(mapper.mapping()); } else { newMapper = mapper; } @@ -403,12 +402,12 @@ public class MapperService extends AbstractIndexComponent implements Closeable { Collections.addAll(fieldMappers, newMapper.mapping().metadataMappers); MapperUtils.collect(newMapper.mapping().root(), objectMappers, fieldMappers); checkFieldUniqueness(newMapper.type(), objectMappers, fieldMappers, fullPathObjectMappers, fieldTypes); - checkObjectsCompatibility(objectMappers, updateAllTypes, fullPathObjectMappers); + checkObjectsCompatibility(objectMappers, fullPathObjectMappers); checkPartitionedIndexConstraints(newMapper); // update lookup data-structures // this will in particular make sure that the merged fields are compatible with other types - fieldTypes = fieldTypes.copyAndAddAll(newMapper.type(), fieldMappers, updateAllTypes); + fieldTypes = fieldTypes.copyAndAddAll(newMapper.type(), fieldMappers); for (ObjectMapper objectMapper : objectMappers) { if (fullPathObjectMappers == this.fullPathObjectMappers) { @@ -575,14 +574,14 @@ public class MapperService extends AbstractIndexComponent implements Closeable { } } - private static void checkObjectsCompatibility(Collection objectMappers, boolean updateAllTypes, + private static void checkObjectsCompatibility(Collection objectMappers, Map fullPathObjectMappers) { for (ObjectMapper newObjectMapper : objectMappers) { ObjectMapper existingObjectMapper = fullPathObjectMappers.get(newObjectMapper.fullPath()); if (existingObjectMapper != null) { // simulate a merge and ignore the result, we are just interested // in exceptions here - existingObjectMapper.merge(newObjectMapper, updateAllTypes); + existingObjectMapper.merge(newObjectMapper); } } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/Mapping.java b/server/src/main/java/org/elasticsearch/index/mapper/Mapping.java index 8a90de4d47a..bd92cf6d009 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/Mapping.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/Mapping.java @@ -84,9 +84,9 @@ public final class Mapping implements ToXContentFragment { return (T) metadataMappersMap.get(clazz); } - /** @see DocumentMapper#merge(Mapping, boolean) */ - public Mapping merge(Mapping mergeWith, boolean updateAllTypes) { - RootObjectMapper mergedRoot = root.merge(mergeWith.root, updateAllTypes); + /** @see DocumentMapper#merge(Mapping) */ + public Mapping merge(Mapping mergeWith) { + RootObjectMapper mergedRoot = root.merge(mergeWith.root); Map, MetadataFieldMapper> mergedMetaDataMappers = new HashMap<>(metadataMappersMap); for (MetadataFieldMapper metaMergeWith : mergeWith.metadataMappers) { MetadataFieldMapper mergeInto = mergedMetaDataMappers.get(metaMergeWith.getClass()); @@ -94,7 +94,7 @@ public final class Mapping implements ToXContentFragment { if (mergeInto == null) { merged = metaMergeWith; } else { - merged = mergeInto.merge(metaMergeWith, updateAllTypes); + merged = mergeInto.merge(metaMergeWith); } mergedMetaDataMappers.put(merged.getClass(), merged); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MetadataFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/MetadataFieldMapper.java index 264c2abd568..1240250a747 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MetadataFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MetadataFieldMapper.java @@ -67,7 +67,7 @@ public abstract class MetadataFieldMapper extends FieldMapper { public abstract void postParse(ParseContext context) throws IOException; @Override - public MetadataFieldMapper merge(Mapper mergeWith, boolean updateAllTypes) { - return (MetadataFieldMapper) super.merge(mergeWith, updateAllTypes); + public MetadataFieldMapper merge(Mapper mergeWith) { + return (MetadataFieldMapper) super.merge(mergeWith); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java index a44611d6406..92cb44cfd14 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -1019,8 +1019,8 @@ public class NumberFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); NumberFieldMapper other = (NumberFieldMapper) mergeWith; if (other.ignoreMalformed.explicit()) { this.ignoreMalformed = other.ignoreMalformed; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java index d83ce173d68..c96d8bb384b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.fielddata.ScriptDocValues; import java.io.IOException; import java.util.ArrayList; @@ -139,7 +138,7 @@ public class ObjectMapper extends Mapper implements Cloneable { Mapper mapper = builder.build(context); Mapper existing = mappers.get(mapper.simpleName()); if (existing != null) { - mapper = existing.merge(mapper, false); + mapper = existing.merge(mapper); } mappers.put(mapper.simpleName(), mapper); } @@ -426,17 +425,17 @@ public class ObjectMapper extends Mapper implements Cloneable { } @Override - public ObjectMapper merge(Mapper mergeWith, boolean updateAllTypes) { + public ObjectMapper merge(Mapper mergeWith) { if (!(mergeWith instanceof ObjectMapper)) { throw new IllegalArgumentException("Can't merge a non object mapping [" + mergeWith.name() + "] with an object mapping [" + name() + "]"); } ObjectMapper mergeWithObject = (ObjectMapper) mergeWith; ObjectMapper merged = clone(); - merged.doMerge(mergeWithObject, updateAllTypes); + merged.doMerge(mergeWithObject); return merged; } - protected void doMerge(final ObjectMapper mergeWith, boolean updateAllTypes) { + protected void doMerge(final ObjectMapper mergeWith) { if (nested().isNested()) { if (!mergeWith.nested().isNested()) { throw new IllegalArgumentException("object mapping [" + name() + "] can't be changed from nested to non-nested"); @@ -459,7 +458,7 @@ public class ObjectMapper extends Mapper implements Cloneable { merged = mergeWithMapper; } else { // root mappers can only exist here for backcompat, and are merged in Mapping - merged = mergeIntoMapper.merge(mergeWithMapper, updateAllTypes); + merged = mergeIntoMapper.merge(mergeWithMapper); } putMapper(merged); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java index 34eaf569ca9..1d3588ae5a7 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java @@ -301,7 +301,7 @@ public class ParentFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { ParentFieldMapper fieldMergeWith = (ParentFieldMapper) mergeWith; if (fieldMergeWith.parentType != null && Objects.equals(parentType, fieldMergeWith.parentType) == false) { throw new IllegalArgumentException("The _parent field's type option can't be changed: [" + parentType + "]->[" + fieldMergeWith.parentType + "]"); @@ -310,7 +310,7 @@ public class ParentFieldMapper extends MetadataFieldMapper { // update that does not explicitly configure the _parent field, so we // ignore it. if (fieldMergeWith.active()) { - super.doMerge(mergeWith, updateAllTypes); + super.doMerge(mergeWith); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/ParsedDocument.java b/server/src/main/java/org/elasticsearch/index/mapper/ParsedDocument.java index 11804c2e88e..0c740a0af7c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/ParsedDocument.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/ParsedDocument.java @@ -131,7 +131,7 @@ public class ParsedDocument { if (dynamicMappingsUpdate == null) { dynamicMappingsUpdate = update; } else { - dynamicMappingsUpdate = dynamicMappingsUpdate.merge(update, false); + dynamicMappingsUpdate = dynamicMappingsUpdate.merge(update); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java index 9a00ddebe83..1536db6510f 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java @@ -256,29 +256,6 @@ public class RangeFieldMapper extends FieldMapper { return rangeType.name; } - @Override - public void checkCompatibility(MappedFieldType fieldType, List conflicts, boolean strict) { - super.checkCompatibility(fieldType, conflicts, strict); - if (strict) { - RangeFieldType other = (RangeFieldType)fieldType; - if (this.rangeType != other.rangeType) { - conflicts.add("mapper [" + name() - + "] is attempting to update from type [" + rangeType.name - + "] to incompatible type [" + other.rangeType.name + "]."); - } - if (this.rangeType == RangeType.DATE) { - if (Objects.equals(dateTimeFormatter().format(), other.dateTimeFormatter().format()) == false) { - conflicts.add("mapper [" + name() - + "] is used by multiple types. Set update_all_types to true to update [format] across all types."); - } - if (Objects.equals(dateTimeFormatter().locale(), other.dateTimeFormatter().locale()) == false) { - conflicts.add("mapper [" + name() - + "] is used by multiple types. Set update_all_types to true to update [locale] across all types."); - } - } - } - } - public FormatDateTimeFormatter dateTimeFormatter() { return dateTimeFormatter; } @@ -416,8 +393,8 @@ public class RangeFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); RangeFieldMapper other = (RangeFieldMapper) mergeWith; if (other.coerce.explicit()) { this.coerce = other.coerce; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/RootObjectMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/RootObjectMapper.java index 42341bfb96b..009caf2b8e8 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/RootObjectMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/RootObjectMapper.java @@ -268,13 +268,13 @@ public class RootObjectMapper extends ObjectMapper { } @Override - public RootObjectMapper merge(Mapper mergeWith, boolean updateAllTypes) { - return (RootObjectMapper) super.merge(mergeWith, updateAllTypes); + public RootObjectMapper merge(Mapper mergeWith) { + return (RootObjectMapper) super.merge(mergeWith); } @Override - protected void doMerge(ObjectMapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(ObjectMapper mergeWith) { + super.doMerge(mergeWith); RootObjectMapper mergeWithObject = (RootObjectMapper) mergeWith; if (mergeWithObject.numericDetection.explicit()) { this.numericDetection = mergeWithObject.numericDetection; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java index a4b009f9f1f..25cfc71261b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java @@ -201,7 +201,7 @@ public class RoutingFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { // do nothing here, no merging, but also no exception } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java index 01b302797e2..197d5557363 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java @@ -278,7 +278,7 @@ public class SeqNoFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { // nothing to do } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java index 47d5e64438e..b4a8330e238 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java @@ -291,7 +291,7 @@ public class SourceFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { SourceFieldMapper sourceMergeWith = (SourceFieldMapper) mergeWith; List conflicts = new ArrayList<>(); if (this.enabled != sourceMergeWith.enabled) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java index ae99f743fe5..4d67ec4cfbc 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -212,31 +212,6 @@ public class TextFieldMapper extends FieldMapper { fielddataMinFrequency, fielddataMaxFrequency, fielddataMinSegmentSize); } - @Override - public void checkCompatibility(MappedFieldType other, - List conflicts, boolean strict) { - super.checkCompatibility(other, conflicts, strict); - TextFieldType otherType = (TextFieldType) other; - if (strict) { - if (fielddata() != otherType.fielddata()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [fielddata] " - + "across all types."); - } - if (fielddataMinFrequency() != otherType.fielddataMinFrequency()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update " - + "[fielddata_frequency_filter.min] across all types."); - } - if (fielddataMaxFrequency() != otherType.fielddataMaxFrequency()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update " - + "[fielddata_frequency_filter.max] across all types."); - } - if (fielddataMinSegmentSize() != otherType.fielddataMinSegmentSize()) { - conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update " - + "[fielddata_frequency_filter.min_segment_size] across all types."); - } - } - } - public boolean fielddata() { return fielddata; } @@ -357,8 +332,8 @@ public class TextFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java index 712e9edec9e..b47242d02b0 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java @@ -316,7 +316,7 @@ public class TypeFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { // do nothing here, no merging, but also no exception } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/UidFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/UidFieldMapper.java index 95dc40bca63..04e791b8cee 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/UidFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/UidFieldMapper.java @@ -229,7 +229,7 @@ public class UidFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { // do nothing here, no merging, but also no exception } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/VersionFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/VersionFieldMapper.java index c5ead1327cc..bedb98e2126 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/VersionFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/VersionFieldMapper.java @@ -145,7 +145,7 @@ public class VersionFieldMapper extends MetadataFieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { // nothing to do } } diff --git a/server/src/main/java/org/elasticsearch/index/shard/StoreRecovery.java b/server/src/main/java/org/elasticsearch/index/shard/StoreRecovery.java index 81ffbea642c..c3b4525924a 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/StoreRecovery.java +++ b/server/src/main/java/org/elasticsearch/index/shard/StoreRecovery.java @@ -112,7 +112,7 @@ final class StoreRecovery { for (ObjectObjectCursor mapping : sourceMetaData.getMappings()) { mappingUpdateConsumer.accept(mapping.key, mapping.value); } - indexShard.mapperService().merge(sourceMetaData, MapperService.MergeReason.MAPPING_RECOVERY, true); + indexShard.mapperService().merge(sourceMetaData, MapperService.MergeReason.MAPPING_RECOVERY); // now that the mapping is merged we can validate the index sort configuration. Sort indexSort = indexShard.getIndexSort(); final boolean hasNested = indexShard.mapperService().hasNested(); diff --git a/server/src/main/java/org/elasticsearch/indices/IndicesService.java b/server/src/main/java/org/elasticsearch/indices/IndicesService.java index 7e0bff53841..f7c4a39eee3 100644 --- a/server/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/server/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -495,7 +495,7 @@ public class IndicesService extends AbstractLifecycleComponent final IndexService service = createIndexService("metadata verification", metaData, indicesQueryCache, indicesFieldDataCache, emptyList()); closeables.add(() -> service.close("metadata verification", false)); - service.mapperService().merge(metaData, MapperService.MergeReason.MAPPING_RECOVERY, true); + service.mapperService().merge(metaData, MapperService.MergeReason.MAPPING_RECOVERY); if (metaData.equals(metaDataUpdate) == false) { service.updateMetaData(metaDataUpdate); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java index 6a741fd3951..0934d855715 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java @@ -49,7 +49,6 @@ public class RestCreateIndexAction extends BaseRestHandler { if (request.hasContent()) { createIndexRequest.source(request.content(), request.getXContentType()); } - createIndexRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false)); createIndexRequest.timeout(request.paramAsTime("timeout", createIndexRequest.timeout())); createIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createIndexRequest.masterNodeTimeout())); createIndexRequest.waitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards"))); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java index 8d7e4a9e6c8..cdac83037db 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java @@ -70,7 +70,6 @@ public class RestPutMappingAction extends BaseRestHandler { PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index"))); putMappingRequest.type(request.param("type")); putMappingRequest.source(request.requiredContent(), request.getXContentType()); - putMappingRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false)); putMappingRequest.timeout(request.paramAsTime("timeout", putMappingRequest.timeout())); putMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putMappingRequest.masterNodeTimeout())); putMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, putMappingRequest.indicesOptions())); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java index 14d66470714..df63613b5b9 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java @@ -280,7 +280,7 @@ public class CreateIndexIT extends ESIntegTestCase { .field("type", "text") .endObject().endObject().endObject()); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> b.get()); - assertThat(e.getMessage(), containsString("mapper [text] is used by multiple types")); + assertThat(e.getMessage(), containsString("Mapper for [text] conflicts with existing mapping:")); } public void testRestartIndexCreationAfterFullClusterRestart() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexCreationTaskTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexCreationTaskTests.java index f44d0b7c403..a315cdc8206 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexCreationTaskTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexCreationTaskTests.java @@ -249,7 +249,7 @@ public class IndexCreationTaskTests extends ESTestCase { @SuppressWarnings("unchecked") public void testIndexRemovalOnFailure() throws Exception { - doThrow(new RuntimeException("oops")).when(mapper).merge(anyMap(), anyObject(), anyBoolean()); + doThrow(new RuntimeException("oops")).when(mapper).merge(anyMap(), anyObject()); expectThrows(RuntimeException.class, this::executeTask); @@ -333,7 +333,7 @@ public class IndexCreationTaskTests extends ESTestCase { @SuppressWarnings("unchecked") private Map> getMappingsFromResponse() { final ArgumentCaptor argument = ArgumentCaptor.forClass(Map.class); - verify(mapper).merge(argument.capture(), anyObject(), anyBoolean()); + verify(mapper).merge(argument.capture(), anyObject()); return argument.getValue(); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/AllFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/AllFieldMapperTests.java index 4ccc8bc215f..b33d98c9b00 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/AllFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/AllFieldMapperTests.java @@ -33,7 +33,7 @@ public class AllFieldMapperTests extends ESSingleNodeTestCase { .put("index.analysis.analyzer.default_search.type", "custom") .put("index.analysis.analyzer.default_search.tokenizer", "standard").build()); String mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc").endObject().endObject().string(); - indexService.mapperService().merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + indexService.mapperService().merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, indexService.mapperService().documentMapper("_doc").mapping().toString()); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java index e6a1c0a69d8..bb839d8e573 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java @@ -211,7 +211,7 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject() .endObject().endObject().string(); DocumentMapper mapper = indexService.mapperService() - .merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + .merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference source = XContentFactory.jsonBuilder() .startObject() diff --git a/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java index a0b6a1458e2..b4c698fa26d 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java @@ -306,11 +306,11 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endObject().endObject().endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper docMapperBefore = mapperService.merge("type1", new CompressedXContent(mappingBefore), MapperService.MergeReason.MAPPING_UPDATE, false); + DocumentMapper docMapperBefore = mapperService.merge("type1", new CompressedXContent(mappingBefore), MapperService.MergeReason.MAPPING_UPDATE); assertEquals(Arrays.asList("foo", "bar"), docMapperBefore.mappers().getMapper("copy_test").copyTo().copyToFields()); - DocumentMapper docMapperAfter = mapperService.merge("type1", new CompressedXContent(mappingAfter), MapperService.MergeReason.MAPPING_UPDATE, false); + DocumentMapper docMapperAfter = mapperService.merge("type1", new CompressedXContent(mappingAfter), MapperService.MergeReason.MAPPING_UPDATE); assertEquals(Arrays.asList("baz", "bar"), docMapperAfter.mappers().getMapper("copy_test").copyTo().copyToFields()); assertEquals(Arrays.asList("foo", "bar"), docMapperBefore.mappers().getMapper("copy_test").copyTo().copyToFields()); @@ -438,7 +438,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endObject(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("_doc", new CompressedXContent(rootToNestedMapping.bytes()), - MergeReason.MAPPING_UPDATE, false)); + MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), Matchers.startsWith("Illegal combination of [copy_to] and [nested] mappings")); XContentBuilder nestedToNestedMapping = jsonBuilder().startObject() @@ -466,7 +466,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endObject(); e = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("_doc", new CompressedXContent(nestedToNestedMapping.bytes()), - MergeReason.MAPPING_UPDATE, false)); + MergeReason.MAPPING_UPDATE)); } public void testCopyToSiblingNested() throws Exception { @@ -496,7 +496,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endObject(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("_doc", new CompressedXContent(rootToNestedMapping.bytes()), - MergeReason.MAPPING_UPDATE, false)); + MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), Matchers.startsWith("Illegal combination of [copy_to] and [nested] mappings")); } @@ -517,7 +517,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endObject(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("_doc", new CompressedXContent(rootToNestedMapping.bytes()), - MergeReason.MAPPING_UPDATE, false)); + MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), Matchers.startsWith("Cannot copy to field [target] since it is mapped as an object")); } @@ -585,7 +585,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test").mapperService(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean())); + () -> mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE)); assertEquals("[copy_to] may not be used to copy to a multi-field: [my_field.bar]", e.getMessage()); } @@ -608,7 +608,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean()); // no exception + mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); // no exception } public void testNestedCopyToMultiField() throws Exception { @@ -633,7 +633,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test").mapperService(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean())); + () -> mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE)); assertEquals("[copy_to] may not be used to copy to a multi-field: [n.my_field.bar]", e.getMessage()); } @@ -654,7 +654,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test").mapperService(); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean())); + () -> mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), Matchers.containsString("copy_to in multi fields is not allowed. Found the copy_to in field [bar] " + "which is within a multi field.")); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java index 5776e9d618e..23bcba4cda7 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java @@ -380,7 +380,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { .startObject("release_date").field("type", "date").field("format", "yyyy/MM/dd").endObject() .endObject().endObject().endObject().string(); DocumentMapper initMapper = indexService.mapperService().merge("movie", new CompressedXContent(initMapping), - MapperService.MergeReason.MAPPING_UPDATE, randomBoolean()); + MapperService.MergeReason.MAPPING_UPDATE); assertThat(initMapper.mappers().getMapper("release_date"), notNullValue()); assertFalse(initMapper.mappers().getMapper("release_date").fieldType().stored()); @@ -392,7 +392,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { Exception e = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("movie", new CompressedXContent(updateFormatMapping), - MapperService.MergeReason.MAPPING_UPDATE, randomBoolean())); + MapperService.MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), containsString("[mapper [release_date] has different [format] values]")); } @@ -408,7 +408,7 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper update = indexService.mapperService().parse("_doc", new CompressedXContent(mappingUpdate), false); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> mapper.merge(update.mapping(), randomBoolean())); + () -> mapper.merge(update.mapping())); assertEquals("mapper [date] of different type, current_type [date], merged_type [text]", e.getMessage()); } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperMergeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperMergeTests.java index 68389112bfd..b528c2119cf 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperMergeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperMergeTests.java @@ -53,7 +53,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .endObject().endObject().endObject().string(); DocumentMapper stage2 = parser.parse("person", new CompressedXContent(stage2Mapping)); - DocumentMapper merged = stage1.merge(stage2.mapping(), false); + DocumentMapper merged = stage1.merge(stage2.mapping()); // stage1 mapping should not have been modified assertThat(stage1.mappers().smartNameFieldMapper("age"), nullValue()); assertThat(stage1.mappers().smartNameFieldMapper("obj1.prop1"), nullValue()); @@ -72,7 +72,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { DocumentMapper withDynamicMapper = parser.parse("type1", new CompressedXContent(withDynamicMapping)); assertThat(withDynamicMapper.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE)); - DocumentMapper merged = mapper.merge(withDynamicMapper.mapping(), false); + DocumentMapper merged = mapper.merge(withDynamicMapper.mapping()); assertThat(merged.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE)); } @@ -88,14 +88,14 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { DocumentMapper nestedMapper = parser.parse("type1", new CompressedXContent(nestedMapping)); try { - objectMapper.merge(nestedMapper.mapping(), false); + objectMapper.merge(nestedMapper.mapping()); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("object mapping [obj] can't be changed from non-nested to nested")); } try { - nestedMapper.merge(objectMapper.mapping(), false); + nestedMapper.merge(objectMapper.mapping()); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("object mapping [obj] can't be changed from nested to non-nested")); @@ -115,7 +115,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { DocumentMapper changed = parser.parse("type", new CompressedXContent(mapping2)); assertThat(((NamedAnalyzer) existing.mappers().getMapper("field").fieldType().searchAnalyzer()).name(), equalTo("whitespace")); - DocumentMapper merged = existing.merge(changed.mapping(), false); + DocumentMapper merged = existing.merge(changed.mapping()); assertThat(((NamedAnalyzer) merged.mappers().getMapper("field").fieldType().searchAnalyzer()).name(), equalTo("keyword")); } @@ -129,8 +129,8 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .startObject("properties").startObject("field").field("type", "text").field("analyzer", "standard").endObject().endObject() .endObject().endObject().string(); - DocumentMapper existing = mapperService.merge("type", new CompressedXContent(mapping1), MapperService.MergeReason.MAPPING_UPDATE, false); - DocumentMapper merged = mapperService.merge("type", new CompressedXContent(mapping2), MapperService.MergeReason.MAPPING_UPDATE, false); + DocumentMapper existing = mapperService.merge("type", new CompressedXContent(mapping1), MapperService.MergeReason.MAPPING_UPDATE); + DocumentMapper merged = mapperService.merge("type", new CompressedXContent(mapping2), MapperService.MergeReason.MAPPING_UPDATE); assertThat(((NamedAnalyzer) existing.mappers().getMapper("field").fieldType().searchAnalyzer()).name(), equalTo("whitespace")); @@ -139,7 +139,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { public void testConcurrentMergeTest() throws Throwable { final MapperService mapperService = createIndex("test").mapperService(); - mapperService.merge("test", new CompressedXContent("{\"test\":{}}"), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("test", new CompressedXContent("{\"test\":{}}"), MapperService.MergeReason.MAPPING_UPDATE); final DocumentMapper documentMapper = mapperService.documentMapper("test"); DocumentFieldMappers dfm = documentMapper.mappers(); @@ -169,7 +169,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { Mapping update = doc.dynamicMappingsUpdate(); assert update != null; lastIntroducedFieldName.set(fieldName); - mapperService.merge("test", new CompressedXContent(update.toString()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("test", new CompressedXContent(update.toString()), MapperService.MergeReason.MAPPING_UPDATE); } } catch (Exception e) { error.set(e); @@ -213,7 +213,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .endObject() .endObject().endObject().bytes()); MapperService mapperService = createIndex("test").mapperService(); - mapperService.merge("type", mapping, MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type", mapping, MapperService.MergeReason.MAPPING_UPDATE); CompressedXContent update = new CompressedXContent(XContentFactory.jsonBuilder().startObject() .startObject("type") @@ -223,7 +223,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .endObject() .endObject() .endObject().endObject().bytes()); - DocumentMapper mapper = mapperService.merge("type", update, MapperService.MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", update, MapperService.MergeReason.MAPPING_UPDATE); assertNotNull(mapper.mappers().getMapper("foo")); assertFalse(mapper.sourceMapper().enabled()); @@ -244,7 +244,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .startObject("name").field("type", "text").endObject() .endObject().endObject().endObject().string(); DocumentMapper updatedMapper1 = parser.parse("child", new CompressedXContent(updatedMapping1)); - DocumentMapper mergedMapper1 = initMapper.merge(updatedMapper1.mapping(), false); + DocumentMapper mergedMapper1 = initMapper.merge(updatedMapper1.mapping()); assertThat(mergedMapper1.mappers().getMapper("_parent#parent"), notNullValue()); assertThat(mergedMapper1.mappers().getMapper("name"), notNullValue()); @@ -255,7 +255,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .startObject("age").field("type", "byte").endObject() .endObject().endObject().endObject().string(); DocumentMapper updatedMapper2 = parser.parse("child", new CompressedXContent(updatedMapping2)); - DocumentMapper mergedMapper2 = mergedMapper1.merge(updatedMapper2.mapping(), false); + DocumentMapper mergedMapper2 = mergedMapper1.merge(updatedMapper2.mapping()); assertThat(mergedMapper2.mappers().getMapper("_parent#parent"), notNullValue()); assertThat(mergedMapper2.mappers().getMapper("name"), notNullValue()); @@ -265,7 +265,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .startObject("_parent").field("type", "new_parent").endObject() .endObject().endObject().string(); DocumentMapper modParentMapper = parser.parse("child", new CompressedXContent(modParentMapping)); - Exception e = expectThrows(IllegalArgumentException.class, () -> initMapper.merge(modParentMapper.mapping(), false)); + Exception e = expectThrows(IllegalArgumentException.class, () -> initMapper.merge(modParentMapper.mapping())); assertThat(e.getMessage(), containsString("The _parent field's type option can't be changed: [parent]->[new_parent]")); } @@ -286,7 +286,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .startObject("age").field("type", "byte").endObject() .endObject().endObject().endObject().string(); DocumentMapper updatedMapper = parser.parse("cowboy", new CompressedXContent(updatedMapping)); - Exception e = expectThrows(IllegalArgumentException.class, () -> initMapper.merge(updatedMapper.mapping(), false)); + Exception e = expectThrows(IllegalArgumentException.class, () -> initMapper.merge(updatedMapper.mapping())); assertThat(e.getMessage(), containsString("The _parent field's type option can't be changed: [null]->[parent]")); } @@ -317,7 +317,7 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .string(); DocumentMapper updatedMapper = parser.parse("test", new CompressedXContent(updateMapping)); - assertThat(initMapper.merge(updatedMapper.mapping(), true).meta().get("foo"), equalTo("bar")); + assertThat(initMapper.merge(updatedMapper.mapping()).meta().get("foo"), equalTo("bar")); updateMapping = XContentFactory.jsonBuilder() .startObject() @@ -330,6 +330,6 @@ public class DocumentMapperMergeTests extends ESSingleNodeTestCase { .string(); updatedMapper = parser.parse("test", new CompressedXContent(updateMapping)); - assertThat(initMapper.merge(updatedMapper.mapping(), true).meta().get("foo"), equalTo("new_bar")); + assertThat(initMapper.merge(updatedMapper.mapping()).meta().get("foo"), equalTo("new_bar")); } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java index b227833f344..fd61afc566e 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java @@ -552,7 +552,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .endArray() .endObject().endObject(); indexService.mapperService().merge("_doc", new CompressedXContent(mappings1.bytes()), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); XContentBuilder json = XContentFactory.jsonBuilder().startObject() .field("field", "foo") @@ -564,7 +564,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { assertNotNull(parsed.dynamicMappingsUpdate()); indexService.mapperService().merge("_doc", new CompressedXContent(parsed.dynamicMappingsUpdate().toString()), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); mapper = indexService.mapperService().documentMapper("_doc"); assertNotNull(mapper.mappers().getMapper("field.raw")); parsed = mapper.parse(source); @@ -591,7 +591,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .endObject() .endArray() .endObject().endObject(); - indexService.mapperService().merge("type1", new CompressedXContent(mappings1.bytes()), MapperService.MergeReason.MAPPING_UPDATE, false); + indexService.mapperService().merge("type1", new CompressedXContent(mappings1.bytes()), MapperService.MergeReason.MAPPING_UPDATE); XContentBuilder mappings2 = jsonBuilder().startObject() .startObject("type2") .startObject("properties") @@ -600,7 +600,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .endObject() .endObject() .endObject().endObject(); - indexService.mapperService().merge("type2", new CompressedXContent(mappings2.bytes()), MapperService.MergeReason.MAPPING_UPDATE, false); + indexService.mapperService().merge("type2", new CompressedXContent(mappings2.bytes()), MapperService.MergeReason.MAPPING_UPDATE); XContentBuilder json = XContentFactory.jsonBuilder().startObject() .field("field", "foo") @@ -611,7 +611,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { ParsedDocument parsed = mapper.parse(source); assertNotNull(parsed.dynamicMappingsUpdate()); - indexService.mapperService().merge("type1", new CompressedXContent(parsed.dynamicMappingsUpdate().toString()), MapperService.MergeReason.MAPPING_UPDATE, false); + indexService.mapperService().merge("type1", new CompressedXContent(parsed.dynamicMappingsUpdate().toString()), MapperService.MergeReason.MAPPING_UPDATE); mapper = indexService.mapperService().documentMapper("type1"); assertNotNull(mapper.mappers().getMapper("field.raw")); parsed = mapper.parse(source); @@ -624,7 +624,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .startObject("type") .field("numeric_detection", true) .endObject().endObject().string(); - mapperService.merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); DocumentMapper mapper = mapperService.documentMapper("type"); doTestDefaultFloatingPointMappings(mapper, XContentFactory.jsonBuilder()); doTestDefaultFloatingPointMappings(mapper, XContentFactory.yamlBuilder()); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java index 67c8435520a..8c2e6d47541 100755 --- a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java @@ -199,7 +199,7 @@ public class ExternalMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { + protected void doMerge(Mapper mergeWith) { // ignore this for now } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java b/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java index 464b0d9f840..efb2023ee69 100755 --- a/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java @@ -156,8 +156,8 @@ public class FakeStringFieldMapper extends FieldMapper { } @Override - protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - super.doMerge(mergeWith, updateAllTypes); + protected void doMerge(Mapper mergeWith) { + super.doMerge(mergeWith); } @Override diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java index 3655f04fcbb..f0753537366 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java @@ -137,11 +137,11 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapperEnabled = mapperService.merge("type", new CompressedXContent(enabledMapping), MapperService.MergeReason.MAPPING_UPDATE, false); - DocumentMapper mapperDisabled = mapperService.merge("type", new CompressedXContent(disabledMapping), MapperService.MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapperEnabled = mapperService.merge("type", new CompressedXContent(enabledMapping), MapperService.MergeReason.MAPPING_UPDATE); + DocumentMapper mapperDisabled = mapperService.merge("type", new CompressedXContent(disabledMapping), MapperService.MergeReason.MAPPING_UPDATE); assertFalse(mapperDisabled.metadataMapper(FieldNamesFieldMapper.class).fieldType().isEnabled()); - mapperEnabled = mapperService.merge("type", new CompressedXContent(enabledMapping), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperEnabled = mapperService.merge("type", new CompressedXContent(enabledMapping), MapperService.MergeReason.MAPPING_UPDATE); assertTrue(mapperEnabled.metadataMapper(FieldNamesFieldMapper.class).fieldType().isEnabled()); } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java b/server/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java index fe885a46b87..39753548ee3 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java @@ -39,7 +39,6 @@ public class FieldTypeLookupTests extends ESTestCase { public void testEmpty() { FieldTypeLookup lookup = new FieldTypeLookup(); assertNull(lookup.get("foo")); - assertEquals(Collections.emptySet(), lookup.getTypes("foo")); Collection names = lookup.simpleMatchToFullName("foo"); assertNotNull(names); assertTrue(names.isEmpty()); @@ -51,7 +50,7 @@ public class FieldTypeLookupTests extends ESTestCase { public void testDefaultMapping() { FieldTypeLookup lookup = new FieldTypeLookup(); try { - lookup.copyAndAddAll(MapperService.DEFAULT_MAPPING, Collections.emptyList(), randomBoolean()); + lookup.copyAndAddAll(MapperService.DEFAULT_MAPPING, Collections.emptyList()); fail(); } catch (IllegalArgumentException expected) { assertEquals("Default mappings should not be added to the lookup", expected.getMessage()); @@ -61,15 +60,11 @@ public class FieldTypeLookupTests extends ESTestCase { public void testAddNewField() { FieldTypeLookup lookup = new FieldTypeLookup(); MockFieldMapper f = new MockFieldMapper("foo"); - FieldTypeLookup lookup2 = lookup.copyAndAddAll("type", newList(f), randomBoolean()); + FieldTypeLookup lookup2 = lookup.copyAndAddAll("type", newList(f)); assertNull(lookup.get("foo")); assertNull(lookup.get("bar")); assertEquals(f.fieldType(), lookup2.get("foo")); assertNull(lookup.get("bar")); - assertEquals(Collections.emptySet(), lookup.getTypes("foo")); - assertEquals(Collections.emptySet(), lookup.getTypes("bar")); - assertEquals(Collections.singleton("type"), lookup2.getTypes("foo")); - assertEquals(Collections.emptySet(), lookup2.getTypes("bar")); assertEquals(1, size(lookup2.iterator())); } @@ -77,8 +72,8 @@ public class FieldTypeLookupTests extends ESTestCase { MockFieldMapper f = new MockFieldMapper("foo"); MockFieldMapper f2 = new MockFieldMapper("foo"); FieldTypeLookup lookup = new FieldTypeLookup(); - lookup = lookup.copyAndAddAll("type1", newList(f), true); - FieldTypeLookup lookup2 = lookup.copyAndAddAll("type2", newList(f2), true); + lookup = lookup.copyAndAddAll("type1", newList(f)); + FieldTypeLookup lookup2 = lookup.copyAndAddAll("type2", newList(f2)); assertEquals(1, size(lookup2.iterator())); assertSame(f.fieldType(), lookup2.get("foo")); @@ -89,8 +84,8 @@ public class FieldTypeLookupTests extends ESTestCase { MockFieldMapper f = new MockFieldMapper("foo"); MockFieldMapper f2 = new MockFieldMapper("bar"); FieldTypeLookup lookup = new FieldTypeLookup(); - lookup = lookup.copyAndAddAll("type1", newList(f), randomBoolean()); - FieldTypeLookup lookup2 = lookup.copyAndAddAll("type2", newList(f2), randomBoolean()); + lookup = lookup.copyAndAddAll("type1", newList(f)); + FieldTypeLookup lookup2 = lookup.copyAndAddAll("type2", newList(f2)); assertSame(f.fieldType(), lookup2.get("foo")); assertSame(f2.fieldType(), lookup2.get("bar")); @@ -102,7 +97,7 @@ public class FieldTypeLookupTests extends ESTestCase { MockFieldMapper f2 = new MockFieldMapper("foo"); FieldTypeLookup lookup = new FieldTypeLookup(); try { - lookup.copyAndAddAll("type2", newList(f2), randomBoolean()); + lookup.copyAndAddAll("type2", newList(f2)); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("mapper [foo] has different [index_name]")); } @@ -111,20 +106,13 @@ public class FieldTypeLookupTests extends ESTestCase { public void testCheckCompatibilityMismatchedTypes() { FieldMapper f1 = new MockFieldMapper("foo"); FieldTypeLookup lookup = new FieldTypeLookup(); - lookup = lookup.copyAndAddAll("type", newList(f1), randomBoolean()); + lookup = lookup.copyAndAddAll("type", newList(f1)); OtherFakeFieldType ft2 = new OtherFakeFieldType(); ft2.setName("foo"); FieldMapper f2 = new MockFieldMapper("foo", ft2); try { - lookup.copyAndAddAll("type2", newList(f2), false); - fail("expected type mismatch"); - } catch (IllegalArgumentException e) { - assertTrue(e.getMessage().contains("cannot be changed from type [faketype] to [otherfaketype]")); - } - // fails even if updateAllTypes == true - try { - lookup.copyAndAddAll("type2", newList(f2), true); + lookup.copyAndAddAll("type2", newList(f2)); fail("expected type mismatch"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("cannot be changed from type [faketype] to [otherfaketype]")); @@ -134,35 +122,21 @@ public class FieldTypeLookupTests extends ESTestCase { public void testCheckCompatibilityConflict() { FieldMapper f1 = new MockFieldMapper("foo"); FieldTypeLookup lookup = new FieldTypeLookup(); - lookup = lookup.copyAndAddAll("type", newList(f1), randomBoolean()); + lookup = lookup.copyAndAddAll("type", newList(f1)); MappedFieldType ft2 = new MockFieldMapper.FakeFieldType(); ft2.setName("foo"); ft2.setBoost(2.0f); FieldMapper f2 = new MockFieldMapper("foo", ft2); - try { - // different type - lookup.copyAndAddAll("type2", newList(f2), false); - fail("expected conflict"); - } catch (IllegalArgumentException e) { - assertTrue(e.getMessage().contains("to update [boost] across all types")); - } - lookup.copyAndAddAll("type", newList(f2), false); // boost is updateable, so ok since we are implicitly updating all types - lookup.copyAndAddAll("type2", newList(f2), true); // boost is updateable, so ok if forcing + lookup.copyAndAddAll("type", newList(f2)); // boost is updateable, so ok since we are implicitly updating all types + lookup.copyAndAddAll("type2", newList(f2)); // boost is updateable, so ok if forcing // now with a non changeable setting MappedFieldType ft3 = new MockFieldMapper.FakeFieldType(); ft3.setName("foo"); ft3.setStored(true); FieldMapper f3 = new MockFieldMapper("foo", ft3); try { - lookup.copyAndAddAll("type2", newList(f3), false); - fail("expected conflict"); - } catch (IllegalArgumentException e) { - assertTrue(e.getMessage().contains("has different [store] values")); - } - // even with updateAllTypes == true, incompatible - try { - lookup.copyAndAddAll("type2", newList(f3), true); + lookup.copyAndAddAll("type2", newList(f3)); fail("expected conflict"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("has different [store] values")); @@ -173,7 +147,7 @@ public class FieldTypeLookupTests extends ESTestCase { MockFieldMapper f1 = new MockFieldMapper("foo"); MockFieldMapper f2 = new MockFieldMapper("bar"); FieldTypeLookup lookup = new FieldTypeLookup(); - lookup = lookup.copyAndAddAll("type", newList(f1, f2), randomBoolean()); + lookup = lookup.copyAndAddAll("type", newList(f1, f2)); Collection names = lookup.simpleMatchToFullName("b*"); assertFalse(names.contains("foo")); assertTrue(names.contains("bar")); @@ -182,7 +156,7 @@ public class FieldTypeLookupTests extends ESTestCase { public void testIteratorImmutable() { MockFieldMapper f1 = new MockFieldMapper("foo"); FieldTypeLookup lookup = new FieldTypeLookup(); - lookup = lookup.copyAndAddAll("type", newList(f1), randomBoolean()); + lookup = lookup.copyAndAddAll("type", newList(f1)); try { Iterator itr = lookup.iterator(); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/GeoShapeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/GeoShapeFieldMapperTests.java index e43cfbe1fd1..a9a830a4141 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/GeoShapeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/GeoShapeFieldMapperTests.java @@ -417,13 +417,13 @@ public class GeoShapeFieldMapperTests extends ESSingleNodeTestCase { .field("precision", "1m").field("tree_levels", 8).field("distance_error_pct", 0.01).field("orientation", "ccw") .endObject().endObject().endObject().endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper docMapper = mapperService.merge("type", new CompressedXContent(stage1Mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + DocumentMapper docMapper = mapperService.merge("type", new CompressedXContent(stage1Mapping), MapperService.MergeReason.MAPPING_UPDATE); String stage2Mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("shape").field("type", "geo_shape").field("tree", "quadtree") .field("strategy", "term").field("precision", "1km").field("tree_levels", 26).field("distance_error_pct", 26) .field("orientation", "cw").endObject().endObject().endObject().endObject().string(); try { - mapperService.merge("type", new CompressedXContent(stage2Mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type", new CompressedXContent(stage2Mapping), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("mapper [shape] has different [strategy]")); @@ -449,7 +449,7 @@ public class GeoShapeFieldMapperTests extends ESSingleNodeTestCase { stage2Mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("shape").field("type", "geo_shape").field("precision", "1m") .field("tree_levels", 8).field("distance_error_pct", 0.001).field("orientation", "cw").endObject().endObject().endObject().endObject().string(); - docMapper = mapperService.merge("type", new CompressedXContent(stage2Mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + docMapper = mapperService.merge("type", new CompressedXContent(stage2Mapping), MapperService.MergeReason.MAPPING_UPDATE); fieldMapper = docMapper.mappers().getMapper("shape"); assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class)); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java index ec07c4d92be..111389336f2 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java @@ -62,7 +62,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase { .put("index.version.created", Version.V_5_6_0) .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); assertEquals(Collections.emptyList(), Arrays.asList(document.rootDoc().getFields(IdFieldMapper.NAME))); } @@ -70,7 +70,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase { public void testDefaultsSingleType() throws IOException { Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); IndexableField[] fields = document.rootDoc().getFields(IdFieldMapper.NAME); assertEquals(1, fields.length); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java index c17df90b5a2..49034a0b287 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java @@ -40,7 +40,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping1.json"); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + DocumentMapper docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name").fieldType().indexOptions()); assertThat(docMapper.mappers().getMapper("name.indexed"), nullValue()); @@ -53,7 +53,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { assertThat(f, nullValue()); mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping2.json"); - docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name").fieldType().indexOptions()); @@ -70,7 +70,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { assertThat(f, notNullValue()); mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping3.json"); - docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name").fieldType().indexOptions()); @@ -81,7 +81,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { assertThat(docMapper.mappers().getMapper("name.not_indexed3"), nullValue()); mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping4.json"); - docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name").fieldType().indexOptions()); @@ -96,7 +96,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping1.json"); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + DocumentMapper docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name").fieldType().indexOptions()); assertThat(docMapper.mappers().getMapper("name.indexed"), nullValue()); @@ -110,7 +110,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/upgrade1.json"); - docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name").fieldType().indexOptions()); @@ -127,7 +127,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { assertThat(f, notNullValue()); mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/upgrade2.json"); - docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + docMapper = mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name").fieldType().indexOptions()); @@ -140,7 +140,7 @@ public class JavaMultiFieldMergeTests extends ESSingleNodeTestCase { mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/upgrade3.json"); try { - mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("mapper [name] has different [index] values")); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java index e67b25b051b..aa663ed5699 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java @@ -358,7 +358,7 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { .startObject("properties").startObject("field") .field("type", "keyword").field("normalizer", "my_lowercase").endObject().endObject() .endObject().endObject().string(); - indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean()); + indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") @@ -366,9 +366,9 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("type", - new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, randomBoolean())); + new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE)); assertEquals( - "Mapper for [field] conflicts with existing mapping in other types:\n[mapper [field] has different [normalizer]]", + "Mapper for [field] conflicts with existing mapping:\n[mapper [field] has different [normalizer]]", e.getMessage()); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java b/server/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java index 95183cc854a..6d7665d8895 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java @@ -89,15 +89,15 @@ public class MapperServiceTests extends ESSingleNodeTestCase { MapperService mapperService = indexService1.mapperService(); assertEquals(Collections.emptySet(), mapperService.types()); - mapperService.merge("type1", new CompressedXContent("{\"type1\":{}}"), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type1", new CompressedXContent("{\"type1\":{}}"), MapperService.MergeReason.MAPPING_UPDATE); assertNull(mapperService.documentMapper(MapperService.DEFAULT_MAPPING)); assertEquals(Collections.singleton("type1"), mapperService.types()); - mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent("{\"_default_\":{}}"), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent("{\"_default_\":{}}"), MapperService.MergeReason.MAPPING_UPDATE); assertNotNull(mapperService.documentMapper(MapperService.DEFAULT_MAPPING)); assertEquals(Collections.singleton("type1"), mapperService.types()); - mapperService.merge("type2", new CompressedXContent("{\"type2\":{}}"), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type2", new CompressedXContent("{\"type2\":{}}"), MapperService.MergeReason.MAPPING_UPDATE); assertNotNull(mapperService.documentMapper(MapperService.DEFAULT_MAPPING)); assertEquals(new HashSet<>(Arrays.asList("type1", "type2")), mapperService.types()); } @@ -148,11 +148,11 @@ public class MapperServiceTests extends ESSingleNodeTestCase { throw new UncheckedIOException(e); } }; - createIndex("test1").mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false); + createIndex("test1").mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE); //set total number of fields to 1 to trigger an exception IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> { createIndex("test2", Settings.builder().put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), 1).build()) - .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false); + .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE); }); assertTrue(e.getMessage(), e.getMessage().contains("Limit of total fields [1] in index [test2] has been exceeded")); } @@ -166,7 +166,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase { .endObject().endObject().bytes()); IndexService indexService1 = createIndex("test1", Settings.builder().put(MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING.getKey(), 1).build()); // no exception - indexService1.mapperService().merge("type", simpleMapping, MergeReason.MAPPING_UPDATE, false); + indexService1.mapperService().merge("type", simpleMapping, MergeReason.MAPPING_UPDATE); CompressedXContent objectMapping = new CompressedXContent(XContentFactory.jsonBuilder().startObject() .startObject("properties") @@ -177,10 +177,10 @@ public class MapperServiceTests extends ESSingleNodeTestCase { IndexService indexService2 = createIndex("test2"); // no exception - indexService2.mapperService().merge("type", objectMapping, MergeReason.MAPPING_UPDATE, false); + indexService2.mapperService().merge("type", objectMapping, MergeReason.MAPPING_UPDATE); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> indexService1.mapperService().merge("type2", objectMapping, MergeReason.MAPPING_UPDATE, false)); + () -> indexService1.mapperService().merge("type2", objectMapping, MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), containsString("Limit of mapping depth [1] in index [test1] has been exceeded")); } @@ -200,14 +200,14 @@ public class MapperServiceTests extends ESSingleNodeTestCase { mappings.put(MapperService.DEFAULT_MAPPING, MapperService.parseMapping(xContentRegistry(), "{}")); MapperException e = expectThrows(MapperParsingException.class, - () -> mapperService.merge(mappings, MergeReason.MAPPING_UPDATE, false)); + () -> mapperService.merge(mappings, MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), startsWith("Failed to parse mapping [" + MapperService.DEFAULT_MAPPING + "]: ")); mappings.clear(); mappings.put("type1", MapperService.parseMapping(xContentRegistry(), "{}")); e = expectThrows( MapperParsingException.class, - () -> mapperService.merge(mappings, MergeReason.MAPPING_UPDATE, false)); + () -> mapperService.merge(mappings, MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), startsWith("Failed to parse mapping [type1]: ")); } @@ -223,7 +223,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase { Set parentTypes = mapperService.getParentTypes(); Map> mappings = new HashMap<>(); - mapperService.merge(mappings, MergeReason.MAPPING_UPDATE, false); + mapperService.merge(mappings, MergeReason.MAPPING_UPDATE); assertSame(parentTypes, mapperService.getParentTypes()); } @@ -238,10 +238,10 @@ public class MapperServiceTests extends ESSingleNodeTestCase { .endObject() .endObject().endObject().bytes()); - indexService.mapperService().merge("type1", simpleMapping, MergeReason.MAPPING_UPDATE, true); + indexService.mapperService().merge("type1", simpleMapping, MergeReason.MAPPING_UPDATE); DocumentMapper documentMapper = indexService.mapperService().documentMapper("type1"); - indexService.mapperService().merge("type2", simpleMapping, MergeReason.MAPPING_UPDATE, true); + indexService.mapperService().merge("type2", simpleMapping, MergeReason.MAPPING_UPDATE); assertSame(indexService.mapperService().documentMapper("type1"), documentMapper); CompressedXContent normsDisabledMapping = new CompressedXContent(XContentFactory.jsonBuilder().startObject() @@ -252,7 +252,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase { .endObject() .endObject().endObject().bytes()); - indexService.mapperService().merge("type3", normsDisabledMapping, MergeReason.MAPPING_UPDATE, true); + indexService.mapperService().merge("type3", normsDisabledMapping, MergeReason.MAPPING_UPDATE); assertNotSame(indexService.mapperService().documentMapper("type1"), documentMapper); } @@ -307,7 +307,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase { .endObject().endObject().bytes()); invalidNestedException = expectThrows(IllegalArgumentException.class, () -> indexService.mapperService().merge("t", nestedFieldMapping, - MergeReason.MAPPING_UPDATE, true)); + MergeReason.MAPPING_UPDATE)); assertThat(invalidNestedException.getMessage(), containsString("cannot have nested fields when index sort is activated")); } @@ -315,18 +315,18 @@ public class MapperServiceTests extends ESSingleNodeTestCase { public void testForbidMultipleTypes() throws IOException { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean()); + mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type2").endObject().endObject().string(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> mapperService.merge("type2", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, randomBoolean())); + () -> mapperService.merge("type2", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), Matchers.startsWith("Rejecting mapping update to [test] as the final mapping would have more than 1 type: ")); } public void testDefaultMappingIsDeprecated() throws IOException { String mapping = XContentFactory.jsonBuilder().startObject().startObject("_default_").endObject().endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - mapperService.merge("_default_", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean()); + mapperService.merge("_default_", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertWarnings("[_default_] mapping is deprecated since it is not useful anymore now that indexes " + "cannot have more than one type"); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java index 8da4b302a6f..bbcad5b7203 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java @@ -444,23 +444,23 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { }; // default limit allows at least two nested fields - createIndex("test1").mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false); + createIndex("test1").mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE); // explicitly setting limit to 0 prevents nested fields Exception e = expectThrows(IllegalArgumentException.class, () -> createIndex("test2", Settings.builder().put(MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING.getKey(), 0).build()) - .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false)); + .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), containsString("Limit of nested fields [0] in index [test2] has been exceeded")); // setting limit to 1 with 2 nested fields fails e = expectThrows(IllegalArgumentException.class, () -> createIndex("test3", Settings.builder().put(MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING.getKey(), 1).build()) - .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false)); + .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), containsString("Limit of nested fields [1] in index [test3] has been exceeded")); // do not check nested fields limit if mapping is not updated createIndex("test4", Settings.builder().put(MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING.getKey(), 0).build()) - .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_RECOVERY, false); + .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_RECOVERY); } public void testLimitOfNestedFieldsWithMultiTypePerIndex() throws Exception { @@ -479,19 +479,19 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test4", Settings.builder() .put("index.version.created", Version.V_5_6_0) .put(MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING.getKey(), 2).build()).mapperService(); - mapperService.merge("type1", new CompressedXContent(mapping.apply("type1")), MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type1", new CompressedXContent(mapping.apply("type1")), MergeReason.MAPPING_UPDATE); // merging same fields, but different type is ok - mapperService.merge("type2", new CompressedXContent(mapping.apply("type2")), MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type2", new CompressedXContent(mapping.apply("type2")), MergeReason.MAPPING_UPDATE); // adding new fields from different type is not ok String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type3").startObject("properties").startObject("nested3") .field("type", "nested").startObject("properties").endObject().endObject().endObject().endObject().endObject().string(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> - mapperService.merge("type3", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, false)); + mapperService.merge("type3", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), containsString("Limit of nested fields [2] in index [test4] has been exceeded")); // do not check nested fields limit if mapping is not updated createIndex("test5", Settings.builder().put(MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING.getKey(), 0).build()) - .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_RECOVERY, false); + .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_RECOVERY); } public void testParentObjectMapperAreNested() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java index bba2007285b..ea8f63345a1 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java @@ -181,13 +181,13 @@ public class ObjectMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertNull(mapper.root().dynamic()); String update = XContentFactory.jsonBuilder().startObject() .startObject("type") .field("dynamic", "strict") .endObject().endObject().string(); - mapper = mapperService.merge("type", new CompressedXContent(update), MergeReason.MAPPING_UPDATE, false); + mapper = mapperService.merge("type", new CompressedXContent(update), MergeReason.MAPPING_UPDATE); assertEquals(Dynamic.STRICT, mapper.root().dynamic()); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java index d21827ee18c..dee554449bc 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java @@ -78,8 +78,8 @@ public class ParentFieldMapperTests extends ESSingleNodeTestCase { .startObject("_parent").field("type", "parent_type").endObject() .endObject().endObject().string(); IndexService indexService = createIndex("test", Settings.builder().put("index.version.created", Version.V_5_6_0).build()); - indexService.mapperService().merge("parent_type", new CompressedXContent(parentMapping), MergeReason.MAPPING_UPDATE, false); - indexService.mapperService().merge("child_type", new CompressedXContent(childMapping), MergeReason.MAPPING_UPDATE, false); + indexService.mapperService().merge("parent_type", new CompressedXContent(parentMapping), MergeReason.MAPPING_UPDATE); + indexService.mapperService().merge("child_type", new CompressedXContent(childMapping), MergeReason.MAPPING_UPDATE); // Indexing parent doc: DocumentMapper parentDocMapper = indexService.mapperService().documentMapper("parent_type"); @@ -121,7 +121,7 @@ public class ParentFieldMapperTests extends ESSingleNodeTestCase { .startObject("properties") .endObject() .endObject().endObject(); - mapperService.merge("some_type", new CompressedXContent(mappingSource.string()), MergeReason.MAPPING_UPDATE, false); + mapperService.merge("some_type", new CompressedXContent(mappingSource.string()), MergeReason.MAPPING_UPDATE); Set allFields = new HashSet<>(mapperService.simpleMatchToIndexNames("*")); assertTrue(allFields.contains("_parent")); assertFalse(allFields.contains("_parent#null")); @@ -146,15 +146,15 @@ public class ParentFieldMapperTests extends ESSingleNodeTestCase { .startObject("_parent").field("type", "parent_type").endObject() .endObject().endObject().string(); IndexService indexService = createIndex("test", Settings.builder().put("index.version.created", Version.V_5_6_0).build()); - indexService.mapperService().merge("parent_type", new CompressedXContent(parentMapping), MergeReason.MAPPING_UPDATE, false); - indexService.mapperService().merge("child_type", new CompressedXContent(childMapping), MergeReason.MAPPING_UPDATE, false); + indexService.mapperService().merge("parent_type", new CompressedXContent(parentMapping), MergeReason.MAPPING_UPDATE); + indexService.mapperService().merge("child_type", new CompressedXContent(childMapping), MergeReason.MAPPING_UPDATE); assertTrue(indexService.mapperService().documentMapper("child_type").parentFieldMapper().fieldType().eagerGlobalOrdinals()); String childMappingUpdate = XContentFactory.jsonBuilder().startObject().startObject("child_type") .startObject("_parent").field("type", "parent_type").field("eager_global_ordinals", false).endObject() .endObject().endObject().string(); - indexService.mapperService().merge("child_type", new CompressedXContent(childMappingUpdate), MergeReason.MAPPING_UPDATE, false); + indexService.mapperService().merge("child_type", new CompressedXContent(childMappingUpdate), MergeReason.MAPPING_UPDATE); assertFalse(indexService.mapperService().documentMapper("child_type").parentFieldMapper().fieldType().eagerGlobalOrdinals()); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java index 72195fbd954..c93d968b448 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java @@ -61,7 +61,7 @@ public class RangeFieldQueryStringQueryBuilderTests extends AbstractQueryTestCas DOUBLE_RANGE_FIELD_NAME, "type=double_range", DATE_RANGE_FIELD_NAME, "type=date_range", IP_RANGE_FIELD_NAME, "type=ip_range" - ).string()), MapperService.MergeReason.MAPPING_UPDATE, false); + ).string()), MapperService.MergeReason.MAPPING_UPDATE); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java index a76d5d01316..d55b90573e9 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java @@ -36,7 +36,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); // update with a different explicit value @@ -46,7 +46,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .field("numeric_detection", true) .endObject() .endObject().string(); - mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, false); + mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); assertEquals(mapping2, mapper.mappingSource().toString()); // update with an implicit value: no change @@ -55,7 +55,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .startObject("type") .endObject() .endObject().string(); - mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE, false); + mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); assertEquals(mapping2, mapper.mappingSource().toString()); } @@ -67,7 +67,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); // update with a different explicit value @@ -77,7 +77,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .field("date_detection", false) .endObject() .endObject().string(); - mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, false); + mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); assertEquals(mapping2, mapper.mappingSource().toString()); // update with an implicit value: no change @@ -86,7 +86,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .startObject("type") .endObject() .endObject().string(); - mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE, false); + mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); assertEquals(mapping2, mapper.mappingSource().toString()); } @@ -98,7 +98,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); // no update if formatters are not set explicitly @@ -107,7 +107,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .startObject("type") .endObject() .endObject().string(); - mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, false); + mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); String mapping3 = XContentFactory.jsonBuilder() @@ -116,7 +116,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .field("dynamic_date_formats", Arrays.asList()) .endObject() .endObject().string(); - mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE, false); + mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); assertEquals(mapping3, mapper.mappingSource().toString()); } @@ -137,7 +137,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .endObject() .endObject().string(); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); // no update if templates are not set explicitly @@ -146,7 +146,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .startObject("type") .endObject() .endObject().string(); - mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, false); + mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); String mapping3 = XContentFactory.jsonBuilder() @@ -155,7 +155,7 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { .field("dynamic_templates", Arrays.asList()) .endObject() .endObject().string(); - mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE, false); + mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); assertEquals(mapping3, mapper.mappingSource().toString()); } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java index 85017cb35cd..f40229e9ebe 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java @@ -164,7 +164,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase { Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0).build(); MapperService mapperService = createIndex("test", settings).mapperService(); - mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent(defaultMapping), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent(defaultMapping), MapperService.MergeReason.MAPPING_UPDATE); DocumentMapper mapper = mapperService.documentMapperWithAutoCreate("my_type").getDocumentMapper(); assertThat(mapper.type(), equalTo("my_type")); @@ -178,12 +178,12 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase { Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0).build(); MapperService mapperService = createIndex("test", settings).mapperService(); - mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent(defaultMapping), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent(defaultMapping), MapperService.MergeReason.MAPPING_UPDATE); String mapping = XContentFactory.jsonBuilder().startObject().startObject("my_type") .startObject("_source").field("enabled", true).endObject() .endObject().endObject().string(); - mapperService.merge("my_type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("my_type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); DocumentMapper mapper = mapperService.documentMapper("my_type"); assertThat(mapper.type(), equalTo("my_type")); @@ -194,10 +194,10 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase { DocumentMapper docMapper = parser.parse("type", new CompressedXContent(mapping1)); docMapper = parser.parse("type", docMapper.mappingSource()); if (conflicts.length == 0) { - docMapper.merge(parser.parse("type", new CompressedXContent(mapping2)).mapping(), false); + docMapper.merge(parser.parse("type", new CompressedXContent(mapping2)).mapping()); } else { try { - docMapper.merge(parser.parse("type", new CompressedXContent(mapping2)).mapping(), false); + docMapper.merge(parser.parse("type", new CompressedXContent(mapping2)).mapping()); fail(); } catch (IllegalArgumentException e) { for (String conflict : conflicts) { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java b/server/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java index 438ccd5fa86..2ff2bda01df 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java @@ -62,7 +62,7 @@ public class StoredNumericValuesTests extends ESSingleNodeTestCase { .endObject() .string(); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder() .startObject() diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java index 3f0f4a87792..f5b83d1bd6e 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java @@ -205,7 +205,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); DocumentMapper mapper = indexService.mapperService().merge("type", - new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); @@ -247,7 +247,7 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { .endObject().endObject().string(); DocumentMapper mapper = indexService.mapperService().merge("type", - new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java index d941b5a0469..4687a3a24ef 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java @@ -66,7 +66,7 @@ public class TypeFieldMapperTests extends ESSingleNodeTestCase { .put("index.version.created", Version.V_5_6_0) .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); Directory dir = newDirectory(); @@ -93,7 +93,7 @@ public class TypeFieldMapperTests extends ESSingleNodeTestCase { .put("index.version.created", Version.V_5_6_0) .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); IndexableField[] fields = document.rootDoc().getFields(TypeFieldMapper.NAME); assertEquals(IndexOptions.DOCS, fields[0].fieldType().indexOptions()); @@ -103,7 +103,7 @@ public class TypeFieldMapperTests extends ESSingleNodeTestCase { public void testDefaultsSingleType() throws IOException { Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); assertEquals(Collections.emptyList(), Arrays.asList(document.rootDoc().getFields(TypeFieldMapper.NAME))); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java index c5816de2e19..4128cec082e 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java @@ -48,7 +48,7 @@ public class UidFieldMapperTests extends ESSingleNodeTestCase { .put("index.version.created", Version.V_5_6_0) .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); IndexableField[] fields = document.rootDoc().getFields(UidFieldMapper.NAME); assertEquals(1, fields.length); @@ -60,7 +60,7 @@ public class UidFieldMapperTests extends ESSingleNodeTestCase { public void testDefaultsSingleType() throws IOException { Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); - DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); assertEquals(Collections.emptyList(), Arrays.asList(document.rootDoc().getFields(UidFieldMapper.NAME))); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/UpdateMappingTests.java b/server/src/test/java/org/elasticsearch/index/mapper/UpdateMappingTests.java index c6a1eae036a..c21fffc1bb1 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/UpdateMappingTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/UpdateMappingTests.java @@ -76,7 +76,7 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { CompressedXContent mappingBeforeUpdate = indexService.mapperService().documentMapper("type").mappingSource(); // simulate like in MetaDataMappingService#putMapping try { - indexService.mapperService().merge("type", new CompressedXContent(mappingUpdate.bytes()), MapperService.MergeReason.MAPPING_UPDATE, false); + indexService.mapperService().merge("type", new CompressedXContent(mappingUpdate.bytes()), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { // expected @@ -97,14 +97,14 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { .endObject().endObject().endObject(); try { - mapperService.merge("type", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("mapper [foo] cannot be changed from type [long] to [double]")); } try { - mapperService.merge("type", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("mapper [foo] cannot be changed from type [long] to [double]")); @@ -125,7 +125,7 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { .endObject().endObject().endObject(); try { - mapperService.merge("type2", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type2", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { // expected @@ -133,7 +133,7 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { } try { - mapperService.merge("type2", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type2", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { // expected @@ -154,15 +154,15 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test", Settings.builder().put("index.version.created", Version.V_5_6_0).build()).mapperService(); - mapperService.merge("type1", new CompressedXContent(mapping1.string()), MapperService.MergeReason.MAPPING_UPDATE, false); - mapperService.merge("type2", new CompressedXContent(mapping2.string()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type1", new CompressedXContent(mapping1.string()), MapperService.MergeReason.MAPPING_UPDATE); + mapperService.merge("type2", new CompressedXContent(mapping2.string()), MapperService.MergeReason.MAPPING_UPDATE); XContentBuilder update = XContentFactory.jsonBuilder().startObject().startObject("type2") .startObject("properties").startObject("foo").field("type", "double").endObject() .endObject().endObject().endObject(); try { - mapperService.merge("type2", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type2", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { // expected @@ -170,7 +170,7 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { } try { - mapperService.merge("type2", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type2", new CompressedXContent(update.string()), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { // expected @@ -190,14 +190,14 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { MapperService mapperService = createIndex("test", Settings.builder().build()).mapperService(); try { - mapperService.merge("type", new CompressedXContent(mapping.string()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type", new CompressedXContent(mapping.string()), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("Field [_id] is defined twice in [type]")); } try { - mapperService.merge("type", new CompressedXContent(mapping.string()), MapperService.MergeReason.MAPPING_UPDATE, false); + mapperService.merge("type", new CompressedXContent(mapping.string()), MapperService.MergeReason.MAPPING_UPDATE); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("Field [_id] is defined twice in [type]")); @@ -223,16 +223,16 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { .endObject().endObject().string(); MapperService mapperService1 = createIndex("test1").mapperService(); - mapperService1.merge("type1", new CompressedXContent(mapping1), MergeReason.MAPPING_UPDATE, false); + mapperService1.merge("type1", new CompressedXContent(mapping1), MergeReason.MAPPING_UPDATE); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> mapperService1.merge("type2", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, false)); + () -> mapperService1.merge("type2", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), equalTo("[foo] is defined as a field in mapping [type2" + "] but this name is already used for an object in other types")); MapperService mapperService2 = createIndex("test2").mapperService(); - mapperService2.merge("type2", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, false); + mapperService2.merge("type2", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); e = expectThrows(IllegalArgumentException.class, - () -> mapperService2.merge("type1", new CompressedXContent(mapping1), MergeReason.MAPPING_UPDATE, false)); + () -> mapperService2.merge("type1", new CompressedXContent(mapping1), MergeReason.MAPPING_UPDATE)); assertThat(e.getMessage(), equalTo("[foo] is defined as an object in mapping [type1" + "] but this name is already used for a field in other types")); } diff --git a/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java index 8849c91ddb3..00a9753b6f8 100644 --- a/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java @@ -355,7 +355,7 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase mapping == null ? update : mapping.merge(update, false)); + recoveredTypes.compute(engineIndex.type(), (k, mapping) -> mapping == null ? update : mapping.merge(update)); } engine.index(engineIndex); break; diff --git a/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldTypeTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldTypeTestCase.java index 2b6f4c38a90..818594d3bf7 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldTypeTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldTypeTestCase.java @@ -42,12 +42,12 @@ public abstract class FieldTypeTestCase extends ESTestCase { public abstract static class Modifier { /** The name of the property that is being modified. Used in test failure messages. */ public final String property; - /** true if this modifier only makes types incompatible in strict mode, false otherwise */ - public final boolean strictOnly; + /** True if this property is updateable, false otherwise. */ + public final boolean updateable; - public Modifier(String property, boolean strictOnly) { + public Modifier(String property, boolean updateable) { this.property = property; - this.strictOnly = strictOnly; + this.updateable = updateable; } /** Modifies the property */ @@ -189,16 +189,16 @@ public abstract class FieldTypeTestCase extends ESTestCase { } } - protected void assertCompatible(String msg, MappedFieldType ft1, MappedFieldType ft2, boolean strict) { + protected void assertCompatible(String msg, MappedFieldType ft1, MappedFieldType ft2) { List conflicts = new ArrayList<>(); - ft1.checkCompatibility(ft2, conflicts, strict); + ft1.checkCompatibility(ft2, conflicts); assertTrue("Found conflicts for " + msg + ": " + conflicts, conflicts.isEmpty()); } - protected void assertNotCompatible(String msg, MappedFieldType ft1, MappedFieldType ft2, boolean strict, String... messages) { + protected void assertNotCompatible(String msg, MappedFieldType ft1, MappedFieldType ft2, String... messages) { assert messages.length != 0; List conflicts = new ArrayList<>(); - ft1.checkCompatibility(ft2, conflicts, strict); + ft1.checkCompatibility(ft2, conflicts); for (String message : messages) { boolean found = false; for (String conflict : conflicts) { @@ -279,7 +279,7 @@ public abstract class FieldTypeTestCase extends ESTestCase { public void testCheckTypeName() { final MappedFieldType fieldType = createNamedDefaultFieldType(); List conflicts = new ArrayList<>(); - fieldType.checkCompatibility(fieldType, conflicts, random().nextBoolean()); // no exception + fieldType.checkCompatibility(fieldType, conflicts); // no exception assertTrue(conflicts.toString(), conflicts.isEmpty()); MappedFieldType bogus = new TermBasedFieldType() { @@ -291,7 +291,7 @@ public abstract class FieldTypeTestCase extends ESTestCase { public Query existsQuery(QueryShardContext context) { return null; } }; try { - fieldType.checkCompatibility(bogus, conflicts, random().nextBoolean()); + fieldType.checkCompatibility(bogus, conflicts); fail("expected bad types exception"); } catch (IllegalStateException e) { assertTrue(e.getMessage().contains("Type names equal")); @@ -307,7 +307,7 @@ public abstract class FieldTypeTestCase extends ESTestCase { public Query existsQuery(QueryShardContext context) { return null; } }; try { - fieldType.checkCompatibility(other, conflicts, random().nextBoolean()); + fieldType.checkCompatibility(other, conflicts); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage(), e.getMessage().contains("cannot be changed from type")); @@ -318,32 +318,22 @@ public abstract class FieldTypeTestCase extends ESTestCase { public void testCheckCompatibility() { MappedFieldType ft1 = createNamedDefaultFieldType(); MappedFieldType ft2 = createNamedDefaultFieldType(); - assertCompatible("default", ft1, ft2, true); - assertCompatible("default", ft1, ft2, false); - assertCompatible("default", ft2, ft1, true); - assertCompatible("default", ft2, ft1, false); + assertCompatible("default", ft1, ft2); + assertCompatible("default", ft2, ft1); for (Modifier modifier : modifiers) { ft1 = createNamedDefaultFieldType(); ft2 = createNamedDefaultFieldType(); modifier.normalizeOther(ft1); modifier.modify(ft2); - if (modifier.strictOnly) { - String[] conflicts = { - "mapper [foo] is used by multiple types", - "update [" + modifier.property + "]" - }; - assertCompatible(modifier.property, ft1, ft2, false); - assertNotCompatible(modifier.property, ft1, ft2, true, conflicts); - assertCompatible(modifier.property, ft2, ft1, false); // always symmetric when not strict - assertNotCompatible(modifier.property, ft2, ft1, true, conflicts); + if (modifier.updateable) { + assertCompatible(modifier.property, ft1, ft2); + assertCompatible(modifier.property, ft2, ft1); // always symmetric when not strict } else { // not compatible whether strict or not String conflict = "different [" + modifier.property + "]"; - assertNotCompatible(modifier.property, ft1, ft2, true, conflict); - assertNotCompatible(modifier.property, ft1, ft2, false, conflict); - assertNotCompatible(modifier.property, ft2, ft1, true, conflict); - assertNotCompatible(modifier.property, ft2, ft1, false, conflict); + assertNotCompatible(modifier.property, ft1, ft2, conflict); + assertNotCompatible(modifier.property, ft2, ft1, conflict); } } } diff --git a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java index cd55c1126eb..ca9d1728d92 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java @@ -287,7 +287,7 @@ public abstract class IndexShardTestCase extends ESTestCase { IndexCache indexCache = new IndexCache(indexSettings, new DisabledQueryCache(indexSettings), null); MapperService mapperService = MapperTestUtils.newMapperService(xContentRegistry(), createTempDir(), indexSettings.getSettings(), "index"); - mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY, true); + mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY); SimilarityService similarityService = new SimilarityService(indexSettings, null, Collections.emptyMap()); final IndexEventListener indexEventListener = new IndexEventListener() { }; @@ -579,7 +579,7 @@ public abstract class IndexShardTestCase extends ESTestCase { protected void updateMappings(IndexShard shard, IndexMetaData indexMetadata) { shard.indexSettings().updateIndexMetaData(indexMetadata); - shard.mapperService().merge(indexMetadata, MapperService.MergeReason.MAPPING_UPDATE, true); + shard.mapperService().merge(indexMetadata, MapperService.MergeReason.MAPPING_UPDATE); } protected Engine.DeleteResult deleteDoc(IndexShard shard, String type, String id) throws IOException { diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index f833e3c6100..4d30bddb3a4 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -1083,12 +1083,12 @@ public abstract class AbstractQueryTestCase> OBJECT_FIELD_NAME, "type=object", GEO_POINT_FIELD_NAME, "type=geo_point", GEO_SHAPE_FIELD_NAME, "type=geo_shape" - ).string()), MapperService.MergeReason.MAPPING_UPDATE, false); + ).string()), MapperService.MergeReason.MAPPING_UPDATE); // also add mappings for two inner field in the object field mapperService.merge(type, new CompressedXContent("{\"properties\":{\"" + OBJECT_FIELD_NAME + "\":{\"type\":\"object\"," + "\"properties\":{\"" + DATE_FIELD_NAME + "\":{\"type\":\"date\"},\"" + INT_FIELD_NAME + "\":{\"type\":\"integer\"}}}}}"), - MapperService.MergeReason.MAPPING_UPDATE, false); + MapperService.MergeReason.MAPPING_UPDATE); } testCase.initializeAdditionalMappings(mapperService); } From 452c36c5523b59ac3ce1e951bde63fa528e7a913 Mon Sep 17 00:00:00 2001 From: kel Date: Mon, 22 Jan 2018 19:42:56 +0800 Subject: [PATCH 4/8] Calculate sum in Kahan summation algorithm in aggregations (#27807) (#27848) --- .../metrics/avg/AvgAggregator.java | 24 +++++-- .../aggregations/metrics/avg/InternalAvg.java | 15 ++++- .../metrics/stats/InternalStats.java | 13 +++- .../metrics/stats/StatsAggregator.java | 23 +++++-- .../extended/ExtendedStatsAggregator.java | 41 ++++++++++-- .../stats/extended/InternalExtendedStats.java | 15 ++++- .../aggregations/metrics/sum/InternalSum.java | 15 ++++- .../metrics/sum/SumAggregator.java | 24 +++++-- .../metrics/ExtendedStatsAggregatorTests.java | 65 +++++++++++++++++++ .../metrics/InternalExtendedStatsTests.java | 42 ++++++++++++ .../metrics/InternalStatsTests.java | 52 ++++++++++++++- .../metrics/InternalSumTests.java | 45 ++++++++++++- .../metrics/StatsAggregatorTests.java | 63 ++++++++++++++++++ .../metrics/SumAggregatorTests.java | 54 ++++++++++++++- .../metrics/avg/AvgAggregatorTests.java | 61 +++++++++++++++-- .../metrics/avg/InternalAvgTests.java | 41 ++++++++++++ .../test/InternalAggregationTestCase.java | 1 + 17 files changed, 557 insertions(+), 37 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java index 0decfa05575..27890efbff1 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java @@ -44,6 +44,7 @@ public class AvgAggregator extends NumericMetricsAggregator.SingleValue { LongArray counts; DoubleArray sums; + DoubleArray compensations; DocValueFormat format; public AvgAggregator(String name, ValuesSource.Numeric valuesSource, DocValueFormat formatter, SearchContext context, @@ -55,6 +56,7 @@ public class AvgAggregator extends NumericMetricsAggregator.SingleValue { final BigArrays bigArrays = context.bigArrays(); counts = bigArrays.newLongArray(1, true); sums = bigArrays.newDoubleArray(1, true); + compensations = bigArrays.newDoubleArray(1, true); } } @@ -76,15 +78,29 @@ public class AvgAggregator extends NumericMetricsAggregator.SingleValue { public void collect(int doc, long bucket) throws IOException { counts = bigArrays.grow(counts, bucket + 1); sums = bigArrays.grow(sums, bucket + 1); + compensations = bigArrays.grow(compensations, bucket + 1); if (values.advanceExact(doc)) { final int valueCount = values.docValueCount(); counts.increment(bucket, valueCount); - double sum = 0; + // Compute the sum of double values with Kahan summation algorithm which is more + // accurate than naive summation. + double sum = sums.get(bucket); + double compensation = compensations.get(bucket); + for (int i = 0; i < valueCount; i++) { - sum += values.nextValue(); + double value = values.nextValue(); + if (Double.isFinite(value) == false) { + sum += value; + } else if (Double.isFinite(sum)) { + double corrected = value - compensation; + double newSum = sum + corrected; + compensation = (newSum - sum) - corrected; + sum = newSum; + } } - sums.increment(bucket, sum); + sums.set(bucket, sum); + compensations.set(bucket, compensation); } } }; @@ -113,7 +129,7 @@ public class AvgAggregator extends NumericMetricsAggregator.SingleValue { @Override public void doClose() { - Releasables.close(counts, sums); + Releasables.close(counts, sums, compensations); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvg.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvg.java index 7fdcc6396b8..c30574c576d 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvg.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvg.java @@ -91,9 +91,20 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i public InternalAvg doReduce(List aggregations, ReduceContext reduceContext) { long count = 0; double sum = 0; + double compensation = 0; + // Compute the sum of double values with Kahan summation algorithm which is more + // accurate than naive summation. for (InternalAggregation aggregation : aggregations) { - count += ((InternalAvg) aggregation).count; - sum += ((InternalAvg) aggregation).sum; + InternalAvg avg = (InternalAvg) aggregation; + count += avg.count; + if (Double.isFinite(avg.sum) == false) { + sum += avg.sum; + } else if (Double.isFinite(sum)) { + double corrected = avg.sum - compensation; + double newSum = sum + corrected; + compensation = (newSum - sum) - corrected; + sum = newSum; + } } return new InternalAvg(getName(), sum, count, format, pipelineAggregators(), getMetaData()); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/InternalStats.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/InternalStats.java index 6d7ae0cddc0..19f74cd72c8 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/InternalStats.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/InternalStats.java @@ -152,12 +152,23 @@ public class InternalStats extends InternalNumericMetricsAggregation.MultiValue double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; double sum = 0; + double compensation = 0; for (InternalAggregation aggregation : aggregations) { InternalStats stats = (InternalStats) aggregation; count += stats.getCount(); min = Math.min(min, stats.getMin()); max = Math.max(max, stats.getMax()); - sum += stats.getSum(); + // Compute the sum of double values with Kahan summation algorithm which is more + // accurate than naive summation. + double value = stats.getSum(); + if (Double.isFinite(value) == false) { + sum += value; + } else if (Double.isFinite(sum)) { + double corrected = value - compensation; + double newSum = sum + corrected; + compensation = (newSum - sum) - corrected; + sum = newSum; + } } return new InternalStats(name, count, sum, min, max, format, pipelineAggregators(), getMetaData()); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregator.java index cca176bd1ad..321e9e10f0f 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregator.java @@ -45,6 +45,7 @@ public class StatsAggregator extends NumericMetricsAggregator.MultiValue { LongArray counts; DoubleArray sums; + DoubleArray compensations; DoubleArray mins; DoubleArray maxes; @@ -59,6 +60,7 @@ public class StatsAggregator extends NumericMetricsAggregator.MultiValue { final BigArrays bigArrays = context.bigArrays(); counts = bigArrays.newLongArray(1, true); sums = bigArrays.newDoubleArray(1, true); + compensations = bigArrays.newDoubleArray(1, true); mins = bigArrays.newDoubleArray(1, false); mins.fill(0, mins.size(), Double.POSITIVE_INFINITY); maxes = bigArrays.newDoubleArray(1, false); @@ -88,6 +90,7 @@ public class StatsAggregator extends NumericMetricsAggregator.MultiValue { final long overSize = BigArrays.overSize(bucket + 1); counts = bigArrays.resize(counts, overSize); sums = bigArrays.resize(sums, overSize); + compensations = bigArrays.resize(compensations, overSize); mins = bigArrays.resize(mins, overSize); maxes = bigArrays.resize(maxes, overSize); mins.fill(from, overSize, Double.POSITIVE_INFINITY); @@ -97,16 +100,28 @@ public class StatsAggregator extends NumericMetricsAggregator.MultiValue { if (values.advanceExact(doc)) { final int valuesCount = values.docValueCount(); counts.increment(bucket, valuesCount); - double sum = 0; double min = mins.get(bucket); double max = maxes.get(bucket); + // Compute the sum of double values with Kahan summation algorithm which is more + // accurate than naive summation. + double sum = sums.get(bucket); + double compensation = compensations.get(bucket); + for (int i = 0; i < valuesCount; i++) { double value = values.nextValue(); - sum += value; + if (Double.isFinite(value) == false) { + sum += value; + } else if (Double.isFinite(sum)) { + double corrected = value - compensation; + double newSum = sum + corrected; + compensation = (newSum - sum) - corrected; + sum = newSum; + } min = Math.min(min, value); max = Math.max(max, value); } - sums.increment(bucket, sum); + sums.set(bucket, sum); + compensations.set(bucket, compensation); mins.set(bucket, min); maxes.set(bucket, max); } @@ -164,6 +179,6 @@ public class StatsAggregator extends NumericMetricsAggregator.MultiValue { @Override public void doClose() { - Releasables.close(counts, maxes, mins, sums); + Releasables.close(counts, maxes, mins, sums, compensations); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java index 8dd78bf1373..8339c06aefd 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java @@ -49,9 +49,11 @@ public class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue LongArray counts; DoubleArray sums; + DoubleArray compensations; DoubleArray mins; DoubleArray maxes; DoubleArray sumOfSqrs; + DoubleArray compensationOfSqrs; public ExtendedStatsAggregator(String name, ValuesSource.Numeric valuesSource, DocValueFormat formatter, SearchContext context, Aggregator parent, double sigma, List pipelineAggregators, @@ -65,11 +67,13 @@ public class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue final BigArrays bigArrays = context.bigArrays(); counts = bigArrays.newLongArray(1, true); sums = bigArrays.newDoubleArray(1, true); + compensations = bigArrays.newDoubleArray(1, true); mins = bigArrays.newDoubleArray(1, false); mins.fill(0, mins.size(), Double.POSITIVE_INFINITY); maxes = bigArrays.newDoubleArray(1, false); maxes.fill(0, maxes.size(), Double.NEGATIVE_INFINITY); sumOfSqrs = bigArrays.newDoubleArray(1, true); + compensationOfSqrs = bigArrays.newDoubleArray(1, true); } } @@ -95,9 +99,11 @@ public class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue final long overSize = BigArrays.overSize(bucket + 1); counts = bigArrays.resize(counts, overSize); sums = bigArrays.resize(sums, overSize); + compensations = bigArrays.resize(compensations, overSize); mins = bigArrays.resize(mins, overSize); maxes = bigArrays.resize(maxes, overSize); sumOfSqrs = bigArrays.resize(sumOfSqrs, overSize); + compensationOfSqrs = bigArrays.resize(compensationOfSqrs, overSize); mins.fill(from, overSize, Double.POSITIVE_INFINITY); maxes.fill(from, overSize, Double.NEGATIVE_INFINITY); } @@ -105,19 +111,40 @@ public class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue if (values.advanceExact(doc)) { final int valuesCount = values.docValueCount(); counts.increment(bucket, valuesCount); - double sum = 0; - double sumOfSqr = 0; double min = mins.get(bucket); double max = maxes.get(bucket); + // Compute the sum and sum of squires for double values with Kahan summation algorithm + // which is more accurate than naive summation. + double sum = sums.get(bucket); + double compensation = compensations.get(bucket); + double sumOfSqr = sumOfSqrs.get(bucket); + double compensationOfSqr = compensationOfSqrs.get(bucket); for (int i = 0; i < valuesCount; i++) { double value = values.nextValue(); - sum += value; - sumOfSqr += value * value; + if (Double.isFinite(value) == false) { + sum += value; + sumOfSqr += value * value; + } else { + if (Double.isFinite(sum)) { + double corrected = value - compensation; + double newSum = sum + corrected; + compensation = (newSum - sum) - corrected; + sum = newSum; + } + if (Double.isFinite(sumOfSqr)) { + double correctedOfSqr = value * value - compensationOfSqr; + double newSumOfSqr = sumOfSqr + correctedOfSqr; + compensationOfSqr = (newSumOfSqr - sumOfSqr) - correctedOfSqr; + sumOfSqr = newSumOfSqr; + } + } min = Math.min(min, value); max = Math.max(max, value); } - sums.increment(bucket, sum); - sumOfSqrs.increment(bucket, sumOfSqr); + sums.set(bucket, sum); + compensations.set(bucket, compensation); + sumOfSqrs.set(bucket, sumOfSqr); + compensationOfSqrs.set(bucket, compensationOfSqr); mins.set(bucket, min); maxes.set(bucket, max); } @@ -196,6 +223,6 @@ public class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue @Override public void doClose() { - Releasables.close(counts, maxes, mins, sumOfSqrs, sums); + Releasables.close(counts, maxes, mins, sumOfSqrs, compensationOfSqrs, sums, compensations); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/InternalExtendedStats.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/InternalExtendedStats.java index 6e06a88cccd..1f259fbe87d 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/InternalExtendedStats.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/InternalExtendedStats.java @@ -45,7 +45,7 @@ public class InternalExtendedStats extends InternalStats implements ExtendedStat private final double sigma; public InternalExtendedStats(String name, long count, double sum, double min, double max, double sumOfSqrs, double sigma, - DocValueFormat formatter, List pipelineAggregators, Map metaData) { + DocValueFormat formatter, List pipelineAggregators, Map metaData) { super(name, count, sum, min, max, formatter, pipelineAggregators, metaData); this.sumOfSqrs = sumOfSqrs; this.sigma = sigma; @@ -142,16 +142,25 @@ public class InternalExtendedStats extends InternalStats implements ExtendedStat @Override public InternalExtendedStats doReduce(List aggregations, ReduceContext reduceContext) { double sumOfSqrs = 0; + double compensationOfSqrs = 0; for (InternalAggregation aggregation : aggregations) { InternalExtendedStats stats = (InternalExtendedStats) aggregation; if (stats.sigma != sigma) { throw new IllegalStateException("Cannot reduce other stats aggregations that have a different sigma"); } - sumOfSqrs += stats.getSumOfSquares(); + double value = stats.getSumOfSquares(); + if (Double.isFinite(value) == false) { + sumOfSqrs += value; + } else if (Double.isFinite(sumOfSqrs)) { + double correctedOfSqrs = value - compensationOfSqrs; + double newSumOfSqrs = sumOfSqrs + correctedOfSqrs; + compensationOfSqrs = (newSumOfSqrs - sumOfSqrs) - correctedOfSqrs; + sumOfSqrs = newSumOfSqrs; + } } final InternalStats stats = super.doReduce(aggregations, reduceContext); return new InternalExtendedStats(name, stats.getCount(), stats.getSum(), stats.getMin(), stats.getMax(), sumOfSqrs, sigma, - format, pipelineAggregators(), getMetaData()); + format, pipelineAggregators(), getMetaData()); } static class Fields { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/InternalSum.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/InternalSum.java index 6f723f4fbcb..fb64d168db6 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/InternalSum.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/InternalSum.java @@ -35,7 +35,7 @@ public class InternalSum extends InternalNumericMetricsAggregation.SingleValue i private final double sum; public InternalSum(String name, double sum, DocValueFormat formatter, List pipelineAggregators, - Map metaData) { + Map metaData) { super(name, pipelineAggregators, metaData); this.sum = sum; this.format = formatter; @@ -73,9 +73,20 @@ public class InternalSum extends InternalNumericMetricsAggregation.SingleValue i @Override public InternalSum doReduce(List aggregations, ReduceContext reduceContext) { + // Compute the sum of double values with Kahan summation algorithm which is more + // accurate than naive summation. double sum = 0; + double compensation = 0; for (InternalAggregation aggregation : aggregations) { - sum += ((InternalSum) aggregation).sum; + double value = ((InternalSum) aggregation).sum; + if (Double.isFinite(value) == false) { + sum += value; + } else if (Double.isFinite(sum)) { + double corrected = value - compensation; + double newSum = sum + corrected; + compensation = (newSum - sum) - corrected; + sum = newSum; + } } return new InternalSum(name, sum, format, pipelineAggregators(), getMetaData()); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java index bd325b39373..9ed8103a1e1 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java @@ -43,6 +43,7 @@ public class SumAggregator extends NumericMetricsAggregator.SingleValue { private final DocValueFormat format; private DoubleArray sums; + private DoubleArray compensations; SumAggregator(String name, ValuesSource.Numeric valuesSource, DocValueFormat formatter, SearchContext context, Aggregator parent, List pipelineAggregators, Map metaData) throws IOException { @@ -51,6 +52,7 @@ public class SumAggregator extends NumericMetricsAggregator.SingleValue { this.format = formatter; if (valuesSource != null) { sums = context.bigArrays().newDoubleArray(1, true); + compensations = context.bigArrays().newDoubleArray(1, true); } } @@ -71,13 +73,27 @@ public class SumAggregator extends NumericMetricsAggregator.SingleValue { @Override public void collect(int doc, long bucket) throws IOException { sums = bigArrays.grow(sums, bucket + 1); + compensations = bigArrays.grow(compensations, bucket + 1); + if (values.advanceExact(doc)) { final int valuesCount = values.docValueCount(); - double sum = 0; + // Compute the sum of double values with Kahan summation algorithm which is more + // accurate than naive summation. + double sum = sums.get(bucket); + double compensation = compensations.get(bucket); for (int i = 0; i < valuesCount; i++) { - sum += values.nextValue(); + double value = values.nextValue(); + if (Double.isFinite(value) == false) { + sum += value; + } else if (Double.isFinite(sum)) { + double corrected = value - compensation; + double newSum = sum + corrected; + compensation = (newSum - sum) - corrected; + sum = newSum; + } } - sums.increment(bucket, sum); + compensations.set(bucket, compensation); + sums.set(bucket, sum); } } }; @@ -106,6 +122,6 @@ public class SumAggregator extends NumericMetricsAggregator.SingleValue { @Override public void doClose() { - Releasables.close(sums); + Releasables.close(sums, compensations); } } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorTests.java index 10b306ad717..144305647eb 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.search.aggregations.metrics; import org.apache.lucene.document.Document; +import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.document.SortedNumericDocValuesField; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; @@ -38,6 +39,8 @@ import org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExte import java.io.IOException; import java.util.function.Consumer; +import static java.util.Collections.singleton; + public class ExtendedStatsAggregatorTests extends AggregatorTestCase { private static final double TOLERANCE = 1e-5; @@ -132,6 +135,68 @@ public class ExtendedStatsAggregatorTests extends AggregatorTestCase { ); } + public void testSummationAccuracy() throws IOException { + double[] values = new double[]{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7}; + verifyStatsOfDoubles(values, 13.5, 16.21, 0d); + + // Summing up an array which contains NaN and infinities and expect a result same as naive summation + int n = randomIntBetween(5, 10); + values = new double[n]; + double sum = 0; + double sumOfSqrs = 0; + for (int i = 0; i < n; i++) { + values[i] = frequently() + ? randomFrom(Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) + : randomDoubleBetween(Double.MIN_VALUE, Double.MAX_VALUE, true); + sum += values[i]; + sumOfSqrs += values[i] * values[i]; + } + verifyStatsOfDoubles(values, sum, sumOfSqrs, TOLERANCE); + + // Summing up some big double values and expect infinity result + n = randomIntBetween(5, 10); + double[] largeValues = new double[n]; + for (int i = 0; i < n; i++) { + largeValues[i] = Double.MAX_VALUE; + } + verifyStatsOfDoubles(largeValues, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 0d); + + for (int i = 0; i < n; i++) { + largeValues[i] = -Double.MAX_VALUE; + } + verifyStatsOfDoubles(largeValues, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0d); + } + + private void verifyStatsOfDoubles(double[] values, double expectedSum, + double expectedSumOfSqrs, double delta) throws IOException { + MappedFieldType ft = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE); + final String fieldName = "field"; + ft.setName(fieldName); + double max = Double.NEGATIVE_INFINITY; + double min = Double.POSITIVE_INFINITY; + for (double value : values) { + max = Math.max(max, value); + min = Math.min(min, value); + } + double expectedMax = max; + double expectedMin = min; + testCase(ft, + iw -> { + for (double value : values) { + iw.addDocument(singleton(new NumericDocValuesField(fieldName, NumericUtils.doubleToSortableLong(value)))); + } + }, + stats -> { + assertEquals(values.length, stats.getCount()); + assertEquals(expectedSum / values.length, stats.getAvg(), delta); + assertEquals(expectedSum, stats.getSum(), delta); + assertEquals(expectedSumOfSqrs, stats.getSumOfSquares(), delta); + assertEquals(expectedMax, stats.getMax(), 0d); + assertEquals(expectedMin, stats.getMin(), 0d); + } + ); + } + public void testCase(MappedFieldType ft, CheckedConsumer buildIndex, Consumer verify) throws IOException { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java index 143ad4553c7..6178a72c83e 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.search.DocValueFormat; +import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats.Bounds; import org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats; @@ -28,6 +29,7 @@ import org.elasticsearch.search.aggregations.metrics.stats.extended.ParsedExtend import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.test.InternalAggregationTestCase; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -188,4 +190,44 @@ public class InternalExtendedStatsTests extends InternalAggregationTestCase aggregations = new ArrayList<>(values.length); + double sigma = randomDouble(); + for (double sumOfSqrs : values) { + aggregations.add(new InternalExtendedStats("dummy1", 1, 0.0, 0.0, 0.0, sumOfSqrs, sigma, null, null, null)); + } + InternalExtendedStats stats = new InternalExtendedStats("dummy", 1, 0.0, 0.0, 0.0, 0.0, sigma, null, null, null); + InternalExtendedStats reduced = stats.doReduce(aggregations, null); + assertEquals(expectedSumOfSqrs, reduced.getSumOfSquares(), delta); + } } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java index 4ce29e4e0ed..369fd671eb9 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.search.DocValueFormat; +import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.metrics.stats.InternalStats; import org.elasticsearch.search.aggregations.metrics.stats.ParsedStats; @@ -30,6 +31,7 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.test.InternalAggregationTestCase; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -48,7 +50,7 @@ public class InternalStatsTests extends InternalAggregationTestCase pipelineAggregators, Map metaData) { + List pipelineAggregators, Map metaData) { return new InternalStats(name, count, sum, min, max, formatter, pipelineAggregators, metaData); } @@ -74,6 +76,54 @@ public class InternalStatsTests extends InternalAggregationTestCase aggregations = new ArrayList<>(values.length); + double max = Double.NEGATIVE_INFINITY; + double min = Double.POSITIVE_INFINITY; + for (double value : values) { + max = Math.max(max, value); + min = Math.min(min, value); + aggregations.add(new InternalStats("dummy1", 1, value, value, value, null, null, null)); + } + InternalStats internalStats = new InternalStats("dummy2", 0, 0.0, 2.0, 0.0, null, null, null); + InternalStats reduced = internalStats.doReduce(aggregations, null); + assertEquals("dummy2", reduced.getName()); + assertEquals(values.length, reduced.getCount()); + assertEquals(expectedSum, reduced.getSum(), delta); + assertEquals(expectedAvg, reduced.getAvg(), delta); + assertEquals(min, reduced.getMin(), 0d); + assertEquals(max, reduced.getMax(), 0d); + } + @Override protected void assertFromXContent(InternalStats aggregation, ParsedAggregation parsedAggregation) { assertTrue(parsedAggregation instanceof ParsedStats); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalSumTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalSumTests.java index feeefac4daa..884f9bfbe0d 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalSumTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalSumTests.java @@ -20,12 +20,14 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.search.DocValueFormat; +import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.metrics.sum.InternalSum; import org.elasticsearch.search.aggregations.metrics.sum.ParsedSum; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.test.InternalAggregationTestCase; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,7 +36,7 @@ public class InternalSumTests extends InternalAggregationTestCase { @Override protected InternalSum createTestInstance(String name, List pipelineAggregators, Map metaData) { - double value = frequently() ? randomDouble() : randomFrom(new Double[] { Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY }); + double value = frequently() ? randomDouble() : randomFrom(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN); DocValueFormat formatter = randomFrom(new DocValueFormat.Decimal("###.##"), DocValueFormat.BOOLEAN, DocValueFormat.RAW); return new InternalSum(name, value, formatter, pipelineAggregators, metaData); } @@ -50,6 +52,47 @@ public class InternalSumTests extends InternalAggregationTestCase { assertEquals(expectedSum, reduced.getValue(), 0.0001d); } + public void testSummationAccuracy() { + // Summing up a normal array and expect an accurate value + double[] values = new double[]{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7}; + verifySummationOfDoubles(values, 13.5, 0d); + + // Summing up an array which contains NaN and infinities and expect a result same as naive summation + int n = randomIntBetween(5, 10); + values = new double[n]; + double sum = 0; + for (int i = 0; i < n; i++) { + values[i] = frequently() + ? randomFrom(Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) + : randomDoubleBetween(Double.MIN_VALUE, Double.MAX_VALUE, true); + sum += values[i]; + } + verifySummationOfDoubles(values, sum, TOLERANCE); + + // Summing up some big double values and expect infinity result + n = randomIntBetween(5, 10); + double[] largeValues = new double[n]; + for (int i = 0; i < n; i++) { + largeValues[i] = Double.MAX_VALUE; + } + verifySummationOfDoubles(largeValues, Double.POSITIVE_INFINITY, 0d); + + for (int i = 0; i < n; i++) { + largeValues[i] = -Double.MAX_VALUE; + } + verifySummationOfDoubles(largeValues, Double.NEGATIVE_INFINITY, 0d); + } + + private void verifySummationOfDoubles(double[] values, double expected, double delta) { + List aggregations = new ArrayList<>(values.length); + for (double value : values) { + aggregations.add(new InternalSum("dummy1", value, null, null, null)); + } + InternalSum internalSum = new InternalSum("dummy", 0, null, null, null); + InternalSum reduced = internalSum.doReduce(aggregations, null); + assertEquals(expected, reduced.value(), delta); + } + @Override protected void assertFromXContent(InternalSum sum, ParsedAggregation parsedAggregation) { ParsedSum parsed = ((ParsedSum) parsedAggregation); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorTests.java index 7286c7de0fe..c5c1420fb22 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.aggregations.metrics; import org.apache.lucene.document.Document; +import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.document.SortedNumericDocValuesField; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; @@ -36,6 +37,8 @@ import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuild import java.io.IOException; import java.util.function.Consumer; +import static java.util.Collections.singleton; + public class StatsAggregatorTests extends AggregatorTestCase { static final double TOLERANCE = 1e-10; @@ -113,6 +116,66 @@ public class StatsAggregatorTests extends AggregatorTestCase { ); } + public void testSummationAccuracy() throws IOException { + // Summing up a normal array and expect an accurate value + double[] values = new double[]{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7}; + verifySummationOfDoubles(values, 15.3, 0.9, 0d); + + // Summing up an array which contains NaN and infinities and expect a result same as naive summation + int n = randomIntBetween(5, 10); + values = new double[n]; + double sum = 0; + for (int i = 0; i < n; i++) { + values[i] = frequently() + ? randomFrom(Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) + : randomDoubleBetween(Double.MIN_VALUE, Double.MAX_VALUE, true); + sum += values[i]; + } + verifySummationOfDoubles(values, sum, sum / n, TOLERANCE); + + // Summing up some big double values and expect infinity result + n = randomIntBetween(5, 10); + double[] largeValues = new double[n]; + for (int i = 0; i < n; i++) { + largeValues[i] = Double.MAX_VALUE; + } + verifySummationOfDoubles(largeValues, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 0d); + + for (int i = 0; i < n; i++) { + largeValues[i] = -Double.MAX_VALUE; + } + verifySummationOfDoubles(largeValues, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, 0d); + } + + private void verifySummationOfDoubles(double[] values, double expectedSum, + double expectedAvg, double delta) throws IOException { + MappedFieldType ft = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE); + ft.setName("field"); + + double max = Double.NEGATIVE_INFINITY; + double min = Double.POSITIVE_INFINITY; + for (double value : values) { + max = Math.max(max, value); + min = Math.min(min, value); + } + double expectedMax = max; + double expectedMin = min; + testCase(ft, + iw -> { + for (double value : values) { + iw.addDocument(singleton(new NumericDocValuesField("field", NumericUtils.doubleToSortableLong(value)))); + } + }, + stats -> { + assertEquals(values.length, stats.getCount()); + assertEquals(expectedAvg, stats.getAvg(), delta); + assertEquals(expectedSum, stats.getSum(), delta); + assertEquals(expectedMax, stats.getMax(), 0d); + assertEquals(expectedMin, stats.getMin(), 0d); + } + ); + } + public void testCase(MappedFieldType ft, CheckedConsumer buildIndex, Consumer verify) throws IOException { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorTests.java index ff9888a4981..edaf5ae03f9 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorTests.java @@ -34,6 +34,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.NumberFieldMapper; @@ -107,7 +108,7 @@ public class SumAggregatorTests extends AggregatorTestCase { } public void testStringField() throws IOException { - IllegalStateException e = expectThrows(IllegalStateException.class , () -> { + IllegalStateException e = expectThrows(IllegalStateException.class, () -> { testCase(new MatchAllDocsQuery(), iw -> { iw.addDocument(singleton(new SortedDocValuesField(FIELD_NAME, new BytesRef("1")))); }, count -> assertEquals(0L, count.getValue(), 0d)); @@ -116,10 +117,59 @@ public class SumAggregatorTests extends AggregatorTestCase { "Re-index with correct docvalues type.", e.getMessage()); } + public void testSummationAccuracy() throws IOException { + // Summing up a normal array and expect an accurate value + double[] values = new double[]{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7}; + verifySummationOfDoubles(values, 15.3, 0d); + + // Summing up an array which contains NaN and infinities and expect a result same as naive summation + int n = randomIntBetween(5, 10); + values = new double[n]; + double sum = 0; + for (int i = 0; i < n; i++) { + values[i] = frequently() + ? randomFrom(Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) + : randomDoubleBetween(Double.MIN_VALUE, Double.MAX_VALUE, true); + sum += values[i]; + } + verifySummationOfDoubles(values, sum, 1e-10); + + // Summing up some big double values and expect infinity result + n = randomIntBetween(5, 10); + double[] largeValues = new double[n]; + for (int i = 0; i < n; i++) { + largeValues[i] = Double.MAX_VALUE; + } + verifySummationOfDoubles(largeValues, Double.POSITIVE_INFINITY, 0d); + + for (int i = 0; i < n; i++) { + largeValues[i] = -Double.MAX_VALUE; + } + verifySummationOfDoubles(largeValues, Double.NEGATIVE_INFINITY, 0d); + } + + private void verifySummationOfDoubles(double[] values, double expected, double delta) throws IOException { + testCase(new MatchAllDocsQuery(), + iw -> { + for (double value : values) { + iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, NumericUtils.doubleToSortableLong(value)))); + } + }, + result -> assertEquals(expected, result.getValue(), delta), + NumberFieldMapper.NumberType.DOUBLE + ); + } + private void testCase(Query query, CheckedConsumer indexer, Consumer verify) throws IOException { + testCase(query, indexer, verify, NumberFieldMapper.NumberType.LONG); + } + private void testCase(Query query, + CheckedConsumer indexer, + Consumer verify, + NumberFieldMapper.NumberType fieldNumberType) throws IOException { try (Directory directory = newDirectory()) { try (RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) { indexer.accept(indexWriter); @@ -128,7 +178,7 @@ public class SumAggregatorTests extends AggregatorTestCase { try (IndexReader indexReader = DirectoryReader.open(directory)) { IndexSearcher indexSearcher = newSearcher(indexReader, true, true); - MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG); + MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(fieldNumberType); fieldType.setName(FIELD_NAME); fieldType.setHasDocValues(true); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorTests.java index 2849ede447b..7835bf75e72 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorTests.java @@ -30,13 +30,11 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.NumberFieldMapper; import org.elasticsearch.search.aggregations.AggregatorTestCase; -import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregator; -import org.elasticsearch.search.aggregations.metrics.avg.InternalAvg; import java.io.IOException; import java.util.Arrays; @@ -103,8 +101,59 @@ public class AvgAggregatorTests extends AggregatorTestCase { }); } - private void testCase(Query query, CheckedConsumer buildIndex, Consumer verify) - throws IOException { + public void testSummationAccuracy() throws IOException { + // Summing up a normal array and expect an accurate value + double[] values = new double[]{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7}; + verifyAvgOfDoubles(values, 0.9, 0d); + + // Summing up an array which contains NaN and infinities and expect a result same as naive summation + int n = randomIntBetween(5, 10); + values = new double[n]; + double sum = 0; + for (int i = 0; i < n; i++) { + values[i] = frequently() + ? randomFrom(Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) + : randomDoubleBetween(Double.MIN_VALUE, Double.MAX_VALUE, true); + sum += values[i]; + } + verifyAvgOfDoubles(values, sum / n, 1e-10); + + // Summing up some big double values and expect infinity result + n = randomIntBetween(5, 10); + double[] largeValues = new double[n]; + for (int i = 0; i < n; i++) { + largeValues[i] = Double.MAX_VALUE; + } + verifyAvgOfDoubles(largeValues, Double.POSITIVE_INFINITY, 0d); + + for (int i = 0; i < n; i++) { + largeValues[i] = -Double.MAX_VALUE; + } + verifyAvgOfDoubles(largeValues, Double.NEGATIVE_INFINITY, 0d); + } + + private void verifyAvgOfDoubles(double[] values, double expected, double delta) throws IOException { + testCase(new MatchAllDocsQuery(), + iw -> { + for (double value : values) { + iw.addDocument(singleton(new NumericDocValuesField("number", NumericUtils.doubleToSortableLong(value)))); + } + }, + avg -> assertEquals(expected, avg.getValue(), delta), + NumberFieldMapper.NumberType.DOUBLE + ); + } + + private void testCase(Query query, + CheckedConsumer buildIndex, + Consumer verify) throws IOException { + testCase(query, buildIndex, verify, NumberFieldMapper.NumberType.LONG); + } + + private void testCase(Query query, + CheckedConsumer buildIndex, + Consumer verify, + NumberFieldMapper.NumberType fieldNumberType) throws IOException { Directory directory = newDirectory(); RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory); buildIndex.accept(indexWriter); @@ -114,7 +163,7 @@ public class AvgAggregatorTests extends AggregatorTestCase { IndexSearcher indexSearcher = newSearcher(indexReader, true, true); AvgAggregationBuilder aggregationBuilder = new AvgAggregationBuilder("_name").field("number"); - MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG); + MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(fieldNumberType); fieldType.setName("number"); AvgAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvgTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvgTests.java index a6bd641aaba..5adfb11f5bb 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvgTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvgTests.java @@ -21,10 +21,12 @@ package org.elasticsearch.search.aggregations.metrics.avg; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.search.DocValueFormat; +import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.test.InternalAggregationTestCase; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -56,6 +58,45 @@ public class InternalAvgTests extends InternalAggregationTestCase { assertEquals(sum / counts, reduced.value(), 0.0000001); } + public void testSummationAccuracy() { + double[] values = new double[]{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7}; + verifyAvgOfDoubles(values, 0.9, 0d); + + int n = randomIntBetween(5, 10); + values = new double[n]; + double sum = 0; + for (int i = 0; i < n; i++) { + values[i] = frequently() + ? randomFrom(Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) + : randomDoubleBetween(Double.MIN_VALUE, Double.MAX_VALUE, true); + sum += values[i]; + } + verifyAvgOfDoubles(values, sum / n, TOLERANCE); + + // Summing up some big double values and expect infinity result + n = randomIntBetween(5, 10); + double[] largeValues = new double[n]; + for (int i = 0; i < n; i++) { + largeValues[i] = Double.MAX_VALUE; + } + verifyAvgOfDoubles(largeValues, Double.POSITIVE_INFINITY, 0d); + + for (int i = 0; i < n; i++) { + largeValues[i] = -Double.MAX_VALUE; + } + verifyAvgOfDoubles(largeValues, Double.NEGATIVE_INFINITY, 0d); + } + + private void verifyAvgOfDoubles(double[] values, double expected, double delta) { + List aggregations = new ArrayList<>(values.length); + for (double value : values) { + aggregations.add(new InternalAvg("dummy1", value, 1, null, null, null)); + } + InternalAvg internalAvg = new InternalAvg("dummy2", 0, 0, null, null, null); + InternalAvg reduced = internalAvg.doReduce(aggregations, null); + assertEquals(expected, reduced.getValue(), delta); + } + @Override protected void assertFromXContent(InternalAvg avg, ParsedAggregation parsedAggregation) { ParsedAvg parsed = ((ParsedAvg) parsedAggregation); diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java index ea846c5dd18..8f5fe5d5622 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java @@ -150,6 +150,7 @@ import static org.hamcrest.Matchers.equalTo; public abstract class InternalAggregationTestCase extends AbstractWireSerializingTestCase { public static final int DEFAULT_MAX_BUCKETS = 100000; + protected static final double TOLERANCE = 1e-10; private final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry( new SearchModule(Settings.EMPTY, false, emptyList()).getNamedWriteables()); From 8d195c86ded108b59a4c01cbc9905f131b8e129c Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Mon, 22 Jan 2018 12:43:34 +0100 Subject: [PATCH 5/8] CountedBitSet doesn't need to extend BitSet. (#28239) --- .../index/seqno/CountedBitSet.java | 36 +++---------------- .../index/seqno/LocalCheckpointTracker.java | 13 ++++--- .../index/translog/MultiSnapshot.java | 5 ++- .../index/seqno/CountedBitSetTests.java | 5 --- .../seqno/LocalCheckpointTrackerTests.java | 3 +- 5 files changed, 13 insertions(+), 49 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/seqno/CountedBitSet.java b/server/src/main/java/org/elasticsearch/index/seqno/CountedBitSet.java index 54270de1b01..d1f6f4a3a37 100644 --- a/server/src/main/java/org/elasticsearch/index/seqno/CountedBitSet.java +++ b/server/src/main/java/org/elasticsearch/index/seqno/CountedBitSet.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.seqno; -import org.apache.lucene.util.BitSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.RamUsageEstimator; @@ -28,7 +27,7 @@ import org.apache.lucene.util.RamUsageEstimator; * when all bits are set to reduce memory usage. This structure can work well for sequence numbers as * these numbers are likely to form contiguous ranges (eg. filling all bits). */ -public final class CountedBitSet extends BitSet { +public final class CountedBitSet { static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(CountedBitSet.class); private short onBits; // Number of bits are set. private FixedBitSet bitset; @@ -41,14 +40,12 @@ public final class CountedBitSet extends BitSet { this.bitset = new FixedBitSet(numBits); } - @Override public boolean get(int index) { assert 0 <= index && index < this.length(); assert bitset == null || onBits < bitset.length() : "Bitset should be released when all bits are set"; return bitset == null ? true : bitset.get(index); } - @Override public void set(int index) { assert 0 <= index && index < this.length(); assert bitset == null || onBits < bitset.length() : "Bitset should be released when all bits are set"; @@ -67,41 +64,16 @@ public final class CountedBitSet extends BitSet { } } - @Override - public void clear(int startIndex, int endIndex) { - throw new UnsupportedOperationException(); - } + // Below methods are pkg-private for testing - @Override - public void clear(int index) { - throw new UnsupportedOperationException(); - } - - @Override - public int cardinality() { + int cardinality() { return onBits; } - @Override - public int length() { + int length() { return bitset == null ? onBits : bitset.length(); } - @Override - public int prevSetBit(int index) { - throw new UnsupportedOperationException(); - } - - @Override - public int nextSetBit(int index) { - throw new UnsupportedOperationException(); - } - - @Override - public long ramBytesUsed() { - return BASE_RAM_BYTES_USED + (bitset == null ? 0 : bitset.ramBytesUsed()); - } - boolean isInternalBitsetReleased() { return bitset == null; } diff --git a/server/src/main/java/org/elasticsearch/index/seqno/LocalCheckpointTracker.java b/server/src/main/java/org/elasticsearch/index/seqno/LocalCheckpointTracker.java index 34926a36f45..cd33c1bf046 100644 --- a/server/src/main/java/org/elasticsearch/index/seqno/LocalCheckpointTracker.java +++ b/server/src/main/java/org/elasticsearch/index/seqno/LocalCheckpointTracker.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.seqno; import com.carrotsearch.hppc.LongObjectHashMap; -import org.apache.lucene.util.BitSet; import org.elasticsearch.common.SuppressForbidden; /** @@ -39,7 +38,7 @@ public class LocalCheckpointTracker { * A collection of bit sets representing pending sequence numbers. Each sequence number is mapped to a bit set by dividing by the * bit set size. */ - final LongObjectHashMap processedSeqNo = new LongObjectHashMap<>(); + final LongObjectHashMap processedSeqNo = new LongObjectHashMap<>(); /** * The current local checkpoint, i.e., all sequence numbers no more than this number have been completed. @@ -96,7 +95,7 @@ public class LocalCheckpointTracker { // this is possible during recovery where we might replay an operation that was also replicated return; } - final BitSet bitSet = getBitSetForSeqNo(seqNo); + final CountedBitSet bitSet = getBitSetForSeqNo(seqNo); final int offset = seqNoToBitSetOffset(seqNo); bitSet.set(offset); if (seqNo == checkpoint + 1) { @@ -170,7 +169,7 @@ public class LocalCheckpointTracker { try { // keep it simple for now, get the checkpoint one by one; in the future we can optimize and read words long bitSetKey = getBitSetKey(checkpoint); - BitSet current = processedSeqNo.get(bitSetKey); + CountedBitSet current = processedSeqNo.get(bitSetKey); if (current == null) { // the bit set corresponding to the checkpoint has already been removed, set ourselves up for the next bit set assert checkpoint % BIT_SET_SIZE == BIT_SET_SIZE - 1; @@ -184,7 +183,7 @@ public class LocalCheckpointTracker { */ if (checkpoint == lastSeqNoInBitSet(bitSetKey)) { assert current != null; - final BitSet removed = processedSeqNo.remove(bitSetKey); + final CountedBitSet removed = processedSeqNo.remove(bitSetKey); assert removed == current; current = processedSeqNo.get(++bitSetKey); } @@ -210,11 +209,11 @@ public class LocalCheckpointTracker { return seqNo / BIT_SET_SIZE; } - private BitSet getBitSetForSeqNo(final long seqNo) { + private CountedBitSet getBitSetForSeqNo(final long seqNo) { assert Thread.holdsLock(this); final long bitSetKey = getBitSetKey(seqNo); final int index = processedSeqNo.indexOf(bitSetKey); - final BitSet bitSet; + final CountedBitSet bitSet; if (processedSeqNo.indexExists(index)) { bitSet = processedSeqNo.indexGet(index); } else { diff --git a/server/src/main/java/org/elasticsearch/index/translog/MultiSnapshot.java b/server/src/main/java/org/elasticsearch/index/translog/MultiSnapshot.java index 910d71a51a0..7ea241958f8 100644 --- a/server/src/main/java/org/elasticsearch/index/translog/MultiSnapshot.java +++ b/server/src/main/java/org/elasticsearch/index/translog/MultiSnapshot.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.translog; import com.carrotsearch.hppc.LongObjectHashMap; -import org.apache.lucene.util.BitSet; import org.elasticsearch.index.seqno.CountedBitSet; import org.elasticsearch.index.seqno.SequenceNumbers; @@ -85,7 +84,7 @@ final class MultiSnapshot implements Translog.Snapshot { static final class SeqNoSet { static final short BIT_SET_SIZE = 1024; - private final LongObjectHashMap bitSets = new LongObjectHashMap<>(); + private final LongObjectHashMap bitSets = new LongObjectHashMap<>(); /** * Marks this sequence number and returns true if it is seen before. @@ -93,7 +92,7 @@ final class MultiSnapshot implements Translog.Snapshot { boolean getAndSet(long value) { assert value >= 0; final long key = value / BIT_SET_SIZE; - BitSet bitset = bitSets.get(key); + CountedBitSet bitset = bitSets.get(key); if (bitset == null) { bitset = new CountedBitSet(BIT_SET_SIZE); bitSets.put(key, bitset); diff --git a/server/src/test/java/org/elasticsearch/index/seqno/CountedBitSetTests.java b/server/src/test/java/org/elasticsearch/index/seqno/CountedBitSetTests.java index b014f827406..bc4f58034d1 100644 --- a/server/src/test/java/org/elasticsearch/index/seqno/CountedBitSetTests.java +++ b/server/src/test/java/org/elasticsearch/index/seqno/CountedBitSetTests.java @@ -26,9 +26,7 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; -import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.lessThan; public class CountedBitSetTests extends ESTestCase { @@ -55,7 +53,6 @@ public class CountedBitSetTests extends ESTestCase { int numBits = (short) randomIntBetween(8, 4096); final CountedBitSet countedBitSet = new CountedBitSet((short) numBits); final List values = IntStream.range(0, numBits).boxed().collect(Collectors.toList()); - final long ramBytesUsedWithBitSet = countedBitSet.ramBytesUsed(); for (int i = 1; i < numBits; i++) { final int value = values.get(i); @@ -68,7 +65,6 @@ public class CountedBitSetTests extends ESTestCase { assertThat(countedBitSet.isInternalBitsetReleased(), equalTo(false)); assertThat(countedBitSet.length(), equalTo(numBits)); assertThat(countedBitSet.cardinality(), equalTo(i)); - assertThat(countedBitSet.ramBytesUsed(), equalTo(ramBytesUsedWithBitSet)); } // The missing piece to fill all bits. @@ -83,7 +79,6 @@ public class CountedBitSetTests extends ESTestCase { assertThat(countedBitSet.isInternalBitsetReleased(), equalTo(true)); assertThat(countedBitSet.length(), equalTo(numBits)); assertThat(countedBitSet.cardinality(), equalTo(numBits)); - assertThat(countedBitSet.ramBytesUsed(), allOf(equalTo(CountedBitSet.BASE_RAM_BYTES_USED), lessThan(ramBytesUsedWithBitSet))); } // Tests with released internal bitset. diff --git a/server/src/test/java/org/elasticsearch/index/seqno/LocalCheckpointTrackerTests.java b/server/src/test/java/org/elasticsearch/index/seqno/LocalCheckpointTrackerTests.java index 31b8c23bf1c..932fb717908 100644 --- a/server/src/test/java/org/elasticsearch/index/seqno/LocalCheckpointTrackerTests.java +++ b/server/src/test/java/org/elasticsearch/index/seqno/LocalCheckpointTrackerTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.seqno; import com.carrotsearch.hppc.LongObjectHashMap; -import org.apache.lucene.util.BitSet; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.Randomness; import org.elasticsearch.common.util.concurrent.AbstractRunnable; @@ -260,7 +259,7 @@ public class LocalCheckpointTrackerTests extends ESTestCase { tracker.resetCheckpoint(localCheckpoint); assertThat(tracker.getCheckpoint(), equalTo((long) localCheckpoint)); assertThat(tracker.getMaxSeqNo(), equalTo((long) maxSeqNo)); - assertThat(tracker.processedSeqNo, new BaseMatcher>() { + assertThat(tracker.processedSeqNo, new BaseMatcher>() { @Override public boolean matches(Object item) { return (item instanceof LongObjectHashMap && ((LongObjectHashMap) item).isEmpty()); From a6bfe67f8b1247068759a392d2e73ee3eaa9ac06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Mon, 22 Jan 2018 13:33:35 +0100 Subject: [PATCH 6/8] [Test] Lower bwc version for rank-eval rest tests The API was backported to 6.2 so the version we test against on master can be lowered to that. --- .../test/resources/rest-api-spec/test/rank_eval/10_basic.yml | 4 ++-- .../test/resources/rest-api-spec/test/rank_eval/20_dcg.yml | 4 ++-- .../resources/rest-api-spec/test/rank_eval/30_failures.yml | 4 ++-- .../resources/rest-api-spec/test/rank-eval/30_template.yml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/10_basic.yml b/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/10_basic.yml index 2eab6e47e7f..4a244dcb9e5 100644 --- a/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/10_basic.yml +++ b/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/10_basic.yml @@ -2,8 +2,8 @@ "Response format": - skip: - version: " - 6.99.99" - reason: the ranking evaluation feature is only available on 7.0 + version: " - 6.1.99" + reason: the ranking evaluation feature is available since 6.2 - do: indices.create: diff --git a/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/20_dcg.yml b/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/20_dcg.yml index 3a68890dce9..fc5e6576ad4 100644 --- a/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/20_dcg.yml +++ b/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/20_dcg.yml @@ -2,8 +2,8 @@ "Response format": - skip: - version: " - 6.99.99" - reason: the ranking evaluation feature is only available on 7.0 + version: " - 6.1.99" + reason: the ranking evaluation feature is available since 6.2 - do: index: diff --git a/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/30_failures.yml b/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/30_failures.yml index 48ea593712e..24902253eb0 100644 --- a/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/30_failures.yml +++ b/modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/30_failures.yml @@ -2,8 +2,8 @@ "Response format": - skip: - version: " - 6.99.99" - reason: the ranking evaluation feature is only available on 7.0 + version: " - 6.1.99" + reason: the ranking evaluation feature is available since 6.2 - do: index: diff --git a/qa/smoke-test-rank-eval-with-mustache/src/test/resources/rest-api-spec/test/rank-eval/30_template.yml b/qa/smoke-test-rank-eval-with-mustache/src/test/resources/rest-api-spec/test/rank-eval/30_template.yml index 9dfbecce75b..692a2e21230 100644 --- a/qa/smoke-test-rank-eval-with-mustache/src/test/resources/rest-api-spec/test/rank-eval/30_template.yml +++ b/qa/smoke-test-rank-eval-with-mustache/src/test/resources/rest-api-spec/test/rank-eval/30_template.yml @@ -2,8 +2,8 @@ "Template request": - skip: - version: " - 6.99.99" - reason: the ranking evaluation feature is only available on 7.0 + version: " - 6.1.99" + reason: the ranking evaluation feature is available since 6.2 - do: indices.create: From 509ecf2aa63560e0e0cb12f89f7f5d7ef09a42f9 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 18 Jan 2018 13:26:16 +0100 Subject: [PATCH 7/8] Do not return all indices if a specific alias is requested via get aliases api. If a get alias api call requests a specific alias pattern then indices not having any matching aliases should not be included in the response. Closes #27763 --- .../alias/get/TransportGetAliasesAction.java | 3 +-- .../cluster/metadata/MetaData.java | 12 +++++------- .../admin/indices/RestGetAliasesAction.java | 1 - .../elasticsearch/aliases/IndexAliasesIT.java | 18 ++++-------------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java index b7ce0407681..6edc95f649d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java @@ -62,8 +62,7 @@ public class TransportGetAliasesAction extends TransportMasterNodeReadAction listener) { String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); - @SuppressWarnings("unchecked") - ImmutableOpenMap> result = (ImmutableOpenMap) state.metaData().findAliases(request.aliases(), concreteIndices); + ImmutableOpenMap> result = state.metaData().findAliases(request.aliases(), concreteIndices); listener.onResponse(new GetAliasesResponse(result)); } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 0e9bcf8f11a..98afe41c596 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -275,14 +275,12 @@ public class MetaData implements Iterable, Diffable, To if (!filteredValues.isEmpty()) { // Make the list order deterministic - CollectionUtil.timSort(filteredValues, new Comparator() { - @Override - public int compare(AliasMetaData o1, AliasMetaData o2) { - return o1.alias().compareTo(o2.alias()); - } - }); + CollectionUtil.timSort(filteredValues, Comparator.comparing(AliasMetaData::alias)); + mapBuilder.put(index, Collections.unmodifiableList(filteredValues)); + } else if (matchAllAliases) { + // in case all aliases are requested then it is desired to return the concrete index with no aliases (#25114): + mapBuilder.put(index, Collections.emptyList()); } - mapBuilder.put(index, Collections.unmodifiableList(filteredValues)); } return mapBuilder.build(); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java index 51ff743d2d1..8cf4707262e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java @@ -19,7 +19,6 @@ package org.elasticsearch.rest.action.admin.indices; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; diff --git a/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java b/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java index 8bf074be551..dae421db97f 100644 --- a/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java +++ b/server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java @@ -570,24 +570,20 @@ public class IndexAliasesIT extends ESIntegTestCase { logger.info("--> getting alias1"); GetAliasesResponse getResponse = admin().indices().prepareGetAliases("alias1").get(); assertThat(getResponse, notNullValue()); - assertThat(getResponse.getAliases().size(), equalTo(5)); + assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1)); assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("alias1")); assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue()); - assertTrue(getResponse.getAliases().get("test").isEmpty()); - assertTrue(getResponse.getAliases().get("test123").isEmpty()); - assertTrue(getResponse.getAliases().get("foobarbaz").isEmpty()); - assertTrue(getResponse.getAliases().get("bazbar").isEmpty()); AliasesExistResponse existsResponse = admin().indices().prepareAliasesExist("alias1").get(); assertThat(existsResponse.exists(), equalTo(true)); logger.info("--> getting all aliases that start with alias*"); getResponse = admin().indices().prepareGetAliases("alias*").get(); assertThat(getResponse, notNullValue()); - assertThat(getResponse.getAliases().size(), equalTo(5)); + assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().get("foobar").size(), equalTo(2)); assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("alias1")); @@ -599,10 +595,6 @@ public class IndexAliasesIT extends ESIntegTestCase { assertThat(getResponse.getAliases().get("foobar").get(1).getFilter(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(1).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(1).getSearchRouting(), nullValue()); - assertTrue(getResponse.getAliases().get("test").isEmpty()); - assertTrue(getResponse.getAliases().get("test123").isEmpty()); - assertTrue(getResponse.getAliases().get("foobarbaz").isEmpty()); - assertTrue(getResponse.getAliases().get("bazbar").isEmpty()); existsResponse = admin().indices().prepareAliasesExist("alias*").get(); assertThat(existsResponse.exists(), equalTo(true)); @@ -687,13 +679,12 @@ public class IndexAliasesIT extends ESIntegTestCase { logger.info("--> getting f* for index *bar"); getResponse = admin().indices().prepareGetAliases("f*").addIndices("*bar").get(); assertThat(getResponse, notNullValue()); - assertThat(getResponse.getAliases().size(), equalTo(2)); + assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo")); assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue()); - assertTrue(getResponse.getAliases().get("bazbar").isEmpty()); existsResponse = admin().indices().prepareAliasesExist("f*") .addIndices("*bar").get(); assertThat(existsResponse.exists(), equalTo(true)); @@ -702,14 +693,13 @@ public class IndexAliasesIT extends ESIntegTestCase { logger.info("--> getting f* for index *bac"); getResponse = admin().indices().prepareGetAliases("foo").addIndices("*bac").get(); assertThat(getResponse, notNullValue()); - assertThat(getResponse.getAliases().size(), equalTo(2)); + assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1)); assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo")); assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue()); - assertTrue(getResponse.getAliases().get("bazbar").isEmpty()); existsResponse = admin().indices().prepareAliasesExist("foo") .addIndices("*bac").get(); assertThat(existsResponse.exists(), equalTo(true)); From 0c83ee2a5dc13cbf9069f02b007b89459373b477 Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Mon, 22 Jan 2018 15:51:46 +0100 Subject: [PATCH 8/8] Trim down usages of `ShardOperationFailedException` interface (#28312) In many cases we use the `ShardOperationFailedException` interface to abstract an exception that can only be of one type, namely `DefaultShardOperationException`. There is no need to use the interface in such cases, the concrete type should be used instead. That has the additional advantage of simplifying parsing such exceptions back from rest responses for the high-level REST client --- .../clear/ClearIndicesCacheResponse.java | 5 ++-- .../TransportClearIndicesCacheAction.java | 4 +-- .../admin/indices/flush/FlushResponse.java | 4 +-- .../indices/flush/TransportFlushAction.java | 5 ++-- .../forcemerge/ForceMergeResponse.java | 4 +-- .../forcemerge/TransportForceMergeAction.java | 4 +-- .../indices/recovery/RecoveryResponse.java | 5 ++-- .../recovery/TransportRecoveryAction.java | 4 +-- .../indices/refresh/RefreshResponse.java | 4 +-- .../refresh/TransportRefreshAction.java | 5 ++-- .../segments/IndicesSegmentResponse.java | 5 ++-- .../TransportIndicesSegmentsAction.java | 4 +-- .../shards/IndicesShardStoresResponse.java | 5 ++-- .../indices/stats/IndicesStatsResponse.java | 5 ++-- .../stats/TransportIndicesStatsAction.java | 4 +-- .../get/TransportUpgradeStatusAction.java | 4 +-- .../upgrade/get/UpgradeStatusResponse.java | 6 ++-- .../upgrade/post/TransportUpgradeAction.java | 4 +-- .../indices/upgrade/post/UpgradeResponse.java | 5 ++-- .../query/TransportValidateQueryAction.java | 3 +- .../validate/query/ValidateQueryResponse.java | 5 ++-- .../support/broadcast/BroadcastResponse.java | 29 +++++++------------ .../node/TransportBroadcastByNodeAction.java | 5 ++-- .../TransportBroadcastReplicationAction.java | 8 ++--- .../indices/stats/IndicesStatsTests.java | 5 ++-- .../TransportBroadcastByNodeActionTests.java | 6 ++-- .../BroadcastReplicationTests.java | 4 +-- .../org/elasticsearch/get/GetActionIT.java | 4 +-- .../indices/stats/IndexStatsIT.java | 7 +++-- .../action/cat/RestRecoveryActionTests.java | 4 +-- .../elasticsearch/test/ESIntegTestCase.java | 4 +-- .../hamcrest/ElasticsearchAssertions.java | 6 ++-- 32 files changed, 87 insertions(+), 89 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheResponse.java index cd3355cae87..d0f4b3cc20b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheResponse.java @@ -19,7 +19,7 @@ package org.elasticsearch.action.admin.indices.cache.clear; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -38,7 +38,8 @@ public class ClearIndicesCacheResponse extends BroadcastResponse { } - ClearIndicesCacheResponse(int totalShards, int successfulShards, int failedShards, List shardFailures) { + ClearIndicesCacheResponse(int totalShards, int successfulShards, int failedShards, + List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java index 0ad94db7b1f..eda82fb710c 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java @@ -19,8 +19,8 @@ package org.elasticsearch.action.admin.indices.cache.clear; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -65,7 +65,7 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastByNodeAc @Override protected ClearIndicesCacheResponse newResponse(ClearIndicesCacheRequest request, int totalShards, int successfulShards, int failedShards, List responses, - List shardFailures, ClusterState clusterState) { + List shardFailures, ClusterState clusterState) { return new ClearIndicesCacheResponse(totalShards, successfulShards, failedShards, shardFailures); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushResponse.java index c2ac7002645..273fc3e817d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushResponse.java @@ -19,7 +19,7 @@ package org.elasticsearch.action.admin.indices.flush; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import java.util.List; @@ -35,7 +35,7 @@ public class FlushResponse extends BroadcastResponse { } - FlushResponse(int totalShards, int successfulShards, int failedShards, List shardFailures) { + FlushResponse(int totalShards, int successfulShards, int failedShards, List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportFlushAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportFlushAction.java index a29918b438e..91755388320 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportFlushAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportFlushAction.java @@ -19,8 +19,8 @@ package org.elasticsearch.action.admin.indices.flush; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.replication.ReplicationResponse; import org.elasticsearch.action.support.replication.TransportBroadcastReplicationAction; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; @@ -57,7 +57,8 @@ public class TransportFlushAction extends TransportBroadcastReplicationAction shardFailures) { + protected FlushResponse newResponse(int successfulShards, int failedShards, int totalNumCopies, List + shardFailures) { return new FlushResponse(totalNumCopies, successfulShards, failedShards, shardFailures); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeResponse.java index 3844f00193c..f77bb5d6a57 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeResponse.java @@ -19,7 +19,7 @@ package org.elasticsearch.action.admin.indices.forcemerge; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import java.util.List; @@ -32,7 +32,7 @@ public class ForceMergeResponse extends BroadcastResponse { ForceMergeResponse() { } - ForceMergeResponse(int totalShards, int successfulShards, int failedShards, List shardFailures) { + ForceMergeResponse(int totalShards, int successfulShards, int failedShards, List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java index 18ac88e1b30..94f27a93624 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java @@ -19,8 +19,8 @@ package org.elasticsearch.action.admin.indices.forcemerge; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -62,7 +62,7 @@ public class TransportForceMergeAction extends TransportBroadcastByNodeAction responses, List shardFailures, ClusterState clusterState) { + protected ForceMergeResponse newResponse(ForceMergeRequest request, int totalShards, int successfulShards, int failedShards, List responses, List shardFailures, ClusterState clusterState) { return new ForceMergeResponse(totalShards, successfulShards, failedShards, shardFailures); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryResponse.java index a19393ebd5b..1a9c86049f8 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryResponse.java @@ -19,7 +19,7 @@ package org.elasticsearch.action.admin.indices.recovery; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -56,7 +56,8 @@ public class RecoveryResponse extends BroadcastResponse implements ToXContentFra * @param shardFailures List of failures processing shards */ public RecoveryResponse(int totalShards, int successfulShards, int failedShards, boolean detailed, - Map> shardRecoveryStates, List shardFailures) { + Map> shardRecoveryStates, + List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); this.shardRecoveryStates = shardRecoveryStates; this.detailed = detailed; diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/TransportRecoveryAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/TransportRecoveryAction.java index 01f37527374..0e11aed9d24 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/TransportRecoveryAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/TransportRecoveryAction.java @@ -19,8 +19,8 @@ package org.elasticsearch.action.admin.indices.recovery; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -69,7 +69,7 @@ public class TransportRecoveryAction extends TransportBroadcastByNodeAction responses, List shardFailures, ClusterState clusterState) { + protected RecoveryResponse newResponse(RecoveryRequest request, int totalShards, int successfulShards, int failedShards, List responses, List shardFailures, ClusterState clusterState) { Map> shardResponses = new HashMap<>(); for (RecoveryState recoveryState : responses) { if (recoveryState == null) { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshResponse.java index ba3ec31c6a5..b629ac22b89 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshResponse.java @@ -19,7 +19,7 @@ package org.elasticsearch.action.admin.indices.refresh; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import java.util.List; @@ -32,7 +32,7 @@ public class RefreshResponse extends BroadcastResponse { RefreshResponse() { } - RefreshResponse(int totalShards, int successfulShards, int failedShards, List shardFailures) { + RefreshResponse(int totalShards, int successfulShards, int failedShards, List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java index 9752e68517e..d44783d3c64 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.admin.indices.refresh; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActiveShardCount; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.replication.BasicReplicationRequest; import org.elasticsearch.action.support.replication.ReplicationResponse; import org.elasticsearch.action.support.replication.TransportBroadcastReplicationAction; @@ -61,7 +61,8 @@ public class TransportRefreshAction extends TransportBroadcastReplicationAction< } @Override - protected RefreshResponse newResponse(int successfulShards, int failedShards, int totalNumCopies, List shardFailures) { + protected RefreshResponse newResponse(int successfulShards, int failedShards, int totalNumCopies, + List shardFailures) { return new RefreshResponse(totalNumCopies, successfulShards, failedShards, shardFailures); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java index 2e241ef1614..b9296c0242f 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java @@ -24,7 +24,7 @@ import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortedNumericSortField; import org.apache.lucene.search.SortedSetSortField; import org.apache.lucene.util.Accountable; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -53,7 +53,8 @@ public class IndicesSegmentResponse extends BroadcastResponse implements ToXCont } - IndicesSegmentResponse(ShardSegments[] shards, int totalShards, int successfulShards, int failedShards, List shardFailures) { + IndicesSegmentResponse(ShardSegments[] shards, int totalShards, int successfulShards, int failedShards, + List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); this.shards = shards; } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/segments/TransportIndicesSegmentsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/segments/TransportIndicesSegmentsAction.java index 350e8dffa19..94b12c9ab17 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/segments/TransportIndicesSegmentsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/segments/TransportIndicesSegmentsAction.java @@ -19,8 +19,8 @@ package org.elasticsearch.action.admin.indices.segments; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -77,7 +77,7 @@ public class TransportIndicesSegmentsAction extends TransportBroadcastByNodeActi } @Override - protected IndicesSegmentResponse newResponse(IndicesSegmentsRequest request, int totalShards, int successfulShards, int failedShards, List results, List shardFailures, ClusterState clusterState) { + protected IndicesSegmentResponse newResponse(IndicesSegmentsRequest request, int totalShards, int successfulShards, int failedShards, List results, List shardFailures, ClusterState clusterState) { return new IndicesSegmentResponse(results.toArray(new ShardSegments[results.size()]), totalShards, successfulShards, failedShards, shardFailures); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresResponse.java index 70624380e86..6cf16089748 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresResponse.java @@ -25,7 +25,6 @@ import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.collect.ImmutableOpenIntMap; @@ -348,7 +347,7 @@ public class IndicesShardStoresResponse extends ActionResponse implements ToXCon } } out.writeVInt(failures.size()); - for (ShardOperationFailedException failure : failures) { + for (Failure failure : failures) { failure.writeTo(out); } } @@ -357,7 +356,7 @@ public class IndicesShardStoresResponse extends ActionResponse implements ToXCon public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (failures.size() > 0) { builder.startArray(Fields.FAILURES); - for (ShardOperationFailedException failure : failures) { + for (Failure failure : failures) { builder.startObject(); failure.toXContent(builder, params); builder.endObject(); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsResponse.java index 5fcd4e5e62e..24a0e10e866 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsResponse.java @@ -19,7 +19,7 @@ package org.elasticsearch.action.admin.indices.stats; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.io.stream.StreamInput; @@ -48,7 +48,8 @@ public class IndicesStatsResponse extends BroadcastResponse implements ToXConten } - IndicesStatsResponse(ShardStats[] shards, int totalShards, int successfulShards, int failedShards, List shardFailures) { + IndicesStatsResponse(ShardStats[] shards, int totalShards, int successfulShards, int failedShards, + List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); this.shards = shards; } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java index bed820189d1..50d7712da11 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java @@ -19,8 +19,8 @@ package org.elasticsearch.action.admin.indices.stats; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -79,7 +79,7 @@ public class TransportIndicesStatsAction extends TransportBroadcastByNodeAction< } @Override - protected IndicesStatsResponse newResponse(IndicesStatsRequest request, int totalShards, int successfulShards, int failedShards, List responses, List shardFailures, ClusterState clusterState) { + protected IndicesStatsResponse newResponse(IndicesStatsRequest request, int totalShards, int successfulShards, int failedShards, List responses, List shardFailures, ClusterState clusterState) { return new IndicesStatsResponse(responses.toArray(new ShardStats[responses.size()]), totalShards, successfulShards, failedShards, shardFailures); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/TransportUpgradeStatusAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/TransportUpgradeStatusAction.java index c2c4424d4c8..19566acaf7a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/TransportUpgradeStatusAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/TransportUpgradeStatusAction.java @@ -20,8 +20,8 @@ package org.elasticsearch.action.admin.indices.upgrade.get; import org.elasticsearch.Version; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -79,7 +79,7 @@ public class TransportUpgradeStatusAction extends TransportBroadcastByNodeAction } @Override - protected UpgradeStatusResponse newResponse(UpgradeStatusRequest request, int totalShards, int successfulShards, int failedShards, List responses, List shardFailures, ClusterState clusterState) { + protected UpgradeStatusResponse newResponse(UpgradeStatusRequest request, int totalShards, int successfulShards, int failedShards, List responses, List shardFailures, ClusterState clusterState) { return new UpgradeStatusResponse(responses.toArray(new ShardUpgradeStatus[responses.size()]), totalShards, successfulShards, failedShards, shardFailures); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/UpgradeStatusResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/UpgradeStatusResponse.java index 565348f5ac2..71110f18b87 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/UpgradeStatusResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/UpgradeStatusResponse.java @@ -19,11 +19,10 @@ package org.elasticsearch.action.admin.indices.upgrade.get; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ToXContent.Params; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -43,7 +42,8 @@ public class UpgradeStatusResponse extends BroadcastResponse implements ToXConte UpgradeStatusResponse() { } - UpgradeStatusResponse(ShardUpgradeStatus[] shards, int totalShards, int successfulShards, int failedShards, List shardFailures) { + UpgradeStatusResponse(ShardUpgradeStatus[] shards, int totalShards, int successfulShards, int failedShards, + List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); this.shards = shards; } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/TransportUpgradeAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/TransportUpgradeAction.java index 87f39336047..67e51c8e557 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/TransportUpgradeAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/TransportUpgradeAction.java @@ -22,8 +22,8 @@ package org.elasticsearch.action.admin.indices.upgrade.post; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.PrimaryMissingActionException; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -71,7 +71,7 @@ public class TransportUpgradeAction extends TransportBroadcastByNodeAction shardUpgradeResults, List shardFailures, ClusterState clusterState) { + protected UpgradeResponse newResponse(UpgradeRequest request, int totalShards, int successfulShards, int failedShards, List shardUpgradeResults, List shardFailures, ClusterState clusterState) { Map successfulPrimaryShards = new HashMap<>(); Map> versions = new HashMap<>(); for (ShardUpgradeResult result : shardUpgradeResults) { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/UpgradeResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/UpgradeResponse.java index 64e958372cd..db49921d435 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/UpgradeResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/UpgradeResponse.java @@ -20,7 +20,7 @@ package org.elasticsearch.action.admin.indices.upgrade.post; import org.elasticsearch.Version; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.stream.StreamInput; @@ -44,7 +44,8 @@ public class UpgradeResponse extends BroadcastResponse { } - UpgradeResponse(Map> versions, int totalShards, int successfulShards, int failedShards, List shardFailures) { + UpgradeResponse(Map> versions, int totalShards, int successfulShards, int failedShards, + List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); this.versions = versions; } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java index c4369a30586..0513a37e4fe 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java @@ -22,7 +22,6 @@ package org.elasticsearch.action.admin.indices.validate.query; import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException; @@ -115,7 +114,7 @@ public class TransportValidateQueryAction extends TransportBroadcastAction shardFailures = null; + List shardFailures = null; List queryExplanations = null; for (int i = 0; i < shardsResponses.length(); i++) { Object shardResponse = shardsResponses.get(i); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryResponse.java index 2d3c0a0a90e..eff37ff4b0c 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryResponse.java @@ -19,7 +19,7 @@ package org.elasticsearch.action.admin.indices.validate.query; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -46,7 +46,8 @@ public class ValidateQueryResponse extends BroadcastResponse { } - ValidateQueryResponse(boolean valid, List queryExplanations, int totalShards, int successfulShards, int failedShards, List shardFailures) { + ValidateQueryResponse(boolean valid, List queryExplanations, int totalShards, int successfulShards, int failedShards, + List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); this.valid = valid; this.queryExplanations = queryExplanations; diff --git a/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastResponse.java b/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastResponse.java index e608e8e0ab7..2baf5a1d50e 100644 --- a/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastResponse.java +++ b/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastResponse.java @@ -20,11 +20,10 @@ package org.elasticsearch.action.support.broadcast; import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.index.shard.ShardNotFoundException; import java.io.IOException; import java.util.List; @@ -35,30 +34,24 @@ import static org.elasticsearch.action.support.DefaultShardOperationFailedExcept * Base class for all broadcast operation based responses. */ public class BroadcastResponse extends ActionResponse { - private static final ShardOperationFailedException[] EMPTY = new ShardOperationFailedException[0]; + private static final DefaultShardOperationFailedException[] EMPTY = new DefaultShardOperationFailedException[0]; private int totalShards; private int successfulShards; private int failedShards; - private ShardOperationFailedException[] shardFailures = EMPTY; + private DefaultShardOperationFailedException[] shardFailures = EMPTY; public BroadcastResponse() { } public BroadcastResponse(int totalShards, int successfulShards, int failedShards, - List shardFailures) { - assertNoShardNotAvailableFailures(shardFailures); + List shardFailures) { this.totalShards = totalShards; this.successfulShards = successfulShards; this.failedShards = failedShards; - this.shardFailures = shardFailures == null ? EMPTY : - shardFailures.toArray(new ShardOperationFailedException[shardFailures.size()]); - } - - private void assertNoShardNotAvailableFailures(List shardFailures) { - if (shardFailures != null) { - for (Object e : shardFailures) { - assert (e instanceof ShardNotFoundException) == false : "expected no ShardNotFoundException failures, but got " + e; - } + if (shardFailures == null) { + this.shardFailures = EMPTY; + } else { + this.shardFailures = shardFailures.toArray(new DefaultShardOperationFailedException[shardFailures.size()]); } } @@ -97,7 +90,7 @@ public class BroadcastResponse extends ActionResponse { /** * The list of shard failures exception. */ - public ShardOperationFailedException[] getShardFailures() { + public DefaultShardOperationFailedException[] getShardFailures() { return shardFailures; } @@ -109,7 +102,7 @@ public class BroadcastResponse extends ActionResponse { failedShards = in.readVInt(); int size = in.readVInt(); if (size > 0) { - shardFailures = new ShardOperationFailedException[size]; + shardFailures = new DefaultShardOperationFailedException[size]; for (int i = 0; i < size; i++) { shardFailures[i] = readShardOperationFailed(in); } @@ -123,7 +116,7 @@ public class BroadcastResponse extends ActionResponse { out.writeVInt(successfulShards); out.writeVInt(failedShards); out.writeVInt(shardFailures.length); - for (ShardOperationFailedException exp : shardFailures) { + for (DefaultShardOperationFailedException exp : shardFailures) { exp.writeTo(out); } } diff --git a/server/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java b/server/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java index 3ef967472a5..b6eaa5163c8 100644 --- a/server/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java @@ -24,7 +24,6 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.NoShardAvailableActionException; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.HandledTransportAction; @@ -131,7 +130,7 @@ public abstract class TransportBroadcastByNodeAction broadcastByNodeResponses = new ArrayList<>(); - List exceptions = new ArrayList<>(); + List exceptions = new ArrayList<>(); for (int i = 0; i < responses.length(); i++) { if (responses.get(i) instanceof FailedNodeException) { FailedNodeException exception = (FailedNodeException) responses.get(i); @@ -176,7 +175,7 @@ public abstract class TransportBroadcastByNodeAction results, List shardFailures, ClusterState clusterState); + protected abstract Response newResponse(Request request, int totalShards, int successfulShards, int failedShards, List results, List shardFailures, ClusterState clusterState); /** * Deserialize a request from an input stream diff --git a/server/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java b/server/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java index 8193cf77ceb..4cad1c21170 100644 --- a/server/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java @@ -22,7 +22,6 @@ package org.elasticsearch.action.support.replication; import com.carrotsearch.hppc.cursors.IntObjectCursor; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.HandledTransportAction; @@ -76,7 +75,7 @@ public abstract class TransportBroadcastReplicationAction listener) { final ClusterState clusterState = clusterService.state(); List shards = shards(request, clusterState); - final CopyOnWriteArrayList shardsResponses = new CopyOnWriteArrayList(); + final CopyOnWriteArrayList shardsResponses = new CopyOnWriteArrayList<>(); if (shards.size() == 0) { finishAndNotifyListener(listener, shardsResponses); } @@ -148,7 +147,7 @@ public abstract class TransportBroadcastReplicationAction shardFailures = null; + List shardFailures = null; for (int i = 0; i < shardsResponses.size(); i++) { ReplicationResponse shardResponse = shardsResponses.get(i); if (shardResponse == null) { @@ -168,5 +167,6 @@ public abstract class TransportBroadcastReplicationAction shardFailures); + protected abstract BroadcastResponse newResponse(int successfulShards, int failedShards, int totalNumCopies, + List shardFailures); } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsTests.java index be84a888064..26785d2c870 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsTests.java @@ -20,8 +20,8 @@ package org.elasticsearch.action.admin.indices.stats; import org.elasticsearch.action.ActionFuture; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; @@ -31,7 +31,6 @@ import org.elasticsearch.index.engine.CommitStats; import org.elasticsearch.index.engine.SegmentsStats; import org.elasticsearch.index.translog.Translog; import org.elasticsearch.test.ESSingleNodeTestCase; -import org.elasticsearch.test.junit.annotations.TestLogging; import java.util.List; import java.util.concurrent.TimeUnit; @@ -158,7 +157,7 @@ public class IndicesStatsTests extends ESSingleNodeTestCase { * Gives access to package private IndicesStatsResponse constructor for test purpose. **/ public static IndicesStatsResponse newIndicesStatsResponse(ShardStats[] shards, int totalShards, int successfulShards, - int failedShards, List shardFailures) { + int failedShards, List shardFailures) { return new IndicesStatsResponse(shards, totalShards, successfulShards, failedShards, shardFailures); } diff --git a/server/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java b/server/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java index 470da323043..6a7d4435538 100644 --- a/server/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java @@ -22,8 +22,8 @@ package org.elasticsearch.action.support.broadcast.node; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.IndicesRequest; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.action.support.broadcast.BroadcastRequest; import org.elasticsearch.action.support.broadcast.BroadcastResponse; @@ -109,7 +109,7 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase { public Response() { } - public Response(int totalShards, int successfulShards, int failedShards, List shardFailures) { + public Response(int totalShards, int successfulShards, int failedShards, List shardFailures) { super(totalShards, successfulShards, failedShards, shardFailures); } } @@ -127,7 +127,7 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase { } @Override - protected Response newResponse(Request request, int totalShards, int successfulShards, int failedShards, List emptyResults, List shardFailures, ClusterState clusterState) { + protected Response newResponse(Request request, int totalShards, int successfulShards, int failedShards, List emptyResults, List shardFailures, ClusterState clusterState) { return new Response(totalShards, successfulShards, failedShards, shardFailures); } diff --git a/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java b/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java index 3aeab0fa5fb..15d7f6d7c59 100644 --- a/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java @@ -21,12 +21,12 @@ package org.elasticsearch.action.support.replication; import org.apache.lucene.util.IOUtils; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.NoShardAvailableActionException; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.UnavailableShardsException; import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.admin.indices.flush.TransportFlushAction; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastRequest; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.cluster.ClusterState; @@ -221,7 +221,7 @@ public class BroadcastReplicationTests extends ESTestCase { @Override protected BroadcastResponse newResponse(int successfulShards, int failedShards, int totalNumCopies, - List shardFailures) { + List shardFailures) { return new BroadcastResponse(totalNumCopies, successfulShards, failedShards, shardFailures); } diff --git a/server/src/test/java/org/elasticsearch/get/GetActionIT.java b/server/src/test/java/org/elasticsearch/get/GetActionIT.java index d468d58212d..911e26528c9 100644 --- a/server/src/test/java/org/elasticsearch/get/GetActionIT.java +++ b/server/src/test/java/org/elasticsearch/get/GetActionIT.java @@ -21,7 +21,6 @@ package org.elasticsearch.get; import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteResponse; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.delete.DeleteResponse; @@ -30,6 +29,7 @@ import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetRequest; import org.elasticsearch.action.get.MultiGetRequestBuilder; import org.elasticsearch.action.get.MultiGetResponse; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -748,7 +748,7 @@ public class GetActionIT extends ESIntegTestCase { if (flushResponse.getSuccessfulShards() == 0) { StringBuilder sb = new StringBuilder("failed to flush at least one shard. total shards [") .append(flushResponse.getTotalShards()).append("], failed shards: [").append(flushResponse.getFailedShards()).append("]"); - for (ShardOperationFailedException failure: flushResponse.getShardFailures()) { + for (DefaultShardOperationFailedException failure: flushResponse.getShardFailures()) { sb.append("\nShard failure: ").append(failure); } fail(sb.toString()); diff --git a/server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java b/server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java index dd4635d30f2..f25a9234698 100644 --- a/server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java +++ b/server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java @@ -22,7 +22,6 @@ package org.elasticsearch.indices.stats; import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteResponse; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.stats.CommonStats; @@ -37,6 +36,7 @@ import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -1113,7 +1113,8 @@ public class IndexStatsIT extends ESIntegTestCase { final CountDownLatch latch = new CountDownLatch(1); final AtomicBoolean failed = new AtomicBoolean(); - final AtomicReference> shardFailures = new AtomicReference<>(new CopyOnWriteArrayList<>()); + final AtomicReference> shardFailures = + new AtomicReference<>(new CopyOnWriteArrayList<>()); final AtomicReference> executionFailures = new AtomicReference<>(new CopyOnWriteArrayList<>()); // increasing the number of shards increases the number of chances any one stats request will hit a race @@ -1191,7 +1192,7 @@ public class IndexStatsIT extends ESIntegTestCase { thread.join(); } - assertThat(shardFailures.get(), emptyCollectionOf(ShardOperationFailedException.class)); + assertThat(shardFailures.get(), emptyCollectionOf(DefaultShardOperationFailedException.class)); assertThat(executionFailures.get(), emptyCollectionOf(Exception.class)); } diff --git a/server/src/test/java/org/elasticsearch/rest/action/cat/RestRecoveryActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/cat/RestRecoveryActionTests.java index 148af7f7d87..ffebd804c60 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/cat/RestRecoveryActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/cat/RestRecoveryActionTests.java @@ -19,8 +19,8 @@ package org.elasticsearch.rest.action.cat; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource; @@ -110,7 +110,7 @@ public class RestRecoveryActionTests extends ESTestCase { Randomness.shuffle(shuffle); shardRecoveryStates.put("index", shuffle); - final List shardFailures = new ArrayList<>(); + final List shardFailures = new ArrayList<>(); final RecoveryResponse response = new RecoveryResponse( totalShards, successfulShards, diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index e633f5adb70..0097621e062 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -32,7 +32,6 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.DocWriteResponse; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; @@ -62,6 +61,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.search.ClearScrollResponse; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; @@ -1275,7 +1275,7 @@ public abstract class ESIntegTestCase extends ESTestCase { protected final FlushResponse flush(String... indices) { waitForRelocation(); FlushResponse actionGet = client().admin().indices().prepareFlush(indices).execute().actionGet(); - for (ShardOperationFailedException failure : actionGet.getShardFailures()) { + for (DefaultShardOperationFailedException failure : actionGet.getShardFailures()) { assertThat("unexpected flush failure " + failure.reason(), failure.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE)); } return actionGet; diff --git a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index 4eaaa96df76..ff31240169e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -27,7 +27,6 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestBuilder; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse; @@ -41,6 +40,7 @@ import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.ShardSearchFailure; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder; import org.elasticsearch.action.support.master.AcknowledgedResponse; @@ -163,7 +163,7 @@ public class ElasticsearchAssertions { * */ public static void assertBlocked(BroadcastResponse replicatedBroadcastResponse) { assertThat("all shard requests should have failed", replicatedBroadcastResponse.getFailedShards(), Matchers.equalTo(replicatedBroadcastResponse.getTotalShards())); - for (ShardOperationFailedException exception : replicatedBroadcastResponse.getShardFailures()) { + for (DefaultShardOperationFailedException exception : replicatedBroadcastResponse.getShardFailures()) { ClusterBlockException clusterBlockException = (ClusterBlockException) ExceptionsHelper.unwrap(exception.getCause(), ClusterBlockException.class); assertNotNull("expected the cause of failure to be a ClusterBlockException but got " + exception.getCause().getMessage(), clusterBlockException); assertThat(clusterBlockException.blocks().size(), greaterThan(0)); @@ -203,7 +203,7 @@ public class ElasticsearchAssertions { msg.append(" Total shards: ").append(response.getTotalShards()) .append(" Successful shards: ").append(response.getSuccessfulShards()) .append(" & ").append(response.getFailedShards()).append(" shard failures:"); - for (ShardOperationFailedException failure : response.getShardFailures()) { + for (DefaultShardOperationFailedException failure : response.getShardFailures()) { msg.append("\n ").append(failure); } return msg.toString();