diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml
index a089d677dc9a5..6593527f23c04 100644
--- a/buildSrc/src/main/resources/checkstyle_suppressions.xml
+++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml
@@ -256,7 +256,6 @@
-
@@ -564,8 +563,6 @@
-
-
@@ -654,7 +651,6 @@
-
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java
index 9cbc1b6563242..ae715050e80b5 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java
@@ -42,7 +42,7 @@
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
+import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
/**
* Create snapshot request
@@ -366,14 +366,14 @@ public CreateSnapshotRequest source(Map source) {
throw new IllegalArgumentException("malformed indices section, should be an array of strings");
}
} else if (name.equals("partial")) {
- partial(lenientNodeBooleanValue(entry.getValue()));
+ partial(nodeBooleanValue(entry.getValue(), "partial"));
} else if (name.equals("settings")) {
if (!(entry.getValue() instanceof Map)) {
throw new IllegalArgumentException("malformed settings section, should indices an inner object");
}
settings((Map) entry.getValue());
} else if (name.equals("include_global_state")) {
- includeGlobalState = lenientNodeBooleanValue(entry.getValue());
+ includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state");
}
}
indicesOptions(IndicesOptions.fromMap((Map) source, IndicesOptions.lenientExpandOpen()));
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java
index 641525f00e8bd..a7bbd02ee54eb 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java
@@ -40,7 +40,7 @@
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
+import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
/**
* Restore snapshot request
@@ -481,16 +481,16 @@ public RestoreSnapshotRequest source(Map source) {
throw new IllegalArgumentException("malformed indices section, should be an array of strings");
}
} else if (name.equals("partial")) {
- partial(lenientNodeBooleanValue(entry.getValue()));
+ partial(nodeBooleanValue(entry.getValue(), "partial"));
} else if (name.equals("settings")) {
if (!(entry.getValue() instanceof Map)) {
throw new IllegalArgumentException("malformed settings section");
}
settings((Map) entry.getValue());
} else if (name.equals("include_global_state")) {
- includeGlobalState = lenientNodeBooleanValue(entry.getValue());
+ includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state");
} else if (name.equals("include_aliases")) {
- includeAliases = lenientNodeBooleanValue(entry.getValue());
+ includeAliases = nodeBooleanValue(entry.getValue(), "include_aliases");
} else if (name.equals("rename_pattern")) {
if (entry.getValue() instanceof String) {
renamePattern((String) entry.getValue());
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java
index b04bb86a63c28..026946334ac6a 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java
@@ -23,7 +23,7 @@
import org.elasticsearch.action.support.replication.ReplicationResponse;
import org.elasticsearch.action.support.replication.TransportReplicationAction;
import org.elasticsearch.cluster.action.shard.ShardStateAction;
-import org.elasticsearch.cluster.block.ClusterBlockLevel;
+import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
@@ -65,7 +65,7 @@ protected ReplicaResult shardOperationOnReplica(ShardFlushRequest request, Index
}
@Override
- protected boolean shouldExecuteReplication(Settings settings) {
+ protected boolean shouldExecuteReplication(IndexMetaData indexMetaData) {
return true;
}
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java
index d8e9d8c0b9e72..d1d8b4078b647 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java
@@ -24,7 +24,7 @@
import org.elasticsearch.action.support.replication.ReplicationResponse;
import org.elasticsearch.action.support.replication.TransportReplicationAction;
import org.elasticsearch.cluster.action.shard.ShardStateAction;
-import org.elasticsearch.cluster.block.ClusterBlockLevel;
+import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
@@ -68,7 +68,7 @@ protected ReplicaResult shardOperationOnReplica(BasicReplicationRequest request,
}
@Override
- protected boolean shouldExecuteReplication(Settings settings) {
+ protected boolean shouldExecuteReplication(IndexMetaData indexMetaData) {
return true;
}
}
diff --git a/core/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java b/core/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java
index 5407184ded31a..d4627391b1169 100644
--- a/core/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java
@@ -379,7 +379,8 @@ public static void parseDocuments(XContentParser parser, List items, @Null
} else if ("_version_type".equals(currentFieldName) || "_versionType".equals(currentFieldName) || "version_type".equals(currentFieldName) || "versionType".equals(currentFieldName)) {
versionType = VersionType.fromString(parser.text());
} else if ("_source".equals(currentFieldName)) {
- if (parser.isBooleanValue()) {
+ // check lenient to avoid interpreting the value as string but parse strict in order to provoke an error early on.
+ if (parser.isBooleanValueLenient()) {
fetchSourceContext = new FetchSourceContext(parser.booleanValue(), fetchSourceContext.includes(),
fetchSourceContext.excludes());
} else if (token == XContentParser.Token.VALUE_STRING) {
diff --git a/core/src/main/java/org/elasticsearch/action/get/TransportGetAction.java b/core/src/main/java/org/elasticsearch/action/get/TransportGetAction.java
index 6b9de7ecf64e3..ee835fa06be5e 100644
--- a/core/src/main/java/org/elasticsearch/action/get/TransportGetAction.java
+++ b/core/src/main/java/org/elasticsearch/action/get/TransportGetAction.java
@@ -71,7 +71,7 @@ protected void resolveRequest(ClusterState state, InternalRequest request) {
if (request.request().realtime && // if the realtime flag is set
request.request().preference() == null && // the preference flag is not already set
indexMeta != null && // and we have the index
- IndexMetaData.isIndexUsingShadowReplicas(indexMeta.getSettings())) { // and the index uses shadow replicas
+ indexMeta.isIndexUsingShadowReplicas()) { // and the index uses shadow replicas
// set the preference for the request to use "_primary" automatically
request.request().preference(Preference.PRIMARY.type());
}
diff --git a/core/src/main/java/org/elasticsearch/action/support/AutoCreateIndex.java b/core/src/main/java/org/elasticsearch/action/support/AutoCreateIndex.java
index a9a5afed9f315..be039d80d9f73 100644
--- a/core/src/main/java/org/elasticsearch/action/support/AutoCreateIndex.java
+++ b/core/src/main/java/org/elasticsearch/action/support/AutoCreateIndex.java
@@ -106,7 +106,7 @@ private AutoCreate(String value) {
boolean autoCreateIndex;
List> expressions = new ArrayList<>();
try {
- autoCreateIndex = Booleans.parseBooleanExact(value);
+ autoCreateIndex = Booleans.parseBoolean(value);
} catch (IllegalArgumentException ex) {
try {
String[] patterns = Strings.commaDelimitedListToStringArray(value);
diff --git a/core/src/main/java/org/elasticsearch/action/support/IndicesOptions.java b/core/src/main/java/org/elasticsearch/action/support/IndicesOptions.java
index 2bc49f7e9f869..b82bfcc7170d8 100644
--- a/core/src/main/java/org/elasticsearch/action/support/IndicesOptions.java
+++ b/core/src/main/java/org/elasticsearch/action/support/IndicesOptions.java
@@ -26,7 +26,7 @@
import java.io.IOException;
import java.util.Map;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
+import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringArrayValue;
/**
@@ -195,8 +195,8 @@ public static IndicesOptions fromParameters(Object wildcardsString, Object ignor
//note that allowAliasesToMultipleIndices is not exposed, always true (only for internal use)
return fromOptions(
- lenientNodeBooleanValue(ignoreUnavailableString, defaultSettings.ignoreUnavailable()),
- lenientNodeBooleanValue(allowNoIndicesString, defaultSettings.allowNoIndices()),
+ nodeBooleanValue(ignoreUnavailableString, "ignore_unavailable", defaultSettings.ignoreUnavailable()),
+ nodeBooleanValue(allowNoIndicesString, "allow_no_indices", defaultSettings.allowNoIndices()),
expandWildcardsOpen,
expandWildcardsClosed,
defaultSettings.allowAliasesToMultipleIndices(),
@@ -279,7 +279,7 @@ public String toString() {
", allow_no_indices=" + allowNoIndices() +
", expand_wildcards_open=" + expandWildcardsOpen() +
", expand_wildcards_closed=" + expandWildcardsClosed() +
- ", allow_alisases_to_multiple_indices=" + allowAliasesToMultipleIndices() +
+ ", allow_aliases_to_multiple_indices=" + allowAliasesToMultipleIndices() +
", forbid_closed_indices=" + forbidClosedIndices() +
']';
}
diff --git a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java
index d3646ac98e7c2..6fec41ff9a3cd 100644
--- a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java
+++ b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java
@@ -315,7 +315,7 @@ public void handleException(TransportException exp) {
} else {
setPhase(replicationTask, "primary");
final IndexMetaData indexMetaData = clusterService.state().getMetaData().index(request.shardId().getIndex());
- final boolean executeOnReplicas = (indexMetaData == null) || shouldExecuteReplication(indexMetaData.getSettings());
+ final boolean executeOnReplicas = (indexMetaData == null) || shouldExecuteReplication(indexMetaData);
final ActionListener listener = createResponseListener(primaryShardReference);
createReplicatedOperation(request,
ActionListener.wrap(result -> result.respond(listener), listener::onFailure),
@@ -914,8 +914,8 @@ public void onFailure(Exception e) {
* Indicated whether this operation should be replicated to shadow replicas or not. If this method returns true the replication phase
* will be skipped. For example writes such as index and delete don't need to be replicated on shadow replicas but refresh and flush do.
*/
- protected boolean shouldExecuteReplication(Settings settings) {
- return IndexMetaData.isIndexUsingShadowReplicas(settings) == false;
+ protected boolean shouldExecuteReplication(IndexMetaData indexMetaData) {
+ return indexMetaData.isIndexUsingShadowReplicas() == false;
}
class ShardReference implements Releasable {
diff --git a/core/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java b/core/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java
index b8ac2a5eb50c3..a9392d3c017de 100644
--- a/core/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java
@@ -377,14 +377,13 @@ static void buildShardLevelInfo(Logger logger, ShardStats[] stats, ImmutableOpen
MetaData meta = state.getMetaData();
for (ShardStats s : stats) {
IndexMetaData indexMeta = meta.index(s.getShardRouting().index());
- Settings indexSettings = indexMeta == null ? null : indexMeta.getSettings();
newShardRoutingToDataPath.put(s.getShardRouting(), s.getDataPath());
long size = s.getStats().getStore().sizeInBytes();
String sid = ClusterInfo.shardIdentifierFromRouting(s.getShardRouting());
if (logger.isTraceEnabled()) {
logger.trace("shard: {} size: {}", sid, size);
}
- if (indexSettings != null && IndexMetaData.isIndexUsingShadowReplicas(indexSettings)) {
+ if (indexMeta != null && indexMeta.isIndexUsingShadowReplicas()) {
// Shards on a shared filesystem should be considered of size 0
if (logger.isTraceEnabled()) {
logger.trace("shard: {} is using shadow replicas and will be treated as size 0", sid);
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java b/core/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java
index 4b4a8e54d7c6c..fa30abe5a736b 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java
@@ -33,7 +33,7 @@ final class AutoExpandReplicas {
public static final Setting SETTING = new Setting<>(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "false", (value) -> {
final int min;
final int max;
- if (Booleans.parseBoolean(value, true) == false) {
+ if (Booleans.isFalse(value)) {
return new AutoExpandReplicas(0, 0, false);
}
final int dash = value.indexOf('-');
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java
index ba5ce1067b3bb..6865983e180c7 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java
@@ -1263,9 +1263,10 @@ public static IndexMetaData fromXContent(XContentParser parser) throws IOExcepti
* is the returned value from
* {@link #isIndexUsingShadowReplicas(org.elasticsearch.common.settings.Settings)}.
*/
- public static boolean isOnSharedFilesystem(Settings settings) {
+ public boolean isOnSharedFilesystem(Settings settings) {
// don't use the setting directly, not to trigger verbose deprecation logging
- return settings.getAsBoolean(SETTING_SHARED_FILESYSTEM, isIndexUsingShadowReplicas(settings));
+ return settings.getAsBooleanLenientForPreEs6Indices(
+ this.indexCreatedVersion, SETTING_SHARED_FILESYSTEM, isIndexUsingShadowReplicas(settings));
}
/**
@@ -1273,9 +1274,13 @@ public static boolean isOnSharedFilesystem(Settings settings) {
* with these settings uses shadow replicas. Otherwise false. The default
* setting for this is false.
*/
- public static boolean isIndexUsingShadowReplicas(Settings settings) {
+ public boolean isIndexUsingShadowReplicas() {
+ return isIndexUsingShadowReplicas(this.settings);
+ }
+
+ public boolean isIndexUsingShadowReplicas(Settings settings) {
// don't use the setting directly, not to trigger verbose deprecation logging
- return settings.getAsBoolean(SETTING_SHADOW_REPLICAS, false);
+ return settings.getAsBooleanLenientForPreEs6Indices(this.indexCreatedVersion, SETTING_SHADOW_REPLICAS, false);
}
/**
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java
index c9a0c6175532b..08d5211e12d74 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java
@@ -34,7 +34,7 @@
import java.io.IOException;
import java.util.Map;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
+import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
/**
* Mapping configuration for a type.
@@ -95,10 +95,6 @@ public MappingMetaData(CompressedXContent mapping) throws IOException {
initMappers((Map) mappingMap.get(this.type));
}
- public MappingMetaData(Map mapping) throws IOException {
- this(mapping.keySet().iterator().next(), mapping);
- }
-
public MappingMetaData(String type, Map mapping) throws IOException {
this.type = type;
XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().map(mapping);
@@ -127,7 +123,12 @@ private void initMappers(Map withoutType) {
String fieldName = entry.getKey();
Object fieldNode = entry.getValue();
if (fieldName.equals("required")) {
- required = lenientNodeBooleanValue(fieldNode);
+ try {
+ required = nodeBooleanValue(fieldNode);
+ } catch (IllegalArgumentException ex) {
+ throw new IllegalArgumentException("Failed to create mapping for type [" + this.type() + "]. " +
+ "Illegal value in field [_routing.required].", ex);
+ }
}
}
this.routing = new Routing(required);
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
index 64f96c8e263bb..7015695948930 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
@@ -428,7 +428,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {
.put(indexMetaData, false)
.build();
- String maybeShadowIndicator = IndexMetaData.isIndexUsingShadowReplicas(indexMetaData.getSettings()) ? "s" : "";
+ String maybeShadowIndicator = indexMetaData.isIndexUsingShadowReplicas() ? "s" : "";
logger.info("[{}] creating index, cause [{}], templates {}, shards [{}]/[{}{}], mappings {}",
request.index(), request.cause(), templateNames, indexMetaData.getNumberOfShards(),
indexMetaData.getNumberOfReplicas(), maybeShadowIndicator, mappings.keySet());
diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java
index 1d137d30dba37..53590550d84df 100644
--- a/core/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java
+++ b/core/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java
@@ -140,7 +140,7 @@ boolean validate(MetaData metaData) {
}
if (indexMetaData.getCreationVersion().onOrAfter(Version.V_5_0_0_alpha1) &&
- IndexMetaData.isIndexUsingShadowReplicas(indexMetaData.getSettings()) == false && // see #20650
+ indexMetaData.isIndexUsingShadowReplicas() == false && // see #20650
shardRouting.primary() && shardRouting.initializing() && shardRouting.relocating() == false &&
RecoverySource.isInitialRecovery(shardRouting.recoverySource().getType()) == false &&
inSyncAllocationIds.contains(shardRouting.allocationId().getId()) == false)
diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java
index 6b0b13247170b..45d567b657e9b 100644
--- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java
+++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java
@@ -540,7 +540,7 @@ assert getByAllocationId(failedShard.shardId(), failedShard.allocationId().getId
if (failedShard.primary()) {
// promote active replica to primary if active replica exists (only the case for shadow replicas)
ShardRouting activeReplica = activeReplica(failedShard.shardId());
- assert activeReplica == null || IndexMetaData.isIndexUsingShadowReplicas(indexMetaData.getSettings()) :
+ assert activeReplica == null || indexMetaData.isIndexUsingShadowReplicas() :
"initializing primary [" + failedShard + "] with active replicas [" + activeReplica + "] only expected when " +
"using shadow replicas";
if (activeReplica == null) {
@@ -599,7 +599,7 @@ private void promoteReplicaToPrimary(ShardRouting activeReplica, IndexMetaData i
assert activeReplica.started() : "replica relocation should have been cancelled: " + activeReplica;
ShardRouting primarySwappedCandidate = promoteActiveReplicaShardToPrimary(activeReplica);
routingChangesObserver.replicaPromoted(activeReplica);
- if (IndexMetaData.isIndexUsingShadowReplicas(indexMetaData.getSettings())) {
+ if (indexMetaData.isIndexUsingShadowReplicas()) {
ShardRouting initializedShard = reinitShadowPrimary(primarySwappedCandidate);
routingChangesObserver.startedPrimaryReinitialized(primarySwappedCandidate, initializedShard);
}
diff --git a/core/src/main/java/org/elasticsearch/common/Booleans.java b/core/src/main/java/org/elasticsearch/common/Booleans.java
index 9ec1ac968aca6..025174c477d64 100644
--- a/core/src/main/java/org/elasticsearch/common/Booleans.java
+++ b/core/src/main/java/org/elasticsearch/common/Booleans.java
@@ -19,34 +19,28 @@
package org.elasticsearch.common;
-public class Booleans {
+public final class Booleans {
+ private Booleans() {
+ throw new AssertionError("No instances intended");
+ }
/**
- * Returns false if text is in false, 0, off, no; else, true
+ * Parses a char[] representation of a boolean value to boolean.
+ *
+ * @return true iff the sequence of chars is "true", false iff the sequence of chars is "false" or the
+ * provided default value iff either text is null or length == 0.
+ * @throws IllegalArgumentException if the string cannot be parsed to boolean.
*/
public static boolean parseBoolean(char[] text, int offset, int length, boolean defaultValue) {
- // TODO: the leniency here is very dangerous: a simple typo will be misinterpreted and the user won't know.
- // We should remove it and cutover to https://github.com/rmuir/booleanparser
if (text == null || length == 0) {
return defaultValue;
+ } else {
+ return parseBoolean(new String(text, offset, length));
}
- if (length == 1) {
- return text[offset] != '0';
- }
- if (length == 2) {
- return !(text[offset] == 'n' && text[offset + 1] == 'o');
- }
- if (length == 3) {
- return !(text[offset] == 'o' && text[offset + 1] == 'f' && text[offset + 2] == 'f');
- }
- if (length == 5) {
- return !(text[offset] == 'f' && text[offset + 1] == 'a' && text[offset + 2] == 'l' && text[offset + 3] == 's' && text[offset + 4] == 'e');
- }
- return true;
}
/**
- * returns true if the a sequence of chars is one of "true","false","on","off","yes","no","0","1"
+ * returns true iff the sequence of chars is one of "true","false".
*
* @param text sequence to check
* @param offset offset to start
@@ -56,55 +50,70 @@ public static boolean isBoolean(char[] text, int offset, int length) {
if (text == null || length == 0) {
return false;
}
- if (length == 1) {
- return text[offset] == '0' || text[offset] == '1';
- }
- if (length == 2) {
- return (text[offset] == 'n' && text[offset + 1] == 'o') || (text[offset] == 'o' && text[offset + 1] == 'n');
- }
- if (length == 3) {
- return (text[offset] == 'o' && text[offset + 1] == 'f' && text[offset + 2] == 'f') ||
- (text[offset] == 'y' && text[offset + 1] == 'e' && text[offset + 2] == 's');
- }
- if (length == 4) {
- return (text[offset] == 't' && text[offset + 1] == 'r' && text[offset + 2] == 'u' && text[offset + 3] == 'e');
- }
- if (length == 5) {
- return (text[offset] == 'f' && text[offset + 1] == 'a' && text[offset + 2] == 'l' && text[offset + 3] == 's' && text[offset + 4] == 'e');
- }
- return false;
+ return isBoolean(new String(text, offset, length));
+ }
+
+ public static boolean isBoolean(String value) {
+ return isFalse(value) || isTrue(value);
}
- /***
+ /**
+ * Parses a string representation of a boolean value to boolean.
*
- * @return true/false
- * throws exception if string cannot be parsed to boolean
+ * @return true iff the provided value is "true". false iff the provided value is "false".
+ * @throws IllegalArgumentException if the string cannot be parsed to boolean.
*/
- public static Boolean parseBooleanExact(String value) {
- boolean isFalse = isExplicitFalse(value);
- if (isFalse) {
+ public static boolean parseBoolean(String value) {
+ if (isFalse(value)) {
return false;
}
- boolean isTrue = isExplicitTrue(value);
- if (isTrue) {
+ if (isTrue(value)) {
return true;
}
+ throw new IllegalArgumentException("Failed to parse value [" + value + "] as only [true] or [false] are allowed.");
+ }
- throw new IllegalArgumentException("Failed to parse value [" + value + "] cannot be parsed to boolean [ true/1/on/yes OR false/0/off/no ]");
+ /**
+ *
+ * @param value text to parse.
+ * @param defaultValue The default value to return if the provided value is null.
+ * @return see {@link #parseBoolean(String)}
+ */
+ public static boolean parseBoolean(String value, boolean defaultValue) {
+ if (Strings.hasText(value)) {
+ return parseBoolean(value);
+ }
+ return defaultValue;
}
public static Boolean parseBoolean(String value, Boolean defaultValue) {
+ if (Strings.hasText(value)) {
+ return parseBoolean(value);
+ }
+ return defaultValue;
+ }
+
+ /**
+ * Returns false if text is in false, 0, off, no; else, true
+ *
+ * @deprecated Only kept to provide automatic upgrades for pre 6.0 indices. Use {@link #parseBoolean(String, Boolean)} instead.
+ */
+ @Deprecated
+ public static Boolean parseBooleanLenient(String value, Boolean defaultValue) {
if (value == null) { // only for the null case we do that here!
return defaultValue;
}
- return parseBoolean(value, false);
+ return parseBooleanLenient(value, false);
}
/**
* Returns true iff the value is neither of the following:
* false, 0, off, no
* otherwise false
+ *
+ * @deprecated Only kept to provide automatic upgrades for pre 6.0 indices. Use {@link #parseBoolean(String, boolean)} instead.
*/
- public static boolean parseBoolean(String value, boolean defaultValue) {
+ @Deprecated
+ public static boolean parseBooleanLenient(String value, boolean defaultValue) {
if (value == null) {
return defaultValue;
}
@@ -112,21 +121,77 @@ public static boolean parseBoolean(String value, boolean defaultValue) {
}
/**
- * Returns true iff the value is either of the following:
- * false, 0, off, no
- * otherwise false
+ * @return true iff the value is false, otherwise false.
*/
- public static boolean isExplicitFalse(String value) {
- return value != null && (value.equals("false") || value.equals("0") || value.equals("off") || value.equals("no"));
+ public static boolean isFalse(String value) {
+ return "false".equals(value);
}
/**
- * Returns true iff the value is either of the following:
- * true, 1, on, yes
- * otherwise false
+ * @return true iff the value is true, otherwise false
+ */
+ public static boolean isTrue(String value) {
+ return "true".equals(value);
+ }
+
+ /**
+ * Returns false if text is in false, 0, off, no; else, true
+ *
+ * @deprecated Only kept to provide automatic upgrades for pre 6.0 indices. Use {@link #parseBoolean(char[], int, int, boolean)} instead
+ */
+ @Deprecated
+ public static boolean parseBooleanLenient(char[] text, int offset, int length, boolean defaultValue) {
+ if (text == null || length == 0) {
+ return defaultValue;
+ }
+ if (length == 1) {
+ return text[offset] != '0';
+ }
+ if (length == 2) {
+ return !(text[offset] == 'n' && text[offset + 1] == 'o');
+ }
+ if (length == 3) {
+ return !(text[offset] == 'o' && text[offset + 1] == 'f' && text[offset + 2] == 'f');
+ }
+ if (length == 5) {
+ return !(text[offset] == 'f' && text[offset + 1] == 'a' && text[offset + 2] == 'l' && text[offset + 3] == 's' &&
+ text[offset + 4] == 'e');
+ }
+ return true;
+ }
+
+ /**
+ * returns true if the a sequence of chars is one of "true","false","on","off","yes","no","0","1"
+ *
+ * @param text sequence to check
+ * @param offset offset to start
+ * @param length length to check
+ *
+ * @deprecated Only kept to provide automatic upgrades for pre 6.0 indices. Use {@link #isBoolean(char[], int, int)} instead.
*/
- public static boolean isExplicitTrue(String value) {
- return value != null && (value.equals("true") || value.equals("1") || value.equals("on") || value.equals("yes"));
+ @Deprecated
+ public static boolean isBooleanLenient(char[] text, int offset, int length) {
+ if (text == null || length == 0) {
+ return false;
+ }
+ if (length == 1) {
+ return text[offset] == '0' || text[offset] == '1';
+ }
+ if (length == 2) {
+ return (text[offset] == 'n' && text[offset + 1] == 'o') || (text[offset] == 'o' && text[offset + 1] == 'n');
+ }
+ if (length == 3) {
+ return (text[offset] == 'o' && text[offset + 1] == 'f' && text[offset + 2] == 'f') ||
+ (text[offset] == 'y' && text[offset + 1] == 'e' && text[offset + 2] == 's');
+ }
+ if (length == 4) {
+ return (text[offset] == 't' && text[offset + 1] == 'r' && text[offset + 2] == 'u' && text[offset + 3] == 'e');
+ }
+ if (length == 5) {
+ return (text[offset] == 'f' && text[offset + 1] == 'a' && text[offset + 2] == 'l' && text[offset + 3] == 's' &&
+ text[offset + 4] == 'e');
+ }
+ return false;
}
}
diff --git a/core/src/main/java/org/elasticsearch/common/TriFunction.java b/core/src/main/java/org/elasticsearch/common/TriFunction.java
new file mode 100644
index 0000000000000..85655863a4f9e
--- /dev/null
+++ b/core/src/main/java/org/elasticsearch/common/TriFunction.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.elasticsearch.common;
+
+/**
+ * Represents a function that accepts three arguments and produces a result.
+ *
+ * @param the type of the first argument
+ * @param the type of the second argument
+ * @param the type of the third argument
+ * @param the return type
+ */
+@FunctionalInterface
+public interface TriFunction {
+ /**
+ * Applies this function to the given arguments.
+ *
+ * @param s the first function argument
+ * @param t the second function argument
+ * @param u the third function argument
+ * @return the result
+ */
+ R apply(S s, T t, U u);
+}
diff --git a/core/src/main/java/org/elasticsearch/common/settings/Setting.java b/core/src/main/java/org/elasticsearch/common/settings/Setting.java
index 45ebe1b061c62..74e10bd6e11b3 100644
--- a/core/src/main/java/org/elasticsearch/common/settings/Setting.java
+++ b/core/src/main/java/org/elasticsearch/common/settings/Setting.java
@@ -668,15 +668,15 @@ public static Setting intSetting(String key, int defaultValue, Property
}
public static Setting boolSetting(String key, boolean defaultValue, Property... properties) {
- return new Setting<>(key, (s) -> Boolean.toString(defaultValue), Booleans::parseBooleanExact, properties);
+ return new Setting<>(key, (s) -> Boolean.toString(defaultValue), Booleans::parseBoolean, properties);
}
public static Setting boolSetting(String key, Setting fallbackSetting, Property... properties) {
- return new Setting<>(key, fallbackSetting, Booleans::parseBooleanExact, properties);
+ return new Setting<>(key, fallbackSetting, Booleans::parseBoolean, properties);
}
public static Setting boolSetting(String key, Function defaultValueFn, Property... properties) {
- return new Setting<>(key, defaultValueFn, Booleans::parseBooleanExact, properties);
+ return new Setting<>(key, defaultValueFn, Booleans::parseBoolean, properties);
}
public static Setting byteSizeSetting(String key, ByteSizeValue value, Property... properties) {
diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java
index ef9ff00a1f029..e588b28b6354b 100644
--- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java
+++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java
@@ -26,6 +26,8 @@
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.common.logging.DeprecationLogger;
+import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.loader.SettingsLoader;
import org.elasticsearch.common.settings.loader.SettingsLoaderFactory;
import org.elasticsearch.common.unit.ByteSizeUnit;
@@ -74,6 +76,7 @@
* An immutable settings implementation.
*/
public final class Settings implements ToXContent {
+ private static final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(Settings.class));
public static final Settings EMPTY = new Builder().build();
private static final Pattern ARRAY_PATTERN = Pattern.compile("(.*)\\.\\d+$");
@@ -313,6 +316,32 @@ public Boolean getAsBoolean(String setting, Boolean defaultValue) {
return Booleans.parseBoolean(get(setting), defaultValue);
}
+ // TODO #22298: Delete this method and update call sites to #getAsBoolean(String, Boolean).
+ /**
+ * Returns the setting value (as boolean) associated with the setting key. If it does not exist, returns the default value provided.
+ * If the index was created on Elasticsearch below 6.0, booleans will be parsed leniently otherwise they are parsed strictly.
+ *
+ * See {@link Booleans#isBooleanLenient(char[], int, int)} for the definition of a "lenient boolean"
+ * and {@link Booleans#isBoolean(char[], int, int)} for the definition of a "strict boolean".
+ *
+ * @deprecated Only used to provide automatic upgrades for pre 6.0 indices.
+ */
+ @Deprecated
+ public Boolean getAsBooleanLenientForPreEs6Indices(Version indexVersion, String setting, Boolean defaultValue) {
+ if (indexVersion.before(Version.V_6_0_0_alpha1_UNRELEASED)) {
+ //Only emit a warning if the setting's value is not a proper boolean
+ final String value = get(setting, "false");
+ if (Booleans.isBoolean(value) == false) {
+ @SuppressWarnings("deprecation")
+ boolean convertedValue = Booleans.parseBooleanLenient(get(setting), defaultValue);
+ deprecationLogger.deprecated("The value [{}] of setting [{}] is not coerced into boolean anymore. Please change " +
+ "this value to [{}].", value, setting, String.valueOf(convertedValue));
+ return convertedValue;
+ }
+ }
+ return getAsBoolean(setting, defaultValue);
+ }
+
/**
* Returns the setting value (as time) associated with the setting key. If it does not exists,
* returns the default value provided.
diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContent.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContent.java
index e7dbeafe5d0db..879b9e9d723f6 100644
--- a/core/src/main/java/org/elasticsearch/common/xcontent/XContent.java
+++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContent.java
@@ -52,7 +52,7 @@ public interface XContent {
*/
static boolean isStrictDuplicateDetectionEnabled() {
// Don't allow duplicate keys in JSON content by default but let the user opt out
- return Booleans.parseBooleanExact(System.getProperty("es.xcontent.strict_duplicate_detection", "true"));
+ return Booleans.parseBoolean(System.getProperty("es.xcontent.strict_duplicate_detection", "true"));
}
/**
diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java
index 7ca77442268cd..e1f1c4b3f8a1f 100644
--- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java
+++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java
@@ -201,16 +201,32 @@ enum NumberType {
double doubleValue() throws IOException;
+ /**
+ * @return true iff the current value is either boolean (true or false) or one of "false", "true".
+ */
+ boolean isBooleanValue() throws IOException;
+
+ boolean booleanValue() throws IOException;
+
+ // TODO #22298: Remove this method and replace all call sites with #isBooleanValue()
/**
* returns true if the current value is boolean in nature.
* values that are considered booleans:
* - boolean value (true/false)
* - numeric integers (=0 is considered as false, !=0 is true)
* - one of the following strings: "true","false","on","off","yes","no","1","0"
+ *
+ * @deprecated Just present for providing backwards compatibility. Use {@link #isBooleanValue()} instead.
*/
- boolean isBooleanValue() throws IOException;
+ @Deprecated
+ boolean isBooleanValueLenient() throws IOException;
- boolean booleanValue() throws IOException;
+ // TODO #22298: Remove this method and replace all call sites with #booleanValue()
+ /**
+ * @deprecated Just present for providing backwards compatibility. Use {@link #booleanValue()} instead.
+ */
+ @Deprecated
+ boolean booleanValueLenient() throws IOException;
/**
* Reads a plain binary value that was written via one of the following methods:
diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java
index 162e5f7fb7d86..95fe08d96c35e 100644
--- a/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java
+++ b/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java
@@ -74,6 +74,28 @@ void ensureNumberConversion(boolean coerce, long result, Class extends Number>
@Override
public boolean isBooleanValue() throws IOException {
+ switch (currentToken()) {
+ case VALUE_BOOLEAN:
+ return true;
+ case VALUE_STRING:
+ return Booleans.isBoolean(textCharacters(), textOffset(), textLength());
+ default:
+ return false;
+ }
+ }
+
+ @Override
+ public boolean booleanValue() throws IOException {
+ Token token = currentToken();
+ if (token == Token.VALUE_STRING) {
+ return Booleans.parseBoolean(textCharacters(), textOffset(), textLength(), false /* irrelevant */);
+ }
+ return doBooleanValue();
+ }
+
+ @Override
+ @Deprecated
+ public boolean isBooleanValueLenient() throws IOException {
switch (currentToken()) {
case VALUE_BOOLEAN:
return true;
@@ -81,19 +103,20 @@ public boolean isBooleanValue() throws IOException {
NumberType numberType = numberType();
return numberType == NumberType.LONG || numberType == NumberType.INT;
case VALUE_STRING:
- return Booleans.isBoolean(textCharacters(), textOffset(), textLength());
+ return Booleans.isBooleanLenient(textCharacters(), textOffset(), textLength());
default:
return false;
}
}
@Override
- public boolean booleanValue() throws IOException {
+ @Deprecated
+ public boolean booleanValueLenient() throws IOException {
Token token = currentToken();
if (token == Token.VALUE_NUMBER) {
return intValue() != 0;
} else if (token == Token.VALUE_STRING) {
- return Booleans.parseBoolean(textCharacters(), textOffset(), textLength(), false /* irrelevant */);
+ return Booleans.parseBooleanLenient(textCharacters(), textOffset(), textLength(), false /* irrelevant */);
}
return doBooleanValue();
}
diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java b/core/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java
index 09d9dabac7540..36eacb81f8309 100644
--- a/core/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java
+++ b/core/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java
@@ -24,6 +24,7 @@
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
import org.apache.lucene.util.automaton.Operations;
import org.elasticsearch.ElasticsearchParseException;
+import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Numbers;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.regex.Regex;
@@ -412,39 +413,29 @@ public static long nodeLongValue(Object node) {
return Long.parseLong(node.toString());
}
- /**
- * This method is very lenient, use {@link #nodeBooleanValue} instead.
- */
- public static boolean lenientNodeBooleanValue(Object node, boolean defaultValue) {
- if (node == null) {
- return defaultValue;
+ public static boolean nodeBooleanValue(Object node, String name, boolean defaultValue) {
+ try {
+ return nodeBooleanValue(node, defaultValue);
+ } catch (IllegalArgumentException ex) {
+ throw new IllegalArgumentException("Could not convert [" + name + "] to boolean", ex);
}
- return lenientNodeBooleanValue(node);
}
- /**
- * This method is very lenient, use {@link #nodeBooleanValue} instead.
- */
- public static boolean lenientNodeBooleanValue(Object node) {
- if (node instanceof Boolean) {
- return (Boolean) node;
- }
- if (node instanceof Number) {
- return ((Number) node).intValue() != 0;
+ public static boolean nodeBooleanValue(Object node, boolean defaultValue) {
+ String nodeValue = node == null ? null : node.toString();
+ return Booleans.parseBoolean(nodeValue, defaultValue);
+ }
+
+ public static boolean nodeBooleanValue(Object node, String name) {
+ try {
+ return nodeBooleanValue(node);
+ } catch (IllegalArgumentException ex) {
+ throw new IllegalArgumentException("Could not convert [" + name + "] to boolean", ex);
}
- String value = node.toString();
- return !(value.equals("false") || value.equals("0") || value.equals("off"));
}
public static boolean nodeBooleanValue(Object node) {
- switch (node.toString()) {
- case "true":
- return true;
- case "false":
- return false;
- default:
- throw new IllegalArgumentException("Can't parse boolean value [" + node + "], expected [true] or [false]");
- }
+ return Booleans.parseBoolean(node.toString());
}
public static TimeValue nodeTimeValue(Object node, TimeValue defaultValue) {
diff --git a/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java b/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java
index e930f327f0d33..927397725be0c 100644
--- a/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java
+++ b/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java
@@ -477,9 +477,11 @@ static NodeShardsResult buildVersionBasedNodeShardsResult(ShardRouting shard, bo
*/
private boolean recoverOnAnyNode(IndexMetaData metaData) {
// don't use the setting directly, not to trigger verbose deprecation logging
- return (IndexMetaData.isOnSharedFilesystem(metaData.getSettings()) || IndexMetaData.isOnSharedFilesystem(this.settings))
- && (metaData.getSettings().getAsBoolean(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, false) ||
- this.settings.getAsBoolean(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, false));
+ return (metaData.isOnSharedFilesystem(metaData.getSettings()) || metaData.isOnSharedFilesystem(this.settings))
+ && (metaData.getSettings().getAsBooleanLenientForPreEs6Indices(
+ metaData.getCreationVersion(), IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, false) ||
+ this.settings.getAsBooleanLenientForPreEs6Indices
+ (metaData.getCreationVersion(), IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, false));
}
protected abstract FetchResult fetchData(ShardRouting shard, RoutingAllocation allocation);
diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java
index 97edd2fd468f8..25e32dc0dee94 100644
--- a/core/src/main/java/org/elasticsearch/index/IndexModule.java
+++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java
@@ -23,6 +23,7 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
+import org.elasticsearch.common.TriFunction;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
@@ -69,7 +70,7 @@
* IndexModule represents the central extension point for index level custom implementations like:
*
*
{@link SimilarityProvider} - New {@link SimilarityProvider} implementations can be registered through
- * {@link #addSimilarity(String, BiFunction)}while existing Providers can be referenced through Settings under the
+ * {@link #addSimilarity(String, TriFunction)}while existing Providers can be referenced through Settings under the
* {@link IndexModule#SIMILARITY_SETTINGS_PREFIX} prefix along with the "type" value. For example, to reference the
* {@link BM25SimilarityProvider}, the configuration "index.similarity.my_similarity.type : "BM25" can be used.
*
{@link IndexStore} - Custom {@link IndexStore} instances can be registered via {@link #addIndexStore(String, Function)}
@@ -112,7 +113,7 @@ public final class IndexModule {
final SetOnce engineFactory = new SetOnce<>();
private SetOnce indexSearcherWrapper = new SetOnce<>();
private final Set indexEventListeners = new HashSet<>();
- private final Map> similarities = new HashMap<>();
+ private final Map> similarities = new HashMap<>();
private final Map> storeTypes = new HashMap<>();
private final SetOnce> forceQueryCacheProvider = new SetOnce<>();
private final List searchOperationListeners = new ArrayList<>();
@@ -256,7 +257,7 @@ public void addIndexStore(String type, Function provi
* @param name Name of the SimilarityProvider
* @param similarity SimilarityProvider to register
*/
- public void addSimilarity(String name, BiFunction similarity) {
+ public void addSimilarity(String name, TriFunction similarity) {
ensureNotFrozen();
if (similarities.containsKey(name) || SimilarityService.BUILT_IN.containsKey(name)) {
throw new IllegalArgumentException("similarity for name: [" + name + " is already registered");
diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java
index 50fdb5272c0d6..25e2666343fa6 100644
--- a/core/src/main/java/org/elasticsearch/index/IndexService.java
+++ b/core/src/main/java/org/elasticsearch/index/IndexService.java
@@ -343,8 +343,8 @@ public synchronized IndexShard createShard(ShardRouting routing) throws IOExcept
logger.debug("creating shard_id {}", shardId);
// if we are on a shared FS we only own the shard (ie. we can safely delete it) if we are the primary.
- final boolean canDeleteShardContent = IndexMetaData.isOnSharedFilesystem(indexSettings) == false ||
- (primary && IndexMetaData.isOnSharedFilesystem(indexSettings));
+ final boolean canDeleteShardContent = this.indexSettings.isOnSharedFilesystem() == false ||
+ (primary && this.indexSettings.isOnSharedFilesystem());
final Engine.Warmer engineWarmer = (searcher) -> {
IndexShard shard = getShardOrNull(shardId.getId());
if (shard != null) {
@@ -353,7 +353,7 @@ public synchronized IndexShard createShard(ShardRouting routing) throws IOExcept
};
store = new Store(shardId, this.indexSettings, indexStore.newDirectoryService(path), lock,
new StoreCloseListener(shardId, canDeleteShardContent, () -> eventListener.onStoreClosed(shardId)));
- if (useShadowEngine(primary, indexSettings)) {
+ if (useShadowEngine(primary, this.indexSettings)) {
indexShard = new ShadowIndexShard(routing, this.indexSettings, path, store, indexCache, mapperService, similarityService,
indexFieldData, engineFactory, eventListener, searcherWrapper, threadPool, bigArrays, engineWarmer,
searchOperationListeners);
@@ -381,8 +381,8 @@ public synchronized IndexShard createShard(ShardRouting routing) throws IOExcept
}
}
- static boolean useShadowEngine(boolean primary, Settings indexSettings) {
- return primary == false && IndexMetaData.isIndexUsingShadowReplicas(indexSettings);
+ static boolean useShadowEngine(boolean primary, IndexSettings indexSettings) {
+ return primary == false && indexSettings.isShadowReplicaIndex();
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java
index 25751cfc77190..260cb593a82de 100644
--- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java
+++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java
@@ -229,7 +229,7 @@ public IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSetti
nodeName = Node.NODE_NAME_SETTING.get(settings);
this.indexMetaData = indexMetaData;
numberOfShards = settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, null);
- isShadowReplicaIndex = IndexMetaData.isIndexUsingShadowReplicas(settings);
+ isShadowReplicaIndex = indexMetaData.isIndexUsingShadowReplicas(settings);
this.defaultField = DEFAULT_FIELD_SETTING.get(settings);
this.queryStringLenient = QUERY_STRING_LENIENT_SETTING.get(settings);
@@ -327,16 +327,7 @@ public String customDataPath() {
* filesystem.
*/
public boolean isOnSharedFilesystem() {
- return IndexMetaData.isOnSharedFilesystem(getSettings());
- }
-
- /**
- * Returns true iff the given settings indicate that the index associated
- * with these settings uses shadow replicas. Otherwise false. The default
- * setting for this is false.
- */
- public boolean isIndexUsingShadowReplicas() {
- return IndexMetaData.isOnSharedFilesystem(getSettings());
+ return indexMetaData.isOnSharedFilesystem(getSettings());
}
/**
diff --git a/core/src/main/java/org/elasticsearch/index/MergePolicyConfig.java b/core/src/main/java/org/elasticsearch/index/MergePolicyConfig.java
index 0f7305789ecb5..c2625f7615bff 100644
--- a/core/src/main/java/org/elasticsearch/index/MergePolicyConfig.java
+++ b/core/src/main/java/org/elasticsearch/index/MergePolicyConfig.java
@@ -164,7 +164,8 @@ public final class MergePolicyConfig {
ByteSizeValue maxMergedSegment = indexSettings.getValue(INDEX_MERGE_POLICY_MAX_MERGED_SEGMENT_SETTING);
double segmentsPerTier = indexSettings.getValue(INDEX_MERGE_POLICY_SEGMENTS_PER_TIER_SETTING);
double reclaimDeletesWeight = indexSettings.getValue(INDEX_MERGE_POLICY_RECLAIM_DELETES_WEIGHT_SETTING);
- this.mergesEnabled = indexSettings.getSettings().getAsBoolean(INDEX_MERGE_ENABLED, true);
+ this.mergesEnabled = indexSettings.getSettings()
+ .getAsBooleanLenientForPreEs6Indices(indexSettings.getIndexVersionCreated(), INDEX_MERGE_ENABLED, true);
if (mergesEnabled == false) {
logger.warn("[{}] is set to false, this should only be used in tests and can cause serious problems in production environments", INDEX_MERGE_ENABLED);
}
diff --git a/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java
index 4318ef273dca9..1486382521aa8 100644
--- a/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java
+++ b/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java
@@ -37,7 +37,8 @@ public class ASCIIFoldingTokenFilterFactory extends AbstractTokenFilterFactory i
public ASCIIFoldingTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
super(indexSettings, name, settings);
- preserveOriginal = settings.getAsBoolean(PRESERVE_ORIGINAL.getPreferredName(), DEFAULT_PRESERVE_ORIGINAL);
+ preserveOriginal = settings.getAsBooleanLenientForPreEs6Indices(
+ indexSettings.getIndexVersionCreated(), PRESERVE_ORIGINAL.getPreferredName(), DEFAULT_PRESERVE_ORIGINAL);
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/index/analysis/Analysis.java b/core/src/main/java/org/elasticsearch/index/analysis/Analysis.java
index aded2bb4ee9fc..170e35905d538 100644
--- a/core/src/main/java/org/elasticsearch/index/analysis/Analysis.java
+++ b/core/src/main/java/org/elasticsearch/index/analysis/Analysis.java
@@ -178,12 +178,15 @@ public static CharArraySet parseCommonWords(Environment env, Settings settings,
return parseWords(env, settings, "common_words", defaultCommonWords, NAMED_STOP_WORDS, ignoreCase);
}
- public static CharArraySet parseArticles(Environment env, Settings settings) {
- return parseWords(env, settings, "articles", null, null, settings.getAsBoolean("articles_case", false));
+ public static CharArraySet parseArticles(Environment env, org.elasticsearch.Version indexCreatedVersion, Settings settings) {
+ boolean articlesCase = settings.getAsBooleanLenientForPreEs6Indices(indexCreatedVersion, "articles_case", false);
+ return parseWords(env, settings, "articles", null, null, articlesCase);
}
- public static CharArraySet parseStopWords(Environment env, Settings settings, CharArraySet defaultStopWords) {
- return parseStopWords(env, settings, defaultStopWords, settings.getAsBoolean("stopwords_case", false));
+ public static CharArraySet parseStopWords(Environment env, org.elasticsearch.Version indexCreatedVersion, Settings settings,
+ CharArraySet defaultStopWords) {
+ boolean stopwordsCase = settings.getAsBooleanLenientForPreEs6Indices(indexCreatedVersion, "stopwords_case", false);
+ return parseStopWords(env, settings, defaultStopWords, stopwordsCase);
}
public static CharArraySet parseStopWords(Environment env, Settings settings, CharArraySet defaultStopWords, boolean ignoreCase) {
@@ -205,12 +208,14 @@ private static CharArraySet resolveNamedWords(Collection words, Map wordList = getWordList(env, settings, settingsPrefix);
if (wordList == null) {
return null;
}
- return new CharArraySet(wordList, settings.getAsBoolean(settingsPrefix + "_case", false));
+ boolean ignoreCase = settings.getAsBooleanLenientForPreEs6Indices(indexCreatedVersion, settingsPrefix + "_case", false);
+ return new CharArraySet(wordList, ignoreCase);
}
/**
diff --git a/core/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java
index fffa594b9e1c0..10d8f22bde7e8 100644
--- a/core/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java
+++ b/core/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java
@@ -31,8 +31,10 @@ public class ArabicAnalyzerProvider extends AbstractIndexAnalyzerProvider scripts = new HashSet<>(Arrays.asList("han", "hiragana", "katakana", "hangul"));
if (asArray != null) {
diff --git a/core/src/main/java/org/elasticsearch/index/analysis/CatalanAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/CatalanAnalyzerProvider.java
index 25328421f9948..ff0f9e323097d 100644
--- a/core/src/main/java/org/elasticsearch/index/analysis/CatalanAnalyzerProvider.java
+++ b/core/src/main/java/org/elasticsearch/index/analysis/CatalanAnalyzerProvider.java
@@ -31,8 +31,10 @@ public class CatalanAnalyzerProvider extends AbstractIndexAnalyzerProvider rules = Analysis.getWordSet(env, settings, "keywords");
+ boolean ignoreCase = settings.getAsBooleanLenientForPreEs6Indices(indexSettings.getIndexVersionCreated(), "ignore_case", false);
+ Set> rules = Analysis.getWordSet(env, indexSettings.getIndexVersionCreated(), settings, "keywords");
if (rules == null) {
throw new IllegalArgumentException("keyword filter requires either `keywords` or `keywords_path` to be configured");
}
diff --git a/core/src/main/java/org/elasticsearch/index/analysis/LatvianAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/LatvianAnalyzerProvider.java
index a288747ab4b2b..a7731f352b997 100644
--- a/core/src/main/java/org/elasticsearch/index/analysis/LatvianAnalyzerProvider.java
+++ b/core/src/main/java/org/elasticsearch/index/analysis/LatvianAnalyzerProvider.java
@@ -31,8 +31,10 @@ public class LatvianAnalyzerProvider extends AbstractIndexAnalyzerProvider tokenizerFactoryFactory =
diff --git a/core/src/main/java/org/elasticsearch/index/analysis/ThaiAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/ThaiAnalyzerProvider.java
index f1a69c62b1e09..119eb81d7482d 100644
--- a/core/src/main/java/org/elasticsearch/index/analysis/ThaiAnalyzerProvider.java
+++ b/core/src/main/java/org/elasticsearch/index/analysis/ThaiAnalyzerProvider.java
@@ -30,7 +30,8 @@ public class ThaiAnalyzerProvider extends AbstractIndexAnalyzerProvider "O", "Neil"
flags |= getFlag(STEM_ENGLISH_POSSESSIVE, settings, "stem_english_possessive", true);
// If not null is the set of tokens to protect from being delimited
- Set> protectedWords = Analysis.getWordSet(env, settings, "protected_words");
+ Set> protectedWords = Analysis.getWordSet(env, indexSettings.getIndexVersionCreated(), settings, "protected_words");
this.protoWords = protectedWords == null ? null : CharArraySet.copy(protectedWords);
this.flags = flags;
}
@@ -101,7 +101,7 @@ public TokenStream create(TokenStream tokenStream) {
}
public int getFlag(int flag, Settings settings, String key, boolean defaultValue) {
- if (settings.getAsBoolean(key, defaultValue)) {
+ if (settings.getAsBooleanLenientForPreEs6Indices(indexSettings.getIndexVersionCreated(), key, defaultValue)) {
return flag;
}
return 0;
diff --git a/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java
index e7147334a7eaa..9be3f38b02fbc 100644
--- a/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java
+++ b/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java
@@ -44,8 +44,9 @@ public AbstractCompoundWordTokenFilterFactory(IndexSettings indexSettings, Envir
minWordSize = settings.getAsInt("min_word_size", CompoundWordTokenFilterBase.DEFAULT_MIN_WORD_SIZE);
minSubwordSize = settings.getAsInt("min_subword_size", CompoundWordTokenFilterBase.DEFAULT_MIN_SUBWORD_SIZE);
maxSubwordSize = settings.getAsInt("max_subword_size", CompoundWordTokenFilterBase.DEFAULT_MAX_SUBWORD_SIZE);
- onlyLongestMatch = settings.getAsBoolean("only_longest_match", false);
- wordList = Analysis.getWordSet(env, settings, "word_list");
+ onlyLongestMatch = settings
+ .getAsBooleanLenientForPreEs6Indices(indexSettings.getIndexVersionCreated(), "only_longest_match", false);
+ wordList = Analysis.getWordSet(env, indexSettings.getIndexVersionCreated(), settings, "word_list");
if (wordList == null) {
throw new IllegalArgumentException("word_list must be provided for [" + name + "], either as a path to a file, or directly");
}
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java
index d77a99cf3655d..58380ce689034 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java
@@ -40,7 +40,6 @@
import java.util.List;
import java.util.Map;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeMapValue;
import static org.elasticsearch.index.mapper.TypeParsers.parseTextField;
@@ -118,7 +117,7 @@ public MetadataFieldMapper.Builder,?> parse(String name, Map n
// the AllFieldMapper ctor in the builder since it is not valid. Here we validate
// the doc values settings (old and new) are rejected
Object docValues = node.get("doc_values");
- if (docValues != null && lenientNodeBooleanValue(docValues)) {
+ if (docValues != null && TypeParsers.nodeBooleanValueLenient(name, "doc_values", docValues)) {
throw new MapperParsingException("Field [" + name +
"] is always tokenized and cannot have doc values");
}
@@ -139,8 +138,8 @@ public MetadataFieldMapper.Builder,?> parse(String name, Map n
String fieldName = entry.getKey();
Object fieldNode = entry.getValue();
if (fieldName.equals("enabled")) {
- builder.enabled(lenientNodeBooleanValue(fieldNode) ? EnabledAttributeMapper.ENABLED :
- EnabledAttributeMapper.DISABLED);
+ boolean enabled = TypeParsers.nodeBooleanValueLenient(name, "enabled", fieldNode);
+ builder.enabled(enabled ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED);
iterator.remove();
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/BaseGeoPointFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/BaseGeoPointFieldMapper.java
index c075d784c942e..610588e654052 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/BaseGeoPointFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/BaseGeoPointFieldMapper.java
@@ -123,7 +123,7 @@ public abstract static class TypeParser implements Mapper.TypeParser {
Object propNode = entry.getValue();
if (propName.equals(Names.IGNORE_MALFORMED)) {
- builder.ignoreMalformed(XContentMapValues.lenientNodeBooleanValue(propNode));
+ builder.ignoreMalformed(TypeParsers.nodeBooleanValue(name, Names.IGNORE_MALFORMED, propNode, parserContext));
iterator.remove();
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java
index fc9520beeab39..7bd8c79ee670a 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java
@@ -26,8 +26,10 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.util.BytesRef;
-import org.elasticsearch.common.Booleans;
+import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
+import org.elasticsearch.common.logging.DeprecationLogger;
+import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -44,13 +46,13 @@
import java.util.List;
import java.util.Map;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
import static org.elasticsearch.index.mapper.TypeParsers.parseField;
/**
* A field mapper for boolean fields.
*/
public class BooleanFieldMapper extends FieldMapper {
+ private static final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(BooleanFieldMapper.class));
public static final String CONTENT_TYPE = "boolean";
@@ -108,7 +110,7 @@ public Mapper.Builder parse(String name, Map node, ParserContext
if (propNode == null) {
throw new MapperParsingException("Property [null_value] cannot be null.");
}
- builder.nullValue(lenientNodeBooleanValue(propNode));
+ builder.nullValue(TypeParsers.nodeBooleanValue(name, "null_value", propNode, parserContext));
iterator.remove();
}
}
@@ -231,7 +233,15 @@ protected void parseCreateField(ParseContext context, List field
value = fieldType().nullValue();
}
} else {
- value = context.parser().booleanValue();
+ if (indexCreatedVersion.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
+ value = context.parser().booleanValue();
+ } else {
+ value = context.parser().booleanValueLenient();
+ if (context.parser().isBooleanValueLenient() != context.parser().isBooleanValue()) {
+ String rawValue = context.parser().text();
+ deprecationLogger.deprecated("Expected a boolean for property [{}] but got [{}]", fieldType().name(), rawValue);
+ }
+ }
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java
index d2833d4bfb36b..52e5de0a176d9 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java
@@ -151,7 +151,7 @@ public Mapper.Builder,?> parse(String name, Map node, ParserCo
builder.nullValue(propNode.toString());
iterator.remove();
} else if (propName.equals("ignore_malformed")) {
- builder.ignoreMalformed(TypeParsers.nodeBooleanValue("ignore_malformed", propNode, parserContext));
+ builder.ignoreMalformed(TypeParsers.nodeBooleanValue(name, "ignore_malformed", propNode, parserContext));
iterator.remove();
} else if (propName.equals("locale")) {
builder.locale(LocaleUtils.parse(propNode.toString()));
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java
index b2152e41b75ab..0ed093b3a884f 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java
@@ -237,7 +237,7 @@ protected void setupFieldType(BuilderContext context) {
}
}
- private final Version indexCreatedVersion;
+ protected final Version indexCreatedVersion;
protected MappedFieldType fieldType;
protected final MappedFieldType defaultFieldType;
protected MultiFields multiFields;
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java
index 764586562d29c..863ce3c514905 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java
@@ -36,8 +36,6 @@
import java.util.Map;
import java.util.Objects;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
-
/**
* A mapper that indexes the field names of a document under _field_names. This mapper is typically useful in order
* to have fast exists and missing queries/filters.
@@ -107,7 +105,7 @@ public MetadataFieldMapper.Builder,?> parse(String name, Map n
String fieldName = entry.getKey();
Object fieldNode = entry.getValue();
if (fieldName.equals("enabled")) {
- builder.enabled(lenientNodeBooleanValue(fieldNode));
+ builder.enabled(TypeParsers.nodeBooleanValue(name, "enabled", fieldNode, parserContext));
iterator.remove();
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java
index f1a73308692f5..c46fe227d6fdc 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java
@@ -41,7 +41,6 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.QueryShardException;
import org.locationtech.spatial4j.shape.Point;
@@ -54,9 +53,6 @@
import java.util.Map;
import java.util.Objects;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
-
-
/**
* FieldMapper for indexing {@link org.locationtech.spatial4j.shape.Shape}s.
*
@@ -185,11 +181,12 @@ public Mapper.Builder parse(String name, Map node, ParserContext
builder.fieldType().setStrategyName(fieldNode.toString());
iterator.remove();
} else if (Names.COERCE.equals(fieldName)) {
- builder.coerce(lenientNodeBooleanValue(fieldNode));
+ builder.coerce(TypeParsers.nodeBooleanValue(fieldName, Names.COERCE, fieldNode, parserContext));
iterator.remove();
} else if (Names.STRATEGY_POINTS_ONLY.equals(fieldName)
&& builder.fieldType().strategyName.equals(SpatialStrategy.TERM.getStrategyName()) == false) {
- builder.fieldType().setPointsOnly(XContentMapValues.lenientNodeBooleanValue(fieldNode));
+ boolean pointsOnly = TypeParsers.nodeBooleanValue(fieldName, Names.STRATEGY_POINTS_ONLY, fieldNode, parserContext);
+ builder.fieldType().setPointsOnly(pointsOnly);
iterator.remove();
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java
index 0b3b4fd8a4086..9f4412c34ccca 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java
@@ -114,7 +114,7 @@ public Mapper.Builder,?> parse(String name, Map node, ParserCo
builder.nullValue(InetAddresses.forString(propNode.toString()));
iterator.remove();
} else if (propName.equals("ignore_malformed")) {
- builder.ignoreMalformed(TypeParsers.nodeBooleanValue("ignore_malformed", propNode, parserContext));
+ builder.ignoreMalformed(TypeParsers.nodeBooleanValue(name, "ignore_malformed", propNode, parserContext));
iterator.remove();
} else if (TypeParsers.parseMultiField(builder, name, parserContext, propName, propNode)) {
iterator.remove();
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java
index f4f6266262fe2..8824b84fc9b10 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java
@@ -136,10 +136,10 @@ public Mapper.Builder,?> parse(String name, Map node, ParserCo
builder.ignoreAbove(XContentMapValues.nodeIntegerValue(propNode, -1));
iterator.remove();
} else if (propName.equals("norms")) {
- builder.omitNorms(XContentMapValues.nodeBooleanValue(propNode) == false);
+ builder.omitNorms(XContentMapValues.nodeBooleanValue(propNode, "norms") == false);
iterator.remove();
} else if (propName.equals("eager_global_ordinals")) {
- builder.eagerGlobalOrdinals(XContentMapValues.nodeBooleanValue(propNode));
+ builder.eagerGlobalOrdinals(XContentMapValues.nodeBooleanValue(propNode, "eager_global_ordinals"));
iterator.remove();
} else if (propName.equals("normalizer")) {
if (propNode != null) {
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java
index c922cd8b54c7f..e9043b3c754be 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java
@@ -150,10 +150,10 @@ public Mapper.Builder,?> parse(String name, Map node,
builder.nullValue(type.parse(propNode, false));
iterator.remove();
} else if (propName.equals("ignore_malformed")) {
- builder.ignoreMalformed(TypeParsers.nodeBooleanValue("ignore_malformed", propNode, parserContext));
+ builder.ignoreMalformed(TypeParsers.nodeBooleanValue(name,"ignore_malformed", propNode, parserContext));
iterator.remove();
} else if (propName.equals("coerce")) {
- builder.coerce(TypeParsers.nodeBooleanValue("coerce", propNode, parserContext));
+ builder.coerce(TypeParsers.nodeBooleanValue(name, "coerce", propNode, parserContext));
iterator.remove();
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java
index 60c264e570617..9cd6ef3b65f46 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java
@@ -42,8 +42,6 @@
import java.util.Locale;
import java.util.Map;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
-
public class ObjectMapper extends Mapper implements Cloneable {
public static final String CONTENT_TYPE = "object";
@@ -167,7 +165,7 @@ public static class TypeParser implements Mapper.TypeParser {
@Override
public Mapper.Builder parse(String name, Map node, ParserContext parserContext) throws MapperParsingException {
ObjectMapper.Builder builder = new Builder(name);
- parseNested(name, node, builder);
+ parseNested(name, node, builder, parserContext);
for (Iterator> iterator = node.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = iterator.next();
String fieldName = entry.getKey();
@@ -185,11 +183,12 @@ protected static boolean parseObjectOrDocumentTypeProperties(String fieldName, O
if (value.equalsIgnoreCase("strict")) {
builder.dynamic(Dynamic.STRICT);
} else {
- builder.dynamic(lenientNodeBooleanValue(fieldNode) ? Dynamic.TRUE : Dynamic.FALSE);
+ boolean dynamic = TypeParsers.nodeBooleanValue(fieldName, "dynamic", fieldNode, parserContext);
+ builder.dynamic(dynamic ? Dynamic.TRUE : Dynamic.FALSE);
}
return true;
} else if (fieldName.equals("enabled")) {
- builder.enabled(lenientNodeBooleanValue(fieldNode));
+ builder.enabled(TypeParsers.nodeBooleanValue(fieldName, "enabled", fieldNode, parserContext));
return true;
} else if (fieldName.equals("properties")) {
if (fieldNode instanceof Collection && ((Collection) fieldNode).isEmpty()) {
@@ -201,13 +200,14 @@ protected static boolean parseObjectOrDocumentTypeProperties(String fieldName, O
}
return true;
} else if (fieldName.equals("include_in_all")) {
- builder.includeInAll(lenientNodeBooleanValue(fieldNode));
+ builder.includeInAll(TypeParsers.nodeBooleanValue(fieldName, "include_in_all", fieldNode, parserContext));
return true;
}
return false;
}
- protected static void parseNested(String name, Map node, ObjectMapper.Builder builder) {
+ protected static void parseNested(String name, Map node, ObjectMapper.Builder builder,
+ ParserContext parserContext) {
boolean nested = false;
boolean nestedIncludeInParent = false;
boolean nestedIncludeInRoot = false;
@@ -224,12 +224,12 @@ protected static void parseNested(String name, Map node, ObjectM
}
fieldNode = node.get("include_in_parent");
if (fieldNode != null) {
- nestedIncludeInParent = lenientNodeBooleanValue(fieldNode);
+ nestedIncludeInParent = TypeParsers.nodeBooleanValue(name, "include_in_parent", fieldNode, parserContext);
node.remove("include_in_parent");
}
fieldNode = node.get("include_in_root");
if (fieldNode != null) {
- nestedIncludeInRoot = lenientNodeBooleanValue(fieldNode);
+ nestedIncludeInRoot = TypeParsers.nodeBooleanValue(name, "include_in_root", fieldNode, parserContext);
node.remove("include_in_root");
}
if (nested) {
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java
index 6b4133fd33aab..aee6979b5c809 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java
@@ -122,7 +122,7 @@ public MetadataFieldMapper.Builder parse(String name, Map node,
}
iterator.remove();
} else if (fieldName.equals("eager_global_ordinals")) {
- builder.eagerGlobalOrdinals(XContentMapValues.nodeBooleanValue(fieldNode));
+ builder.eagerGlobalOrdinals(XContentMapValues.nodeBooleanValue(fieldNode, "eager_global_ordinals"));
iterator.remove();
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java
index b0a809c12dfce..d3c9afd2f9629 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java
@@ -166,7 +166,7 @@ public Mapper.Builder,?> parse(String name, Map node,
throw new MapperParsingException("Property [null_value] is not supported for [" + this.type.name
+ "] field types.");
} else if (propName.equals("coerce")) {
- builder.coerce(TypeParsers.nodeBooleanValue("coerce", propNode, parserContext));
+ builder.coerce(TypeParsers.nodeBooleanValue(name, "coerce", propNode, parserContext));
iterator.remove();
} else if (propName.equals("locale")) {
builder.locale(LocaleUtils.parse(propNode.toString()));
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/RootObjectMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/RootObjectMapper.java
index 0ae7ce3358113..c51f29072c188 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/RootObjectMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/RootObjectMapper.java
@@ -150,10 +150,10 @@ protected boolean processField(RootObjectMapper.Builder builder, String fieldNam
builder.dynamicTemplates(templates);
return true;
} else if (fieldName.equals("date_detection")) {
- ((Builder) builder).dateDetection = new Explicit<>(nodeBooleanValue(fieldNode), true);
+ builder.dateDetection = new Explicit<>(nodeBooleanValue(fieldNode, "date_detection"), true);
return true;
} else if (fieldName.equals("numeric_detection")) {
- ((Builder) builder).numericDetection = new Explicit<>(nodeBooleanValue(fieldNode), true);
+ builder.numericDetection = new Explicit<>(nodeBooleanValue(fieldNode, "numeric_detection"), true);
return true;
}
return false;
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java
index 8640bfaa35bdc..d1161b4740f22 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java
@@ -32,8 +32,6 @@
import java.util.List;
import java.util.Map;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
-
public class RoutingFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_routing";
@@ -86,7 +84,7 @@ public MetadataFieldMapper.Builder,?> parse(String name, Map n
String fieldName = entry.getKey();
Object fieldNode = entry.getValue();
if (fieldName.equals("required")) {
- builder.required(lenientNodeBooleanValue(fieldNode));
+ builder.required(TypeParsers.nodeBooleanValue(name, "required", fieldNode, parserContext));
iterator.remove();
}
}
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java
index 6cd69c0fc6b7f..cf2564f0382f4 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java
@@ -147,10 +147,10 @@ public Mapper.Builder,?> parse(String name, Map node,
builder.nullValue(NumberFieldMapper.NumberType.DOUBLE.parse(propNode, false));
iterator.remove();
} else if (propName.equals("ignore_malformed")) {
- builder.ignoreMalformed(TypeParsers.nodeBooleanValue("ignore_malformed", propNode, parserContext));
+ builder.ignoreMalformed(TypeParsers.nodeBooleanValue(name, "ignore_malformed", propNode, parserContext));
iterator.remove();
} else if (propName.equals("coerce")) {
- builder.coerce(TypeParsers.nodeBooleanValue("coerce", propNode, parserContext));
+ builder.coerce(TypeParsers.nodeBooleanValue(name, "coerce", propNode, parserContext));
iterator.remove();
} else if (propName.equals("scaling_factor")) {
builder.scalingFactor(NumberFieldMapper.NumberType.DOUBLE.parse(propNode, false).doubleValue());
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java
index efddec9066937..e06ec80a472dd 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java
@@ -47,8 +47,6 @@
import java.util.Map;
import java.util.function.Function;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
-
public class SourceFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_source";
@@ -116,7 +114,7 @@ public MetadataFieldMapper.Builder,?> parse(String name, Map n
String fieldName = entry.getKey();
Object fieldNode = entry.getValue();
if (fieldName.equals("enabled")) {
- builder.enabled(lenientNodeBooleanValue(fieldNode));
+ builder.enabled(TypeParsers.nodeBooleanValue(name, "enabled", fieldNode, parserContext));
iterator.remove();
} else if ("format".equals(fieldName) && parserContext.indexVersionCreated().before(Version.V_5_0_0_alpha1)) {
// ignore on old indices, reject on and after 5.0
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java
index bb8c4d77a6311..b41695eb8bd49 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java
@@ -144,10 +144,10 @@ public Mapper.Builder parse(String fieldName, Map node, ParserCo
builder.positionIncrementGap(newPositionIncrementGap);
iterator.remove();
} else if (propName.equals("fielddata")) {
- builder.fielddata(XContentMapValues.nodeBooleanValue(propNode));
+ builder.fielddata(XContentMapValues.nodeBooleanValue(propNode, "fielddata"));
iterator.remove();
} else if (propName.equals("eager_global_ordinals")) {
- builder.eagerGlobalOrdinals(XContentMapValues.nodeBooleanValue(propNode));
+ builder.eagerGlobalOrdinals(XContentMapValues.nodeBooleanValue(propNode, "eager_global_ordinals"));
iterator.remove();
} else if (propName.equals("fielddata_frequency_filter")) {
Map,?> frequencyFilter = (Map, ?>) propNode;
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java b/core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java
index 6e88e8b46cd04..3faa135402d7d 100644
--- a/core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java
+++ b/core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java
@@ -22,6 +22,7 @@
import org.apache.lucene.index.IndexOptions;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
+import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.joda.Joda;
import org.elasticsearch.common.logging.DeprecationLogger;
@@ -30,17 +31,13 @@
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.similarity.SimilarityProvider;
-import java.util.Arrays;
import java.util.Collections;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.isArray;
-import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeFloatValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeMapValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringValue;
@@ -54,17 +51,37 @@ public class TypeParsers {
public static final String INDEX_OPTIONS_OFFSETS = "offsets";
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(TypeParsers.class));
- private static final Set BOOLEAN_STRINGS = new HashSet<>(Arrays.asList("true", "false"));
- public static boolean nodeBooleanValue(String name, Object node, Mapper.TypeParser.ParserContext parserContext) {
- // TODO: remove this leniency in 6.0
- if (BOOLEAN_STRINGS.contains(node.toString()) == false) {
- DEPRECATION_LOGGER.deprecated("Expected a boolean for property [{}] but got [{}]", name, node);
+ //TODO 22298: Remove this method and have all call-sites use XContentMapValues.nodeBooleanValue(node) directly.
+ public static boolean nodeBooleanValue(String fieldName, String propertyName, Object node,
+ Mapper.TypeParser.ParserContext parserContext) {
+ if (parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
+ return XContentMapValues.nodeBooleanValue(node, fieldName + "." + propertyName);
+ } else {
+ return nodeBooleanValueLenient(fieldName, propertyName, node);
+ }
+ }
+
+ //TODO 22298: Remove this method and have all call-sites use XContentMapValues.nodeBooleanValue(node) directly.
+ public static boolean nodeBooleanValueLenient(String fieldName, String propertyName, Object node) {
+ if (Booleans.isBoolean(node.toString()) == false) {
+ DEPRECATION_LOGGER.deprecated("Expected a boolean for property [{}] for field [{}] but got [{}]",
+ propertyName, fieldName, node);
+ }
+ if (node instanceof Boolean) {
+ return (Boolean) node;
}
- return XContentMapValues.lenientNodeBooleanValue(node);
+ if (node instanceof Number) {
+ return ((Number) node).intValue() != 0;
+ }
+ @SuppressWarnings("deprecated")
+ boolean value = Booleans.parseBooleanLenient(node.toString(), false);
+ return value;
}
- private static void parseAnalyzersAndTermVectors(FieldMapper.Builder builder, String name, Map fieldNode, Mapper.TypeParser.ParserContext parserContext) {
+
+ private static void parseAnalyzersAndTermVectors(FieldMapper.Builder builder, String name, Map fieldNode,
+ Mapper.TypeParser.ParserContext parserContext) {
NamedAnalyzer indexAnalyzer = null;
NamedAnalyzer searchAnalyzer = null;
NamedAnalyzer searchQuoteAnalyzer = null;
@@ -77,16 +94,17 @@ private static void parseAnalyzersAndTermVectors(FieldMapper.Builder builder, St
parseTermVector(name, propNode.toString(), builder);
iterator.remove();
} else if (propName.equals("store_term_vectors")) {
- builder.storeTermVectors(nodeBooleanValue("store_term_vectors", propNode, parserContext));
+ builder.storeTermVectors(nodeBooleanValue(name, "store_term_vectors", propNode, parserContext));
iterator.remove();
} else if (propName.equals("store_term_vector_offsets")) {
- builder.storeTermVectorOffsets(nodeBooleanValue("store_term_vector_offsets", propNode, parserContext));
+ builder.storeTermVectorOffsets(nodeBooleanValue(name, "store_term_vector_offsets", propNode, parserContext));
iterator.remove();
} else if (propName.equals("store_term_vector_positions")) {
- builder.storeTermVectorPositions(nodeBooleanValue("store_term_vector_positions", propNode, parserContext));
+ builder.storeTermVectorPositions(
+ nodeBooleanValue(name, "store_term_vector_positions", propNode, parserContext));
iterator.remove();
} else if (propName.equals("store_term_vector_payloads")) {
- builder.storeTermVectorPayloads(nodeBooleanValue("store_term_vector_payloads", propNode, parserContext));
+ builder.storeTermVectorPayloads(nodeBooleanValue(name,"store_term_vector_payloads", propNode, parserContext));
iterator.remove();
} else if (propName.equals("analyzer")) {
NamedAnalyzer analyzer = parserContext.getIndexAnalyzers().get(propNode.toString());
@@ -117,7 +135,8 @@ private static void parseAnalyzersAndTermVectors(FieldMapper.Builder builder, St
}
if (searchAnalyzer == null && searchQuoteAnalyzer != null) {
- throw new MapperParsingException("analyzer and search_analyzer on field [" + name + "] must be set when search_quote_analyzer is set");
+ throw new MapperParsingException("analyzer and search_analyzer on field [" + name +
+ "] must be set when search_quote_analyzer is set");
}
if (searchAnalyzer == null) {
@@ -139,16 +158,17 @@ private static void parseAnalyzersAndTermVectors(FieldMapper.Builder builder, St
}
}
- public static boolean parseNorms(FieldMapper.Builder builder, String propName, Object propNode, Mapper.TypeParser.ParserContext parserContext) {
+ public static boolean parseNorms(FieldMapper.Builder builder, String fieldName, String propName, Object propNode,
+ Mapper.TypeParser.ParserContext parserContext) {
if (propName.equals("norms")) {
if (propNode instanceof Map) {
final Map properties = nodeMapValue(propNode, "norms");
- for (Iterator> propsIterator = properties.entrySet().iterator(); propsIterator.hasNext();) {
+ for (Iterator> propsIterator = properties.entrySet().iterator(); propsIterator.hasNext(); ) {
Entry entry2 = propsIterator.next();
final String propName2 = entry2.getKey();
final Object propNode2 = entry2.getValue();
if (propName2.equals("enabled")) {
- builder.omitNorms(!lenientNodeBooleanValue(propNode2));
+ builder.omitNorms(nodeBooleanValue(fieldName, "enabled", propNode2, parserContext) == false);
propsIterator.remove();
} else if (propName2.equals("loading")) {
// ignore for bw compat
@@ -156,13 +176,14 @@ public static boolean parseNorms(FieldMapper.Builder builder, String propName, O
}
}
DocumentMapperParser.checkNoRemainingFields(propName, properties, parserContext.indexVersionCreated());
- DEPRECATION_LOGGER.deprecated("The [norms{enabled:true/false}] way of specifying norms is deprecated, please use [norms:true/false] instead");
+ DEPRECATION_LOGGER.deprecated("The [norms{enabled:true/false}] way of specifying norms is deprecated, please use " +
+ "[norms:true/false] instead");
} else {
- builder.omitNorms(nodeBooleanValue("norms", propNode, parserContext) == false);
+ builder.omitNorms(nodeBooleanValue(fieldName,"norms", propNode, parserContext) == false);
}
return true;
} else if (propName.equals("omit_norms")) {
- builder.omitNorms(nodeBooleanValue("norms", propNode, parserContext));
+ builder.omitNorms(nodeBooleanValue(fieldName,"norms", propNode, parserContext));
DEPRECATION_LOGGER.deprecated("[omit_norms] is deprecated, please use [norms] instead with the opposite boolean value");
return true;
} else {
@@ -174,14 +195,15 @@ public static boolean parseNorms(FieldMapper.Builder builder, String propName, O
* Parse text field attributes. In addition to {@link #parseField common attributes}
* this will parse analysis and term-vectors related settings.
*/
- public static void parseTextField(FieldMapper.Builder builder, String name, Map fieldNode, Mapper.TypeParser.ParserContext parserContext) {
+ public static void parseTextField(FieldMapper.Builder builder, String name, Map fieldNode,
+ Mapper.TypeParser.ParserContext parserContext) {
parseField(builder, name, fieldNode, parserContext);
parseAnalyzersAndTermVectors(builder, name, fieldNode, parserContext);
- for (Iterator> iterator = fieldNode.entrySet().iterator(); iterator.hasNext();) {
+ for (Iterator> iterator = fieldNode.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry entry = iterator.next();
final String propName = entry.getKey();
final Object propNode = entry.getValue();
- if (parseNorms(builder, propName, propNode, parserContext)) {
+ if (parseNorms(builder, name, propName, propNode, parserContext)) {
iterator.remove();
}
}
@@ -190,8 +212,8 @@ public static void parseTextField(FieldMapper.Builder builder, String name, Map<
/**
* Parse common field attributes such as {@code doc_values} or {@code store}.
*/
- public static void parseField(FieldMapper.Builder builder, String name, Map fieldNode, Mapper.TypeParser.ParserContext parserContext) {
- Version indexVersionCreated = parserContext.indexVersionCreated();
+ public static void parseField(FieldMapper.Builder builder, String name, Map fieldNode,
+ Mapper.TypeParser.ParserContext parserContext) {
for (Iterator> iterator = fieldNode.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = iterator.next();
final String propName = entry.getKey();
@@ -204,28 +226,29 @@ public static void parseField(FieldMapper.Builder builder, String name, Map) propNode;
} else {
throw new MapperParsingException("expected map for property [fields] on field [" + propNode + "] or " +
- "[" + propName + "] but got a " + propNode.getClass());
+ "[" + propName + "] but got a " + propNode.getClass());
}
for (Map.Entry multiFieldEntry : multiFieldsPropNodes.entrySet()) {
String multiFieldName = multiFieldEntry.getKey();
if (multiFieldName.contains(".")) {
- throw new MapperParsingException("Field name [" + multiFieldName + "] which is a multi field of [" + name + "] cannot contain '.'");
+ throw new MapperParsingException("Field name [" + multiFieldName + "] which is a multi field of [" + name + "] cannot" +
+ " contain '.'");
}
if (!(multiFieldEntry.getValue() instanceof Map)) {
throw new MapperParsingException("illegal field [" + multiFieldName + "], only fields can be specified inside fields");
@@ -343,40 +369,11 @@ public static void parseTermVector(String fieldName, String termVector, FieldMap
}
}
- private static boolean parseIndex(String fieldName, String index) throws MapperParsingException {
- switch (index) {
- case "true":
- return true;
- case "false":
- return false;
- case "not_analyzed":
- case "analyzed":
- case "no":
- DEPRECATION_LOGGER.deprecated("Expected a boolean for property [index] but got [{}]", index);
- return "no".equals(index) == false;
- default:
- throw new IllegalArgumentException("Can't parse [index] value [" + index + "] for field [" + fieldName + "], expected [true] or [false]");
- }
- }
-
- private static boolean parseStore(String store) throws MapperParsingException {
- if (BOOLEAN_STRINGS.contains(store) == false) {
- DEPRECATION_LOGGER.deprecated("Expected a boolean for property [store] but got [{}]", store);
- }
- if ("no".equals(store)) {
- return false;
- } else if ("yes".equals(store)) {
- return true;
- } else {
- return lenientNodeBooleanValue(store);
- }
- }
-
@SuppressWarnings("unchecked")
public static void parseCopyFields(Object propNode, FieldMapper.Builder builder) {
FieldMapper.CopyTo.Builder copyToBuilder = new FieldMapper.CopyTo.Builder();
if (isArray(propNode)) {
- for(Object node : (List