diff --git a/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java b/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java index 57043e9a70ff3..fc469ffaebb83 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java @@ -509,7 +509,7 @@ private static Engine.Result performOpOnReplica(DocWriteResponse primaryResponse final ShardId shardId = replica.shardId(); final SourceToParse sourceToParse = SourceToParse.source(shardId.getIndexName(), - indexRequest.type(), indexRequest.id(), indexRequest.source(), indexRequest.getContentType()) + indexRequest.type(), indexRequest.id(), indexRequest.source(), indexRequest.getContentType(), replica.shardId().getId()) .routing(indexRequest.routing()).parent(indexRequest.parent()); return replica.applyIndexOperationOnReplica(primaryResponse.getSeqNo(), primaryTerm, primaryResponse.getVersion(), indexRequest.versionType().versionTypeForReplicationAndRecovery(), indexRequest.getAutoGeneratedTimestamp(), @@ -535,7 +535,7 @@ private static Engine.Result performOpOnReplica(DocWriteResponse primaryResponse static Engine.IndexResult executeIndexRequestOnPrimary(IndexRequest request, IndexShard primary, MappingUpdatePerformer mappingUpdater) throws Exception { final SourceToParse sourceToParse = - SourceToParse.source(request.index(), request.type(), request.id(), request.source(), request.getContentType()) + SourceToParse.source(request.index(), request.type(), request.id(), request.source(), request.getContentType(), primary.shardId().getId()) .routing(request.routing()).parent(request.parent()); try { // if a mapping update is required to index this request, issue a mapping update on the master, and abort the diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index 8bc606d714166..34e4cf5641041 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -157,7 +157,7 @@ public IndexService( // The sort order is validated right after the merge of the mapping later in the process. this.indexSortSupplier = () -> indexSettings.getIndexSortConfig().buildIndexSort( mapperService::fullName, - indexFieldData::getForField + field -> indexFieldData.getForField(field, -1) ); } else { this.indexSortSupplier = () -> null; diff --git a/core/src/main/java/org/elasticsearch/index/IndexWarmer.java b/core/src/main/java/org/elasticsearch/index/IndexWarmer.java index e177ca668f472..ac6a168431617 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexWarmer.java +++ b/core/src/main/java/org/elasticsearch/index/IndexWarmer.java @@ -134,7 +134,7 @@ public TerminationHandle warmReader(final IndexShard indexShard, final Engine.Se executor.execute(() -> { try { final long start = System.nanoTime(); - IndexFieldData.Global ifd = indexFieldDataService.getForField(fieldType); + IndexFieldData.Global ifd = indexFieldDataService.getForField(fieldType, indexShard.shardId().getId()); DirectoryReader reader = searcher.getDirectoryReader(); IndexFieldData global = ifd.loadGlobal(reader); if (reader.leaves().isEmpty() == false) { diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java index 0b63dfb8df80a..16074e07e594e 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java @@ -223,7 +223,7 @@ public Object missingValue(boolean reversed) { interface Builder { IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, - CircuitBreakerService breakerService, MapperService mapperService); + CircuitBreakerService breakerService, MapperService mapperService, int shardId); } interface Global extends IndexFieldData { diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java b/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java index 2577d967e621e..3ae42aa24821a 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java @@ -106,7 +106,7 @@ public synchronized void clearField(final String fieldName) { } @SuppressWarnings("unchecked") - public > IFD getForField(MappedFieldType fieldType) { + public > IFD getForField(MappedFieldType fieldType, int shardId) { final String fieldName = fieldType.name(); IndexFieldData.Builder builder = fieldType.fielddataBuilder(); @@ -126,7 +126,7 @@ public > IFD getForField(MappedFieldType fieldType } } - return (IFD) builder.build(indexSettings, fieldType, cache, circuitBreakerService, mapperService); + return (IFD) builder.build(indexSettings, fieldType, cache, circuitBreakerService, mapperService, shardId); } /** diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointDVIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointDVIndexFieldData.java index 6c92d571196ec..21dd54cffc3b9 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointDVIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointDVIndexFieldData.java @@ -82,7 +82,7 @@ static void checkCompatible(FieldInfo fieldInfo) { public static class Builder implements IndexFieldData.Builder { @Override public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, - CircuitBreakerService breakerService, MapperService mapperService) { + CircuitBreakerService breakerService, MapperService mapperService, int shardId) { // ignore breaker return new LatLonPointDVIndexFieldData(indexSettings.getIndex(), fieldType.name()); } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/BytesBinaryDVIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/BytesBinaryDVIndexFieldData.java index 398093c034b79..95e89d2cba9b0 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/BytesBinaryDVIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/BytesBinaryDVIndexFieldData.java @@ -64,7 +64,7 @@ public static class Builder implements IndexFieldData.Builder { @Override public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, - CircuitBreakerService breakerService, MapperService mapperService) { + CircuitBreakerService breakerService, MapperService mapperService, int shardId) { // Ignore breaker final String fieldName = fieldType.name(); return new BytesBinaryDVIndexFieldData(indexSettings.getIndex(), fieldName); diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/ConstantIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/ConstantIndexFieldData.java index ebf959e92e1a6..a6ff98f493f4f 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/ConstantIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/ConstantIndexFieldData.java @@ -44,22 +44,22 @@ import java.io.IOException; import java.util.Collection; import java.util.Collections; -import java.util.function.Function; +import java.util.function.BiFunction; public class ConstantIndexFieldData extends AbstractIndexOrdinalsFieldData { public static class Builder implements IndexFieldData.Builder { - private final Function valueFunction; + private final BiFunction valueFunction; - public Builder(Function valueFunction) { + public Builder(BiFunction valueFunction) { this.valueFunction = valueFunction; } @Override public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, - CircuitBreakerService breakerService, MapperService mapperService) { - return new ConstantIndexFieldData(indexSettings, fieldType.name(), valueFunction.apply(mapperService)); + CircuitBreakerService breakerService, MapperService mapperService, int shardId) { + return new ConstantIndexFieldData(indexSettings, fieldType.name(), valueFunction.apply(mapperService, shardId)); } } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java index 4a066328bc2a9..0eaf6e44cc182 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/DocValuesIndexFieldData.java @@ -89,7 +89,7 @@ public Builder scriptFunction(Function> s @Override public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, - CircuitBreakerService breakerService, MapperService mapperService) { + CircuitBreakerService breakerService, MapperService mapperService, int shardId) { // Ignore Circuit Breaker final String fieldName = fieldType.name(); if (BINARY_INDEX_FIELD_NAMES.contains(fieldName)) { diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java index fa126d6813251..c3213b48d1a14 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java @@ -20,7 +20,6 @@ import org.apache.lucene.codecs.blocktree.FieldReader; import org.apache.lucene.codecs.blocktree.Stats; -import org.apache.lucene.index.Fields; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.PostingsEnum; @@ -66,7 +65,8 @@ public Builder(double minFrequency, double maxFrequency, int minSegmentSize) { @Override public IndexOrdinalsFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, - IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { + IndexFieldDataCache cache, CircuitBreakerService breakerService, + MapperService mapperService, int shardId) { return new PagedBytesIndexFieldData(indexSettings, fieldType.name(), cache, breakerService, minFrequency, maxFrequency, minSegmentSize); } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java index 81293b6d13cc7..1be7dd07ccb0f 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/IdFieldMapper.java @@ -164,8 +164,8 @@ public IndexFieldData.Builder fielddataBuilder() { return new IndexFieldData.Builder() { @Override public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, - CircuitBreakerService breakerService, MapperService mapperService) { - final IndexFieldData fieldData = fieldDataBuilder.build(indexSettings, fieldType, cache, breakerService, mapperService); + CircuitBreakerService breakerService, MapperService mapperService, int shardId) { + final IndexFieldData fieldData = fieldDataBuilder.build(indexSettings, fieldType, cache, breakerService, mapperService, shardId); if (indexSettings.getIndexVersionCreated().before(Version.V_6_0_0_beta1)) { // ids were indexed as utf-8 return fieldData; diff --git a/core/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java index c85f5d7d9fa9d..b43660ecf13fd 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java @@ -157,7 +157,7 @@ private boolean isSameIndex(Object value, String indexName) { @Override public IndexFieldData.Builder fielddataBuilder() { - return new ConstantIndexFieldData.Builder(mapperService -> mapperService.index().getName()); + return new ConstantIndexFieldData.Builder((mapperService, shardId) -> mapperService.index().getName()); } } 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 7059345174959..f15d8e861e56c 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java @@ -264,10 +264,10 @@ public IndexFieldData.Builder fielddataBuilder() { return new IndexFieldData.Builder() { @Override public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, - CircuitBreakerService breakerService, MapperService mapperService) { + CircuitBreakerService breakerService, MapperService mapperService, int shardId) { final IndexNumericFieldData scaledValues = (IndexNumericFieldData) new DocValuesIndexFieldData.Builder() .numericType(IndexNumericFieldData.NumericType.LONG) - .build(indexSettings, fieldType, cache, breakerService, mapperService); + .build(indexSettings, fieldType, cache, breakerService, mapperService, shardId); return new ScaledFloatIndexFieldData(scaledValues, scalingFactor); } }; diff --git a/core/src/main/java/org/elasticsearch/index/mapper/ShardIdFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/ShardIdFieldMapper.java new file mode 100644 index 0000000000000..ef581e7312cc0 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/index/mapper/ShardIdFieldMapper.java @@ -0,0 +1,168 @@ +/* + * 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.index.mapper; + +import org.apache.lucene.document.SortedDocValuesField; +import org.apache.lucene.index.IndexOptions; +import org.apache.lucene.index.IndexableField; +import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.MatchNoDocsQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.Version; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.ToXContent.Params; +import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.fielddata.IndexFieldData; +import org.elasticsearch.index.fielddata.IndexFieldDataCache; +import org.elasticsearch.index.fielddata.plain.ConstantIndexFieldData; +import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData; +import org.elasticsearch.index.mapper.IdFieldMapper.IdFieldType; +import org.elasticsearch.index.query.QueryShardContext; +import org.elasticsearch.indices.breaker.CircuitBreakerService; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** + * A mapper that stores the shard id that documents are assigned to. + * This field is doc-valued instead of being a view like _index so that (shard_id, seq_no) pairs are still unique after shrinking. + */ +public class ShardIdFieldMapper extends MetadataFieldMapper { + + public static final String NAME = "_shard"; + + public static class TypeParser implements MetadataFieldMapper.TypeParser { + @Override + public MetadataFieldMapper.Builder parse(String name, Map node, + ParserContext parserContext) throws MapperParsingException { + throw new MapperParsingException(NAME + " is not configurable"); + } + + @Override + public MetadataFieldMapper getDefault(MappedFieldType fieldType, ParserContext context) { + assert fieldType == null || fieldType.equals(new ShardIdFieldType()); + final IndexSettings indexSettings = context.mapperService().getIndexSettings(); + return new ShardIdFieldMapper(indexSettings); + } + } + + static class ShardIdFieldType extends MappedFieldType { + + ShardIdFieldType() { + setName(NAME); + setHasDocValues(true); + setIndexOptions(IndexOptions.NONE); + } + + protected ShardIdFieldType(ShardIdFieldType ref) { + super(ref); + } + + @Override + public MappedFieldType clone() { + return new ShardIdFieldType(this); + } + + @Override + public String typeName() { + return NAME; + } + + @Override + public Query termQuery(Object value, QueryShardContext context) { + BytesRef binaryValue; + if (value instanceof BytesRef) { + binaryValue = (BytesRef) value; + } else { + binaryValue = new BytesRef(value.toString()); + } + + if (context.indexVersionCreated().before(Version.V_6_0_0_beta1)) { + if (binaryValue.bytesEquals(new BytesRef(Integer.toString(context.getShardId())))) { + return new MatchAllDocsQuery(); + } else { + return new MatchNoDocsQuery("Different shard than the requested one"); + } + } else { + // We use doc values for querying. + // This is fine since in the common case either we are on the right shard + // and we will return the doc values iterator, or we are on a different shard + // and we will return a null scorer since the term can't be found in the terms + // dict. + return SortedDocValuesField.newExactQuery(NAME, binaryValue); + } + } + + @Override + public IndexFieldData.Builder fielddataBuilder() { + IndexFieldData.Builder view = new ConstantIndexFieldData.Builder((mapperService, shardId) -> Integer.toString(shardId)); + IndexFieldData.Builder dv = new DocValuesIndexFieldData.Builder(); + return new IndexFieldData.Builder() { + @Override + public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, + CircuitBreakerService breakerService, MapperService mapperService, int shardId) { + if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_0_0_beta1)) { + return dv.build(indexSettings, fieldType, cache, breakerService, mapperService, shardId); + } else { + if (shardId == -1) { + throw new IllegalArgumentException("The shard id is not usable with 5.x indices and index sorting or scripts"); + } + return view.build(indexSettings, fieldType, cache, breakerService, mapperService, shardId); + } + } + }; + } + } + + private final boolean pre6x; + + protected ShardIdFieldMapper(IndexSettings indexSettings) { + super(NAME, new ShardIdFieldType(), new ShardIdFieldType(), indexSettings.getSettings()); + pre6x = indexSettings.getIndexVersionCreated().before(Version.V_6_0_0_beta1); + } + + @Override + public void preParse(ParseContext context) throws IOException { + super.parse(context); + } + + @Override + public void postParse(ParseContext context) throws IOException {} + + @Override + protected void parseCreateField(ParseContext context, List fields) throws IOException { + if (pre6x == false) { + fields.add(new SortedDocValuesField(NAME, new BytesRef(Integer.toString(context.sourceToParse().shardId())))); + } + } + + @Override + protected String contentType() { + return NAME; + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + // nothing to serialize since it is not configurable + return builder; + } +} diff --git a/core/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java b/core/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java index 52e3001da84cd..b887a58fa89d6 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java @@ -27,9 +27,9 @@ public class SourceToParse { - public static SourceToParse source(String index, String type, String id, BytesReference source, - XContentType contentType) { - return new SourceToParse(index, type, id, source, contentType); + public static SourceToParse source(String index, String type, String id,BytesReference source, + XContentType contentType, int shardId) { + return new SourceToParse(index, type, id, source, contentType, shardId); } private final BytesReference source; @@ -40,13 +40,15 @@ public static SourceToParse source(String index, String type, String id, BytesRe private final String id; + private final int shardId; + private String routing; private String parentId; private XContentType xContentType; - private SourceToParse(String index, String type, String id, BytesReference source, XContentType xContentType) { + private SourceToParse(String index, String type, String id, BytesReference source, XContentType xContentType, int shardId) { this.index = Objects.requireNonNull(index); this.type = Objects.requireNonNull(type); this.id = Objects.requireNonNull(id); @@ -54,6 +56,7 @@ private SourceToParse(String index, String type, String id, BytesReference sourc // so, we might as well do it here, and improve the performance of working with direct byte arrays this.source = new BytesArray(Objects.requireNonNull(source).toBytesRef()); this.xContentType = Objects.requireNonNull(xContentType); + this.shardId = shardId; } public BytesReference source() { @@ -94,6 +97,10 @@ public SourceToParse routing(String routing) { return this; } + public int shardId() { + return shardId; + } + public enum Origin { PRIMARY, REPLICA diff --git a/core/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java index 6c645c24ebb37..84d1fc3a42acb 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java @@ -51,7 +51,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Function; +import java.util.function.BiFunction; public class TypeFieldMapper extends MetadataFieldMapper { @@ -114,7 +114,7 @@ public IndexFieldData.Builder fielddataBuilder() { return new DocValuesIndexFieldData.Builder(); } else { // means the index has a single type and the type field is implicit - Function typeFunction = mapperService -> { + BiFunction typeFunction = (mapperService, shardId) -> { Collection types = mapperService.types(); if (types.size() > 1) { throw new AssertionError(); diff --git a/core/src/main/java/org/elasticsearch/index/mapper/UidFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/UidFieldMapper.java index b2d62c625fa80..76151b4033983 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/UidFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/UidFieldMapper.java @@ -116,10 +116,10 @@ public IndexFieldData.Builder fielddataBuilder() { return new IndexFieldData.Builder() { @Override public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, - CircuitBreakerService breakerService, MapperService mapperService) { + CircuitBreakerService breakerService, MapperService mapperService, int shardId) { MappedFieldType idFieldType = mapperService.fullName(IdFieldMapper.NAME); IndexFieldData idFieldData = idFieldType.fielddataBuilder() - .build(indexSettings, idFieldType, cache, breakerService, mapperService); + .build(indexSettings, idFieldType, cache, breakerService, mapperService, shardId); final String type = mapperService.types().iterator().next(); return new UidIndexFieldData(indexSettings.getIndex(), type, idFieldData); } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java index 8f1615cde7dc3..31d48f03fd04a 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -155,7 +155,7 @@ public BitSetProducer bitsetFilter(Query filter) { } public > IFD getForField(MappedFieldType mapper) { - return indexFieldDataService.getForField(mapper); + return indexFieldDataService.getForField(mapper, shardId); } public void addNamedQuery(String name, Query query) { diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 8637b79ca35a0..90240c12a1c8b 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -1189,7 +1189,8 @@ public Engine.Result applyTranslogOperation(Translog.Operation operation, Engine // autoGeneratedID docs that are coming from the primary are updated correctly. result = applyIndexOperation(index.seqNo(), index.primaryTerm(), index.version(), index.versionType().versionTypeForReplicationAndRecovery(), index.getAutoGeneratedIdTimestamp(), true, origin, - source(shardId.getIndexName(), index.type(), index.id(), index.source(), XContentFactory.xContentType(index.source())) + source(shardId.getIndexName(), index.type(), index.id(), index.source(), + XContentFactory.xContentType(index.source()), shardId.getId()) .routing(index.routing()).parent(index.parent()), onMappingUpdate); break; case DELETE: diff --git a/core/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java b/core/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java index 495f1dc4bdb9a..272be26fb2b65 100644 --- a/core/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java +++ b/core/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java @@ -305,7 +305,8 @@ private static ParsedDocument parseDocument(IndexShard indexShard, String index, XContentType xContentType) { MapperService mapperService = indexShard.mapperService(); DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type); - ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse(source(index, type, "_id_for_tv_api", doc, xContentType)); + ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse(source(index, type, "_id_for_tv_api", doc, xContentType, + indexShard.shardId().getId())); if (docMapper.getMapping() != null) { parsedDocument.addDynamicMappingsUpdate(docMapper.getMapping()); } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesModule.java b/core/src/main/java/org/elasticsearch/indices/IndicesModule.java index bbcc508dbd589..e3ea7f1526bbc 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesModule.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesModule.java @@ -48,6 +48,7 @@ import org.elasticsearch.index.mapper.RoutingFieldMapper; import org.elasticsearch.index.mapper.ScaledFloatFieldMapper; import org.elasticsearch.index.mapper.SeqNoFieldMapper; +import org.elasticsearch.index.mapper.ShardIdFieldMapper; import org.elasticsearch.index.mapper.SourceFieldMapper; import org.elasticsearch.index.mapper.TextFieldMapper; import org.elasticsearch.index.mapper.TokenCountFieldMapper; @@ -142,6 +143,7 @@ private Map getMetadataMappers(List= subReaderContext.docBase + subReaderContext.reader().maxDoc()) { int readerIndex = ReaderUtil.subIndex(hit.docId(), context.searcher().getIndexReader().leaves()); subReaderContext = context.searcher().getIndexReader().leaves().get(readerIndex); - data = context.fieldData().getForField(fieldType).load(subReaderContext); + data = context.fieldData().getForField(fieldType, context.indexShard().shardId().getId()).load(subReaderContext); values = data.getScriptValues(); } int subDocId = hit.docId() - subReaderContext.docBase; diff --git a/core/src/main/java/org/elasticsearch/search/lookup/LeafDocLookup.java b/core/src/main/java/org/elasticsearch/search/lookup/LeafDocLookup.java index 5c75c4a6b1d81..dabe75ae05cc3 100644 --- a/core/src/main/java/org/elasticsearch/search/lookup/LeafDocLookup.java +++ b/core/src/main/java/org/elasticsearch/search/lookup/LeafDocLookup.java @@ -49,7 +49,8 @@ public class LeafDocLookup implements Map> { private int docId = -1; - LeafDocLookup(MapperService mapperService, IndexFieldDataService fieldDataService, @Nullable String[] types, LeafReaderContext reader) { + LeafDocLookup(MapperService mapperService, IndexFieldDataService fieldDataService, + @Nullable String[] types, LeafReaderContext reader) { this.mapperService = mapperService; this.fieldDataService = fieldDataService; this.types = types; @@ -83,7 +84,7 @@ public ScriptDocValues get(Object key) { scriptValues = AccessController.doPrivileged(new PrivilegedAction>() { @Override public ScriptDocValues run() { - return fieldDataService.getForField(fieldType).load(reader).getScriptValues(); + return fieldDataService.getForField(fieldType, -1).load(reader).getScriptValues(); } }); localCacheFieldData.put(fieldName, scriptValues); diff --git a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java index f914c921a47f5..5f596e7f00d10 100644 --- a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java +++ b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java @@ -105,7 +105,7 @@ public void execute(SearchContext searchContext) throws QueryPhaseExecutionExcep // here to make sure it happens during the QUERY phase aggregationPhase.preProcess(searchContext); Sort indexSort = searchContext.mapperService().getIndexSettings().getIndexSortConfig() - .buildIndexSort(searchContext.mapperService()::fullName, searchContext.fieldData()::getForField); + .buildIndexSort(searchContext.mapperService()::fullName, field -> searchContext.fieldData().getForField(field, -1)); final ContextIndexSearcher searcher = searchContext.searcher(); boolean rescore = execute(searchContext, searchContext.searcher(), searcher::setCheckCancelled, indexSort); diff --git a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index b659f7dbae2e2..a24cf8939387e 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -2825,7 +2825,7 @@ private Engine.Operation convertToEngineOp(Translog.Operation operation, Engine. final String indexName = mapperService.index().getName(); final Engine.Index engineIndex = IndexShard.prepareIndex(docMapper(index.type()), mapperService.getIndexSettings().getIndexVersionCreated(), - source(indexName, index.type(), index.id(), index.source(), XContentFactory.xContentType(index.source())) + source(indexName, index.type(), index.id(), index.source(), XContentFactory.xContentType(index.source()), 0) .routing(index.routing()).parent(index.parent()), index.seqNo(), index.primaryTerm(), index.version(), index.versionType().versionTypeForReplicationAndRecovery(), origin, index.getAutoGeneratedIdTimestamp(), true); diff --git a/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java b/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java index b9e3a0813b29b..e01716f63e622 100644 --- a/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java @@ -129,7 +129,7 @@ public > IFD getForField(String type, String field } else { throw new UnsupportedOperationException(type); } - return ifdService.getForField(fieldType); + return ifdService.getForField(fieldType, 0); } @Before diff --git a/core/src/test/java/org/elasticsearch/index/fielddata/BinaryDVFieldDataTests.java b/core/src/test/java/org/elasticsearch/index/fielddata/BinaryDVFieldDataTests.java index 64dcf0a0943b9..405ca80aa320a 100644 --- a/core/src/test/java/org/elasticsearch/index/fielddata/BinaryDVFieldDataTests.java +++ b/core/src/test/java/org/elasticsearch/index/fielddata/BinaryDVFieldDataTests.java @@ -62,16 +62,16 @@ public void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - ParsedDocument d = mapper.parse(SourceToParse.source("test", "test", "1", doc.bytes(), XContentType.JSON)); + ParsedDocument d = mapper.parse(SourceToParse.source("test", "test", "1", doc.bytes(), XContentType.JSON, 0)); writer.addDocument(d.rootDoc()); BytesRef bytes1 = randomBytes(); doc = XContentFactory.jsonBuilder().startObject().field("field", bytes1).endObject(); - d = mapper.parse(SourceToParse.source("test", "test", "2", doc.bytes(), XContentType.JSON)); + d = mapper.parse(SourceToParse.source("test", "test", "2", doc.bytes(), XContentType.JSON, 0)); writer.addDocument(d.rootDoc()); doc = XContentFactory.jsonBuilder().startObject().endObject(); - d = mapper.parse(SourceToParse.source("test", "test", "3", doc.bytes(), XContentType.JSON)); + d = mapper.parse(SourceToParse.source("test", "test", "3", doc.bytes(), XContentType.JSON, 0)); writer.addDocument(d.rootDoc()); // test remove duplicate value @@ -87,7 +87,7 @@ public void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - d = mapper.parse(SourceToParse.source("test", "test", "4", doc.bytes(), XContentType.JSON)); + d = mapper.parse(SourceToParse.source("test", "test", "4", doc.bytes(), XContentType.JSON, 0)); writer.addDocument(d.rootDoc()); IndexFieldData indexFieldData = getForField("field"); diff --git a/core/src/test/java/org/elasticsearch/index/fielddata/FilterFieldDataTests.java b/core/src/test/java/org/elasticsearch/index/fielddata/FilterFieldDataTests.java index 19725aca523ac..26a78ad7eff61 100644 --- a/core/src/test/java/org/elasticsearch/index/fielddata/FilterFieldDataTests.java +++ b/core/src/test/java/org/elasticsearch/index/fielddata/FilterFieldDataTests.java @@ -68,7 +68,7 @@ public void testFilterByFrequency() throws Exception { .fielddata(true) .fielddataFrequencyFilter(0, random.nextBoolean() ? 100 : 0.5d, 0) .build(builderCtx).fieldType(); - IndexOrdinalsFieldData fieldData = ifdService.getForField(ft); + IndexOrdinalsFieldData fieldData = ifdService.getForField(ft, 0); for (LeafReaderContext context : contexts) { AtomicOrdinalsFieldData loadDirect = fieldData.loadDirect(context); SortedSetDocValues bytesValues = loadDirect.getOrdinalsValues(); @@ -83,7 +83,7 @@ public void testFilterByFrequency() throws Exception { .fielddata(true) .fielddataFrequencyFilter(random.nextBoolean() ? 101 : 101d/200.0d, 201, 100) .build(builderCtx).fieldType(); - IndexOrdinalsFieldData fieldData = ifdService.getForField(ft); + IndexOrdinalsFieldData fieldData = ifdService.getForField(ft, 0); for (LeafReaderContext context : contexts) { AtomicOrdinalsFieldData loadDirect = fieldData.loadDirect(context); SortedSetDocValues bytesValues = loadDirect.getOrdinalsValues(); @@ -98,7 +98,7 @@ public void testFilterByFrequency() throws Exception { .fielddata(true) .fielddataFrequencyFilter(random.nextBoolean() ? 101 : 101d/200.0d, Integer.MAX_VALUE, 101) .build(builderCtx).fieldType(); - IndexOrdinalsFieldData fieldData = ifdService.getForField(ft); + IndexOrdinalsFieldData fieldData = ifdService.getForField(ft, 0); for (LeafReaderContext context : contexts) { AtomicOrdinalsFieldData loadDirect = fieldData.loadDirect(context); SortedSetDocValues bytesValues = loadDirect.getOrdinalsValues(); @@ -114,7 +114,7 @@ public void testFilterByFrequency() throws Exception { .fielddata(true) .fielddataFrequencyFilter(random.nextBoolean() ? 101 : 101d/200.0d, Integer.MAX_VALUE, 101) .build(builderCtx).fieldType(); - IndexOrdinalsFieldData fieldData = ifdService.getForField(ft); + IndexOrdinalsFieldData fieldData = ifdService.getForField(ft, 0); for (LeafReaderContext context : contexts) { AtomicOrdinalsFieldData loadDirect = fieldData.loadDirect(context); SortedSetDocValues bytesValues = loadDirect.getOrdinalsValues(); diff --git a/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java b/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java index cefa9c74ea38d..95bc0e6fa169b 100644 --- a/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/fielddata/IndexFieldDataServiceTests.java @@ -71,7 +71,7 @@ public void testGetForFieldDefaults() { final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1)); final MappedFieldType stringMapper = new KeywordFieldMapper.Builder("string").build(ctx).fieldType(); ifdService.clear(); - IndexFieldData fd = ifdService.getForField(stringMapper); + IndexFieldData fd = ifdService.getForField(stringMapper, 0); assertTrue(fd instanceof SortedSetDVOrdinalsIndexFieldData); for (MappedFieldType mapper : Arrays.asList( @@ -81,20 +81,20 @@ public void testGetForFieldDefaults() { new NumberFieldMapper.Builder("long", NumberFieldMapper.NumberType.LONG).build(ctx).fieldType() )) { ifdService.clear(); - fd = ifdService.getForField(mapper); + fd = ifdService.getForField(mapper, 0); assertTrue(fd instanceof SortedNumericDVIndexFieldData); } final MappedFieldType floatMapper = new NumberFieldMapper.Builder("float", NumberFieldMapper.NumberType.FLOAT) .build(ctx).fieldType(); ifdService.clear(); - fd = ifdService.getForField(floatMapper); + fd = ifdService.getForField(floatMapper, 0); assertTrue(fd instanceof SortedNumericDVIndexFieldData); final MappedFieldType doubleMapper = new NumberFieldMapper.Builder("double", NumberFieldMapper.NumberType.DOUBLE) .build(ctx).fieldType(); ifdService.clear(); - fd = ifdService.getForField(doubleMapper); + fd = ifdService.getForField(doubleMapper, 0); assertTrue(fd instanceof SortedNumericDVIndexFieldData); } @@ -137,7 +137,7 @@ public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, lon onRemovalCalled.incrementAndGet(); } }); - IndexFieldData ifd = ifdService.getForField(mapper1); + IndexFieldData ifd = ifdService.getForField(mapper1, 0); LeafReaderContext leafReaderContext = reader.getContext().leaves().get(0); AtomicFieldData load = ifd.load(leafReaderContext); assertEquals(1, onCacheCalled.get()); @@ -178,10 +178,10 @@ private void doTestRequireDocValues(MappedFieldType ft) { IndexFieldDataService ifds = new IndexFieldDataService(IndexSettingsModule.newIndexSettings("test", Settings.EMPTY), cache, null, null); ft.setName("some_long"); ft.setHasDocValues(true); - ifds.getForField(ft); // no exception + ifds.getForField(ft, 0); // no exception ft.setHasDocValues(false); try { - ifds.getForField(ft); + ifds.getForField(ft, 0); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("doc values")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java index fac6e4c84b18c..ea4719faa87b3 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/BinaryFieldMapperTests.java @@ -95,7 +95,7 @@ public void testStoredValue() throws IOException { for (byte[] value : Arrays.asList(binaryValue1, binaryValue2)) { ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "id", XContentFactory.jsonBuilder().startObject().field("field", value).endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); BytesRef indexedValue = doc.rootDoc().getBinaryValue("field"); assertEquals(new BytesRef(value), indexedValue); FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper("field"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java index e6a1c0a69d81a..ba4760c529efc 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java @@ -86,7 +86,7 @@ public void testDefaults() throws IOException { .field("field", true) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); try (Directory dir = new RAMDirectory(); IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(new MockAnalyzer(random())))) { @@ -158,7 +158,7 @@ public void testParsesPreEs6BooleansLenient() throws IOException { .field("field2", truthy) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); Document doc = parsedDoc.rootDoc(); assertEquals("F", doc.getField("field1").stringValue()); assertEquals("T", doc.getField("field2").stringValue()); @@ -194,7 +194,7 @@ public void testParsesEs6BooleansStrict() throws IOException { .field("field", randomFrom("off", "no", "0", "on", "yes", "1")) .endObject().bytes(); MapperParsingException ex = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON))); + () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON, 0))); assertEquals("failed to parse [field]", ex.getMessage()); } @@ -217,7 +217,7 @@ public void testMultiFields() throws IOException { .startObject() .field("field", false) .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON, 0)); assertNotNull(doc.rootDoc().getField("field.as_string")); } @@ -247,7 +247,7 @@ public void testDocValues() throws Exception { .field("bool3", true) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); Document doc = parsedDoc.rootDoc(); IndexableField[] fields = doc.getFields("bool1"); assertEquals(2, fields.length); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java b/core/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java index ac14f2905cf3b..fac22d6bab906 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java @@ -38,7 +38,7 @@ public void testCamelCaseFieldNameStaysAsIs() throws Exception { ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject() .field("thisIsCamelCase", "value1") .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertNotNull(doc.dynamicMappingsUpdate()); client().admin().indices().preparePutMapping("test").setType("type") diff --git a/core/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java index 5da524b69c0e6..44bb07e794b38 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java @@ -158,7 +158,7 @@ public void testParsingMinimal() throws Exception { .field("completion", "suggestion") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertSuggestFields(fields, 1); } @@ -178,7 +178,7 @@ public void testParsingMultiValued() throws Exception { .array("completion", "suggestion1", "suggestion2") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertSuggestFields(fields, 2); } @@ -201,7 +201,7 @@ public void testParsingWithWeight() throws Exception { .endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertSuggestFields(fields, 1); } @@ -224,7 +224,7 @@ public void testParsingMultiValueWithWeight() throws Exception { .endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertSuggestFields(fields, 3); } @@ -257,7 +257,7 @@ public void testParsingFull() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertSuggestFields(fields, 3); } @@ -290,7 +290,7 @@ public void testParsingMixed() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertSuggestFields(fields, 6); } @@ -315,7 +315,7 @@ public void testNonContextEnabledParsingWithContexts() throws Exception { .endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); fail("Supplying contexts to a non context-enabled field should error"); } catch (MapperParsingException e) { assertThat(e.getRootCause().getMessage(), containsString("field1")); @@ -339,7 +339,7 @@ public void testFieldValueValidation() throws Exception { .field("completion", charsRefBuilder.get().toString()) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); fail("No error indexing value with reserved character [0x1F]"); } catch (MapperParsingException e) { Throwable cause = e.unwrapCause().getCause(); @@ -354,7 +354,7 @@ public void testFieldValueValidation() throws Exception { .field("completion", charsRefBuilder.get().toString()) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); fail("No error indexing value with reserved character [0x0]"); } catch (MapperParsingException e) { Throwable cause = e.unwrapCause().getCause(); @@ -369,7 +369,7 @@ public void testFieldValueValidation() throws Exception { .field("completion", charsRefBuilder.get().toString()) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); fail("No error indexing value with reserved character [0x1E]"); } catch (MapperParsingException e) { Throwable cause = e.unwrapCause().getCause(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java index 4b2f629c36eea..6d269e84821b5 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java @@ -94,7 +94,7 @@ public void testCopyToFieldsParsing() throws Exception { .field("int_to_str_test", 42) .endObject().bytes(); - ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)); + ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON, 0)); ParseContext.Document doc = parsedDoc.rootDoc(); assertThat(doc.getFields("copy_test").length, equalTo(2)); assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo")); @@ -150,7 +150,7 @@ public void testCopyToFieldsInnerObjectParsing() throws Exception { .endObject().bytes(); ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, - XContentType.JSON)).rootDoc(); + XContentType.JSON, 0)).rootDoc(); assertThat(doc.getFields("copy_test").length, equalTo(1)); assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo")); @@ -177,7 +177,7 @@ public void testCopyToDynamicInnerObjectParsing() throws Exception { .endObject().bytes(); ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, - XContentType.JSON)).rootDoc(); + XContentType.JSON, 0)).rootDoc(); assertThat(doc.getFields("copy_test").length, equalTo(1)); assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo")); @@ -214,7 +214,7 @@ public void testCopyToDynamicInnerInnerObjectParsing() throws Exception { .endObject().bytes(); ParseContext.Document doc = docMapper.parse(SourceToParse.source("test", "type1", "1", json, - XContentType.JSON)).rootDoc(); + XContentType.JSON, 0)).rootDoc(); assertThat(doc.getFields("copy_test").length, equalTo(1)); assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo")); @@ -243,7 +243,7 @@ public void testCopyToStrictDynamicInnerObjectParsing() throws Exception { .endObject().bytes(); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON, 0)).rootDoc(); fail(); } catch (MapperParsingException ex) { assertThat(ex.getMessage(), startsWith("mapping set to strict, dynamic introduction of [very] within [type1] is not allowed")); @@ -277,7 +277,7 @@ public void testCopyToInnerStrictDynamicInnerObjectParsing() throws Exception { .endObject().bytes(); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON, 0)).rootDoc(); fail(); } catch (MapperParsingException ex) { assertThat(ex.getMessage(), startsWith("mapping set to strict, dynamic introduction of [field] within [very.far] is not allowed")); @@ -380,7 +380,7 @@ public void testCopyToNestedField() throws Exception { .endArray() .endObject(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", jsonDoc.bytes(), XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", jsonDoc.bytes(), XContentType.JSON, 0)); assertEquals(6, doc.docs().size()); Document nested = doc.docs().get(0); @@ -442,7 +442,7 @@ public void testCopyToDynamicNestedObjectParsing() throws Exception { .endObject().bytes(); try { - docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(SourceToParse.source("test", "type1", "1", json, XContentType.JSON, 0)).rootDoc(); fail(); } catch (MapperParsingException ex) { assertThat(ex.getMessage(), startsWith("It is forbidden to create dynamic nested objects ([very]) through `copy_to`")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java index 747e4b498da95..f5e40421edd58 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java @@ -69,7 +69,7 @@ public void testDefaults() throws Exception { .field("field", "2016-03-11") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -98,7 +98,7 @@ public void testNotIndexed() throws Exception { .field("field", "2016-03-11") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -120,7 +120,7 @@ public void testNoDocValues() throws Exception { .field("field", "2016-03-11") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -142,7 +142,7 @@ public void testStore() throws Exception { .field("field", "2016-03-11") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(3, fields.length); @@ -169,7 +169,7 @@ public void testIgnoreMalformed() throws Exception { .field("field", "2016-03-99") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); MapperParsingException e = expectThrows(MapperParsingException.class, runnable); assertThat(e.getCause().getMessage(), containsString("Cannot parse \"2016-03-99\"")); @@ -185,7 +185,7 @@ public void testIgnoreMalformed() throws Exception { .field("field", ":1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); @@ -206,7 +206,7 @@ public void testChangeFormat() throws IOException { .field("field", 1457654400) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -228,7 +228,7 @@ public void testChangeLocale() throws IOException { .field("field", 1457654400) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); } public void testNullValue() throws IOException { @@ -249,7 +249,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); mapping = XContentFactory.jsonBuilder().startObject() @@ -270,7 +270,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); IndexableField pointField = fields[0]; @@ -339,7 +339,7 @@ public void testTimeZoneParsing() throws Exception { .field("field", DateTimeFormat.forPattern(timeZonePattern).print(randomDate)) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DocumentMapperMergeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DocumentMapperMergeTests.java index e0f3bb9ccb1d3..9d13a8d498a64 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DocumentMapperMergeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DocumentMapperMergeTests.java @@ -165,7 +165,7 @@ public void run() { "test", fieldName, new BytesArray("{ \"" + fieldName + "\" : \"test\" }"), - XContentType.JSON)); + XContentType.JSON, 0)); Mapping update = doc.dynamicMappingsUpdate(); assert update != null; lastIntroducedFieldName.set(fieldName); @@ -188,7 +188,7 @@ public void run() { "test", "random", source, - XContentType.JSON)); + XContentType.JSON, 0)); if (parsedDoc.dynamicMappingsUpdate() != null) { // not in the mapping yet, try again continue; diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java index 4d83cc998462c..209e1c8a7de4a 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -70,7 +70,7 @@ public void testFieldDisabled() throws Exception { .field("foo", "1234") .field("bar", 10) .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertNull(doc.rootDoc().getField("foo")); assertNotNull(doc.rootDoc().getField("bar")); assertNotNull(doc.rootDoc().getField(IdFieldMapper.NAME)); @@ -95,7 +95,7 @@ public void testDotsWithExistingMapper() throws Exception { .field("baz", 789) .endObject() .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertNull(doc.dynamicMappingsUpdate()); // no update! String[] values = doc.rootDoc().getValues("foo.bar.baz"); assertEquals(3, values.length); @@ -117,7 +117,7 @@ public void testDotsWithExistingNestedMapper() throws Exception { .field("foo.bar", 123) .endObject().bytes(); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals( "Cannot add a value for field [foo.bar] since one of the intermediate objects is mapped as a nested object: [foo]", e.getMessage()); @@ -143,7 +143,7 @@ public void testDotsWithDynamicNestedMapper() throws Exception { .field("foo.bar",42) .endObject().bytes(); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals( "It is forbidden to create dynamic nested objects ([foo]) through `copy_to` or dots in field names", e.getMessage()); @@ -195,7 +195,7 @@ public void testNestedHaveIdAndTypeFields() throws Exception { doc.endObject(); // Verify in the case where multiple types are allowed that the _uid field is added to nested documents: - ParsedDocument result = mapper1.parse(SourceToParse.source("index1", "type", "1", doc.bytes(), XContentType.JSON)); + ParsedDocument result = mapper1.parse(SourceToParse.source("index1", "type", "1", doc.bytes(), XContentType.JSON, 0)); assertEquals(2, result.docs().size()); // Nested document: assertNull(result.docs().get(0).getField(IdFieldMapper.NAME)); @@ -215,7 +215,7 @@ public void testNestedHaveIdAndTypeFields() throws Exception { assertEquals("value2", result.docs().get(1).getField("baz").binaryValue().utf8ToString()); // Verify in the case where only a single type is allowed that the _id field is added to nested documents: - result = mapper2.parse(SourceToParse.source("index2", "type", "1", doc.bytes(), XContentType.JSON)); + result = mapper2.parse(SourceToParse.source("index2", "type", "1", doc.bytes(), XContentType.JSON, 0)); assertEquals(2, result.docs().size()); // Nested document: assertNull(result.docs().get(0).getField(UidFieldMapper.NAME)); @@ -249,7 +249,7 @@ public void testPropagateDynamicWithExistingMapper() throws Exception { .startObject().startObject("foo") .field("bar", "something") .endObject().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertNotNull(doc.dynamicMappingsUpdate()); assertNotNull(doc.rootDoc().getField("foo.bar")); } @@ -269,7 +269,7 @@ public void testPropagateDynamicWithDynamicMapper() throws Exception { .startObject().startObject("foo").startObject("bar") .field("baz", "something") .endObject().endObject().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertNotNull(doc.dynamicMappingsUpdate()); assertNotNull(doc.rootDoc().getField("foo.bar.baz")); } @@ -288,7 +288,7 @@ public void testDynamicRootFallback() throws Exception { .startObject().startObject("foo") .field("bar", "something") .endObject().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertNull(doc.dynamicMappingsUpdate()); assertNull(doc.rootDoc().getField("foo.bar")); } @@ -416,7 +416,7 @@ public void testDynamicGeoPointArrayWithTemplate() throws Exception { .startArray().value(0).value(0).endArray() .startArray().value(1).value(1).endArray() .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(2, doc.rootDoc().getFields("foo").length); } @@ -434,7 +434,7 @@ public void testDynamicLongArrayWithTemplate() throws Exception { .value(0) .value(1) .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(4, doc.rootDoc().getFields("foo").length); } @@ -449,7 +449,7 @@ public void testDynamicLongArray() throws Exception { .value(0) .value(1) .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(4, doc.rootDoc().getFields("foo").length); } @@ -464,7 +464,7 @@ public void testDynamicFalseLongArray() throws Exception { .value(0) .value(1) .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(0, doc.rootDoc().getFields("foo").length); } @@ -480,7 +480,7 @@ public void testDynamicStrictLongArray() throws Exception { .value(1) .endArray().endObject().bytes(); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -496,7 +496,7 @@ public void testMappedGeoPointArray() throws Exception { .startArray().value(0).value(0).endArray() .startArray().value(1).value(1).endArray() .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(2, doc.rootDoc().getFields("foo").length); } @@ -512,7 +512,7 @@ public void testMappedLongArray() throws Exception { .value(0) .value(1) .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(4, doc.rootDoc().getFields("foo").length); } @@ -530,7 +530,7 @@ public void testDynamicObjectWithTemplate() throws Exception { .startObject().startObject("foo") .field("bar", "baz") .endObject().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(2, doc.rootDoc().getFields("foo.bar").length); } @@ -544,7 +544,7 @@ public void testDynamicFalseObject() throws Exception { .startObject().startObject("foo") .field("bar", "baz") .endObject().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(0, doc.rootDoc().getFields("foo.bar").length); } @@ -559,7 +559,7 @@ public void testDynamicStrictObject() throws Exception { .field("bar", "baz") .endObject().endObject().bytes(); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -573,7 +573,7 @@ public void testDynamicFalseValue() throws Exception { .startObject() .field("bar", "baz") .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(0, doc.rootDoc().getFields("bar").length); } @@ -588,7 +588,7 @@ public void testDynamicStrictValue() throws Exception { .field("bar", "baz") .endObject().bytes(); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); } @@ -602,7 +602,7 @@ public void testDynamicFalseNull() throws Exception { .startObject() .field("bar", (String) null) .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(0, doc.rootDoc().getFields("bar").length); } @@ -617,7 +617,7 @@ public void testDynamicStrictNull() throws Exception { .field("bar", (String) null) .endObject().bytes(); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); } @@ -631,7 +631,7 @@ public void testMappedNullValue() throws Exception { BytesReference bytes = XContentFactory.jsonBuilder() .startObject().field("foo", (Long) null) .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(0, doc.rootDoc().getFields("foo").length); } @@ -646,7 +646,7 @@ public void testDynamicDottedFieldNameLongArray() throws Exception { .value(0) .value(1) .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -673,7 +673,7 @@ public void testDynamicDottedFieldNameLongArrayWithParentTemplate() throws Excep .value(0) .value(1) .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -699,7 +699,7 @@ public void testDynamicDottedFieldNameLongArrayWithExistingParent() throws Excep .value(0) .value(1) .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -726,7 +726,7 @@ public void testDynamicDottedFieldNameLongArrayWithExistingParentWrongType() thr .value(1) .endArray().endObject().bytes(); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("Could not dynamically add mapping for field [foo.bar.baz]. " + "Existing mapping for [foo] must be of type object but found [long].", exception.getMessage()); } @@ -742,7 +742,7 @@ public void testDynamicFalseDottedFieldNameLongArray() throws Exception { .value(0) .value(1) .endArray().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length); } @@ -758,7 +758,7 @@ public void testDynamicStrictDottedFieldNameLongArray() throws Exception { .value(1) .endArray().endObject().bytes(); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -771,7 +771,7 @@ public void testDynamicDottedFieldNameLong() throws Exception { BytesReference bytes = XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -796,7 +796,7 @@ public void testDynamicDottedFieldNameLongWithParentTemplate() throws Exception BytesReference bytes = XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -820,7 +820,7 @@ public void testDynamicDottedFieldNameLongWithExistingParent() throws Exception BytesReference bytes = XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -845,7 +845,7 @@ public void testDynamicDottedFieldNameLongWithExistingParentWrongType() throws E .startObject().field("foo.bar.baz", 0) .endObject().bytes(); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("Could not dynamically add mapping for field [foo.bar.baz]. " + "Existing mapping for [foo] must be of type object but found [long].", exception.getMessage()); } @@ -859,7 +859,7 @@ public void testDynamicFalseDottedFieldNameLong() throws Exception { BytesReference bytes = XContentFactory.jsonBuilder() .startObject().field("foo.bar.baz", 0) .endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length); } @@ -873,7 +873,7 @@ public void testDynamicStrictDottedFieldNameLong() throws Exception { .startObject().field("foo.bar.baz", 0) .endObject().bytes(); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -887,7 +887,7 @@ public void testDynamicDottedFieldNameObject() throws Exception { .startObject().startObject("foo.bar.baz") .field("a", 0) .endObject().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -916,7 +916,7 @@ public void testDynamicDottedFieldNameObjectWithParentTemplate() throws Exceptio .startObject().startObject("foo.bar.baz") .field("a", 0) .endObject().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -940,7 +940,7 @@ public void testDynamicDottedFieldNameObjectWithExistingParent() throws Exceptio BytesReference bytes = XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz").field("a", 0).endObject().endObject() .bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length); Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo"); assertNotNull(fooMapper); @@ -967,7 +967,7 @@ public void testDynamicDottedFieldNameObjectWithExistingParentWrongType() throws BytesReference bytes = XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz").field("a", 0).endObject().endObject() .bytes(); MapperParsingException exception = expectThrows(MapperParsingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("Could not dynamically add mapping for field [foo.bar.baz]. " + "Existing mapping for [foo] must be of type object but found [long].", exception.getMessage()); @@ -983,7 +983,7 @@ public void testDynamicFalseDottedFieldNameObject() throws Exception { .startObject().startObject("foo.bar.baz") .field("a", 0) .endObject().endObject().bytes(); - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); assertEquals(0, doc.rootDoc().getFields("foo.bar.baz.a").length); } @@ -998,7 +998,7 @@ public void testDynamicStrictDottedFieldNameObject() throws Exception { .field("a", 0) .endObject().endObject().bytes(); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, - () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + () -> mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } @@ -1009,11 +1009,11 @@ public void testDocumentContainsMetadataField() throws Exception { BytesReference bytes = XContentFactory.jsonBuilder().startObject().field("_ttl", 0).endObject().bytes(); MapperParsingException e = expectThrows(MapperParsingException.class, () -> - mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON))); + mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0))); assertTrue(e.getMessage(), e.getMessage().contains("cannot be added inside a document")); BytesReference bytes2 = XContentFactory.jsonBuilder().startObject().field("foo._ttl", 0).endObject().bytes(); - mapper.parse(SourceToParse.source("test", "type", "1", bytes2, XContentType.JSON)); // parses without error + mapper.parse(SourceToParse.source("test", "type", "1", bytes2, XContentType.JSON, 0)); // parses without error } public void testSimpleMapper() throws Exception { @@ -1024,10 +1024,10 @@ public void testSimpleMapper() throws Exception { indexService.mapperService()).build(indexService.mapperService()); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay")); - doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); } public void testParseToJsonAndParse() throws Exception { @@ -1038,7 +1038,7 @@ public void testParseToJsonAndParse() throws Exception { // reparse it DocumentMapper builtDocMapper = parser.parse("person", new CompressedXContent(builtMapping)); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json")); - Document doc = builtDocMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = builtDocMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); assertThat(doc.getBinaryValue(docMapper.idFieldMapper().fieldType().name()), equalTo(Uid.encodeId("1"))); assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay")); } @@ -1050,7 +1050,7 @@ public void testSimpleParser() throws Exception { assertThat((String) docMapper.meta().get("param1"), equalTo("value1")); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); assertThat(doc.getBinaryValue(docMapper.idFieldMapper().fieldType().name()), equalTo(Uid.encodeId("1"))); assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay")); } @@ -1059,7 +1059,7 @@ public void testSimpleParserNoTypeNoId() throws Exception { String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json"); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping)); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1-notype-noid.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); assertThat(doc.getBinaryValue(docMapper.idFieldMapper().fieldType().name()), equalTo(Uid.encodeId("1"))); assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay")); } @@ -1085,7 +1085,7 @@ public void testNoDocumentSent() throws Exception { BytesReference json = new BytesArray("".getBytes(StandardCharsets.UTF_8)); try { - docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); fail("this point is never reached"); } catch (MapperParsingException e) { assertThat(e.getMessage(), equalTo("failed to parse, document is empty")); @@ -1104,7 +1104,7 @@ public void testNoLevel() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("test1"), equalTo("value1")); assertThat(doc.rootDoc().get("test2"), equalTo("value2")); @@ -1123,7 +1123,7 @@ public void testTypeLevel() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject().endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("type.test1"), equalTo("value1")); assertThat(doc.rootDoc().get("type.test2"), equalTo("value2")); @@ -1143,7 +1143,7 @@ public void testNoLevelWithFieldTypeAsValue() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("type"), equalTo("value_type")); assertThat(doc.rootDoc().get("test1"), equalTo("value1")); @@ -1164,7 +1164,7 @@ public void testTypeLevelWithFieldTypeAsValue() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject().endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("type.type"), equalTo("value_type")); assertThat(doc.rootDoc().get("type.test1"), equalTo("value1")); @@ -1185,7 +1185,7 @@ public void testNoLevelWithFieldTypeAsObject() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); // in this case, we analyze the type object as the actual document, and ignore the other same level fields assertThat(doc.rootDoc().get("type.type_field"), equalTo("type_value")); @@ -1206,7 +1206,7 @@ public void testTypeLevelWithFieldTypeAsObject() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject().endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("type.type.type_field"), equalTo("type_value")); assertThat(doc.rootDoc().get("type.test1"), equalTo("value1")); @@ -1227,7 +1227,7 @@ public void testNoLevelWithFieldTypeAsValueNotFirst() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject().endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("type.type"), equalTo("value_type")); assertThat(doc.rootDoc().get("type.test1"), equalTo("value1")); @@ -1248,7 +1248,7 @@ public void testTypeLevelWithFieldTypeAsValueNotFirst() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject().endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("type.type"), equalTo("value_type")); assertThat(doc.rootDoc().get("type.test1"), equalTo("value1")); @@ -1269,7 +1269,7 @@ public void testNoLevelWithFieldTypeAsObjectNotFirst() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); // when the type is not the first one, we don't confuse it... assertThat(doc.rootDoc().get("type.type_field"), equalTo("type_value")); @@ -1291,7 +1291,7 @@ public void testTypeLevelWithFieldTypeAsObjectNotFirst() throws Exception { .startObject("inner").field("inner_field", "inner_value").endObject() .endObject().endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("type.type.type_field"), equalTo("type_value")); assertThat(doc.rootDoc().get("type.test1"), equalTo("value1")); @@ -1314,7 +1314,7 @@ public void testDynamicDateDetectionDisabledOnNumbers() throws IOException { // Even though we matched the dynamic format, we do not match on numbers, // which are too likely to be false positives - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); Mapping update = doc.dynamicMappingsUpdate(); assertNotNull(update); Mapper dateMapper = update.root().getMapper("foo"); @@ -1336,7 +1336,7 @@ public void testDynamicDateDetectionEnabledWithNoSpecialCharacters() throws IOEx .endObject().bytes(); // We should have generated a date field - ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON)); + ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", bytes, XContentType.JSON, 0)); Mapping update = doc.dynamicMappingsUpdate(); assertNotNull(update); Mapper dateMapper = update.root().getMapper("foo"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java index 3f2dc2861089c..d170092b3213b 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java @@ -57,7 +57,7 @@ public void testDoubleIndexingSameDoc() throws Exception { .startArray("field5").value(1).value(2).value(3).endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertNotNull(doc.dynamicMappingsUpdate()); client().admin().indices().preparePutMapping("test").setType("type") .setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java index 06c31f4dd1849..6aaeae17337c1 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java @@ -74,7 +74,7 @@ public void testDynamicTrue() throws IOException { .field("field2", "value2") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("field1"), equalTo("value1")); assertThat(doc.rootDoc().get("field2"), equalTo("value2")); @@ -96,7 +96,7 @@ public void testDynamicFalse() throws IOException { .field("field2", "value2") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("field1"), equalTo("value1")); assertThat(doc.rootDoc().get("field2"), nullValue()); @@ -119,7 +119,7 @@ public void testDynamicStrict() throws IOException { .field("field2", "value2") .endObject() .bytes(), - XContentType.JSON))); + XContentType.JSON, 0))); assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed")); e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder() @@ -128,7 +128,7 @@ public void testDynamicStrict() throws IOException { .field("field2", (String) null) .endObject() .bytes(), - XContentType.JSON))); + XContentType.JSON, 0))); assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed")); } @@ -151,7 +151,7 @@ public void testDynamicFalseWithInnerObjectButDynamicSetOnRoot() throws IOExcept .endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("obj1.field1"), equalTo("value1")); assertThat(doc.rootDoc().get("obj1.field2"), nullValue()); @@ -177,7 +177,7 @@ public void testDynamicStrictWithInnerObjectButDynamicSetOnRoot() throws IOExcep .endObject() .endObject() .bytes(), - XContentType.JSON))); + XContentType.JSON, 0))); assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [obj1] is not allowed")); } @@ -212,7 +212,7 @@ private String serialize(ToXContent mapper) throws Exception { private Mapper parse(DocumentMapper mapper, DocumentMapperParser parser, XContentBuilder builder) throws Exception { Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); - SourceToParse source = SourceToParse.source("test", mapper.type(), "some_id", builder.bytes(), builder.contentType()); + SourceToParse source = SourceToParse.source("test", mapper.type(), "some_id", builder.bytes(), builder.contentType(), 0); try (XContentParser xContentParser = createParser(JsonXContent.jsonXContent, source.source())) { ParseContext.InternalParseContext ctx = new ParseContext.InternalParseContext(settings, parser, mapper, source, xContentParser); assertEquals(XContentParser.Token.START_OBJECT, ctx.parser().nextToken()); @@ -557,7 +557,7 @@ public void testMixTemplateMultiFieldAndMappingReuse() throws Exception { XContentBuilder json = XContentFactory.jsonBuilder().startObject() .field("field", "foo") .endObject(); - SourceToParse source = SourceToParse.source("test", "doc", "1", json.bytes(), json.contentType()); + SourceToParse source = SourceToParse.source("test", "doc", "1", json.bytes(), json.contentType(), 0); DocumentMapper mapper = indexService.mapperService().documentMapper("doc"); assertNull(mapper.mappers().getMapper("field.raw")); ParsedDocument parsed = mapper.parse(source); @@ -605,7 +605,7 @@ public void testMixTemplateMultiFieldMultiTypeAndMappingReuse() throws Exception XContentBuilder json = XContentFactory.jsonBuilder().startObject() .field("field", "foo") .endObject(); - SourceToParse source = SourceToParse.source("test", "type1", "1", json.bytes(), json.contentType()); + SourceToParse source = SourceToParse.source("test", "type1", "1", json.bytes(), json.contentType(), 0); DocumentMapper mapper = indexService.mapperService().documentMapper("type1"); assertNull(mapper.mappers().getMapper("field.raw")); ParsedDocument parsed = mapper.parse(source); @@ -640,7 +640,7 @@ private void doTestDefaultFloatingPointMappings(DocumentMapper mapper, XContentB .field("quux", "3.2") // float detected through numeric detection .endObject().bytes(); ParsedDocument parsedDocument = mapper.parse(SourceToParse.source("index", "type", "id", source, - XContentType.JSON)); + XContentType.JSON, 0)); Mapping update = parsedDocument.dynamicMappingsUpdate(); assertNotNull(update); assertThat(((FieldMapper) update.root().getMapper("foo")).fieldType().typeName(), equalTo("float")); @@ -664,7 +664,7 @@ public void testNumericDetectionEnabled() throws Exception { .field("s_double", "100.0") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertNotNull(doc.dynamicMappingsUpdate()); client().admin().indices().preparePutMapping("test").setType("type") .setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); @@ -691,7 +691,7 @@ public void testNumericDetectionDefault() throws Exception { .field("s_double", "100.0") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertNotNull(doc.dynamicMappingsUpdate()); assertAcked(client().admin().indices().preparePutMapping("test").setType("type") .setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get()); @@ -741,7 +741,7 @@ public void testDateDetectionInheritsFormat() throws Exception { .field("date3", "2016-11-20") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertNotNull(doc.dynamicMappingsUpdate()); assertAcked(client().admin().indices().preparePutMapping("test").setType("type") .setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get()); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java index 70cc2c08441eb..cc37cf702ff4d 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java @@ -52,7 +52,7 @@ public void testMatchTypeOnly() throws Exception { builder = JsonXContent.contentBuilder(); builder.startObject().field("s", "hello").field("l", 1).endObject(); ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", builder.bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); @@ -75,7 +75,7 @@ public void testSimple() throws Exception { DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json"); ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json), - XContentType.JSON)); + XContentType.JSON, 0)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("person"); @@ -134,7 +134,7 @@ public void testSimpleWithXContentTraverse() throws Exception { DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json"); ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json), - XContentType.JSON)); + XContentType.JSON, 0)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("person"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ExternalFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ExternalFieldMapperTests.java index 1651091240f63..8469ec9a37fcf 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ExternalFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/ExternalFieldMapperTests.java @@ -83,7 +83,7 @@ public void testExternalValues() throws Exception { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("field.bool"), notNullValue()); assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T")); @@ -145,7 +145,7 @@ public void testExternalValuesWithMultifield() throws Exception { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("field.bool"), notNullValue()); assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T")); @@ -215,7 +215,7 @@ public void testExternalValuesWithMultifieldTwoLevels() throws Exception { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("field.bool"), notNullValue()); assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java index af5460241278a..22baece7e3845 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/FieldNamesFieldMapperTests.java @@ -97,9 +97,9 @@ public void testInjectIntoDocDuringParsing() throws Exception { .endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); - assertFieldNames(set("a", "a.keyword", "b", "b.c", "_id", "_version", "_seq_no", "_primary_term", "_source"), doc); + assertFieldNames(set("a", "a.keyword", "b", "b.c", "_id", "_version", "_seq_no", "_primary_term", "_source", "_shard"), doc); } public void testExplicitEnabled() throws Exception { @@ -115,9 +115,9 @@ public void testExplicitEnabled() throws Exception { .field("field", "value") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); - assertFieldNames(set("field", "field.keyword", "_id", "_version", "_seq_no", "_primary_term", "_source"), doc); + assertFieldNames(set("field", "field.keyword", "_id", "_version", "_seq_no", "_primary_term", "_source", "_shard"), doc); } public void testDisabled() throws Exception { @@ -133,7 +133,7 @@ public void testDisabled() throws Exception { .field("field", "value") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertNull(doc.rootDoc().get("_field_names")); } @@ -249,7 +249,7 @@ public void testSeesFieldsFromPlugins() throws IOException { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); ParsedDocument parsedDocument = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(FieldNamesFieldMapper.NAME); boolean found = false; for (IndexableField f : fields) { diff --git a/core/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java b/core/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java index 57a6173bc657d..dee818555a192 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java @@ -41,7 +41,7 @@ public void testSimple() throws Exception { DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/genericstore/test-data.json"); ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json), - XContentType.JSON)); + XContentType.JSON, 0)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("person"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java index f8775073e2169..23f45a1813676 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java @@ -60,7 +60,7 @@ public void testGeoHashValue() throws Exception { .field("point", stringEncode(1.3, 1.2)) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("point"), notNullValue()); } @@ -76,7 +76,7 @@ public void testLatLonValuesStored() throws Exception { .startObject("point").field("lat", 1.2).field("lon", 1.3).endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("point"), notNullValue()); } @@ -95,7 +95,7 @@ public void testArrayLatLonValues() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); // doc values are enabled by default, but in this test we disable them; we should only have 2 points assertThat(doc.rootDoc().getFields("point"), notNullValue()); @@ -114,7 +114,7 @@ public void testLatLonInOneValue() throws Exception { .field("point", "1.2,1.3") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("point"), notNullValue()); } @@ -131,7 +131,7 @@ public void testLatLonInOneValueStored() throws Exception { .field("point", "1.2,1.3") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("point"), notNullValue()); } @@ -150,7 +150,7 @@ public void testLatLonInOneValueArray() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); // doc values are enabled by default, but in this test we disable them; we should only have 2 points assertThat(doc.rootDoc().getFields("point"), notNullValue()); @@ -168,7 +168,7 @@ public void testLonLatArray() throws Exception { .startArray("point").value(1.3).value(1.2).endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("point"), notNullValue()); } @@ -185,7 +185,7 @@ public void testLonLatArrayDynamic() throws Exception { .startArray("point").value(1.3).value(1.2).endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("point"), notNullValue()); } @@ -201,7 +201,7 @@ public void testLonLatArrayStored() throws Exception { .startArray("point").value(1.3).value(1.2).endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("point"), notNullValue()); assertThat(doc.rootDoc().getFields("point").length, equalTo(3)); @@ -222,7 +222,7 @@ public void testLonLatArrayArrayStored() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getFields("point"), notNullValue()); assertThat(doc.rootDoc().getFields("point").length, CoreMatchers.equalTo(4)); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java index ec07c4d92be3e..c736bc9a352d6 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java @@ -50,7 +50,7 @@ public void testIncludeInObjectNotAllowed() throws Exception { try { docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder() - .startObject().field("_id", "1").endObject().bytes(), XContentType.JSON)); + .startObject().field("_id", "1").endObject().bytes(), XContentType.JSON, 0)); fail("Expected failure to parse metadata field"); } catch (MapperParsingException e) { assertTrue(e.getMessage(), e.getMessage().contains("Field [_id] is a metadata field and cannot be added inside a document")); @@ -63,7 +63,7 @@ public void testDefaultsMultipleTypes() throws IOException { .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON, 0)); assertEquals(Collections.emptyList(), Arrays.asList(document.rootDoc().getFields(IdFieldMapper.NAME))); } @@ -71,7 +71,7 @@ public void testDefaultsSingleType() throws IOException { Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON, 0)); IndexableField[] fields = document.rootDoc().getFields(IdFieldMapper.NAME); assertEquals(1, fields.length); assertEquals(IndexOptions.DOCS, fields[0].fieldType().indexOptions()); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java index 910fa0f74faba..dd2cc98530c8c 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/IndexFieldMapperTests.java @@ -56,7 +56,7 @@ public void testDefaultDisabledIndexMapper() throws Exception { .field("field", "value") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("_index"), nullValue()); assertThat(doc.rootDoc().get("field"), equalTo("value")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java index 88db0b1b274fd..abe71658f0984 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java @@ -71,7 +71,7 @@ public void testDefaults() throws Exception { .field("field", "::1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -100,7 +100,7 @@ public void testNotIndexed() throws Exception { .field("field", "::1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -122,7 +122,7 @@ public void testNoDocValues() throws Exception { .field("field", "::1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -145,7 +145,7 @@ public void testStore() throws Exception { .field("field", "::1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(3, fields.length); @@ -173,7 +173,7 @@ public void testIgnoreMalformed() throws Exception { .field("field", ":1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); MapperParsingException e = expectThrows(MapperParsingException.class, runnable); assertThat(e.getCause().getMessage(), containsString("':1' is not an IP string literal")); @@ -188,7 +188,7 @@ public void testIgnoreMalformed() throws Exception { .field("field", ":1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); @@ -212,7 +212,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); mapping = XContentFactory.jsonBuilder().startObject() @@ -233,7 +233,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); IndexableField pointField = fields[0]; diff --git a/core/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java index c17df90b5a21d..535d59247ae63 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/JavaMultiFieldMergeTests.java @@ -46,7 +46,7 @@ public void testMergeMultiField() throws Exception { assertThat(docMapper.mappers().getMapper("name.indexed"), nullValue()); BytesReference json = XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject().bytes(); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); @@ -63,7 +63,7 @@ public void testMergeMultiField() throws Exception { assertThat(docMapper.mappers().getMapper("name.not_indexed2"), nullValue()); assertThat(docMapper.mappers().getMapper("name.not_indexed3"), nullValue()); - doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); @@ -102,7 +102,7 @@ public void testUpgradeFromMultiFieldTypeToMultiFields() throws Exception { assertThat(docMapper.mappers().getMapper("name.indexed"), nullValue()); BytesReference json = XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject().bytes(); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); @@ -120,7 +120,7 @@ public void testUpgradeFromMultiFieldTypeToMultiFields() throws Exception { assertThat(docMapper.mappers().getMapper("name.not_indexed2"), nullValue()); assertThat(docMapper.mappers().getMapper("name.not_indexed3"), nullValue()); - doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); f = doc.getField("name"); assertThat(f, notNullValue()); f = doc.getField("name.indexed"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java index 3ecef3aa0f514..808242a07bb99 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java @@ -90,7 +90,7 @@ public void testDefaults() throws Exception { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -127,7 +127,7 @@ public void testIgnoreAbove() throws IOException { .field("field", "elk") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -137,7 +137,7 @@ public void testIgnoreAbove() throws IOException { .field("field", "elasticsearch") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); @@ -156,7 +156,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); mapping = XContentFactory.jsonBuilder().startObject().startObject("type") @@ -171,7 +171,7 @@ public void testNullValue() throws IOException { .startObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); @@ -181,7 +181,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -202,7 +202,7 @@ public void testEnableStore() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -223,7 +223,7 @@ public void testDisableIndex() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -245,7 +245,7 @@ public void testDisableDocValues() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -267,7 +267,7 @@ public void testIndexOptions() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -308,7 +308,7 @@ public void testEnableNorms() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -330,7 +330,7 @@ public void testNormalizer() throws IOException { .field("field", "AbC") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java b/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java index eb1148e9f4598..2179fd34e5bf7 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java @@ -54,7 +54,7 @@ public void testMultiFieldMultiFields() throws Exception { private void testMultiField(String mapping) throws Exception { DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping)); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f.name(), equalTo("name")); @@ -137,7 +137,7 @@ public void testBuildThenParse() throws Exception { BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json")); - Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON)).rootDoc(); + Document doc = docMapper.parse(SourceToParse.source("test", "person", "1", json, XContentType.JSON, 0)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f.name(), equalTo("name")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java index 157033d414884..05b64f040ba26 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java @@ -60,7 +60,7 @@ public void testEmptyNested() throws Exception { .nullField("nested1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.docs().size(), equalTo(1)); @@ -70,7 +70,7 @@ public void testEmptyNested() throws Exception { .startArray("nested").endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.docs().size(), equalTo(1)); } @@ -92,7 +92,7 @@ public void testSingleNested() throws Exception { .startObject("nested1").field("field1", "1").field("field2", "2").endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.docs().size(), equalTo(2)); assertThat(doc.docs().get(0).get(TypeFieldMapper.NAME), equalTo(nested1Mapper.nestedTypePathAsString())); @@ -111,7 +111,7 @@ public void testSingleNested() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.docs().size(), equalTo(3)); assertThat(doc.docs().get(0).get(TypeFieldMapper.NAME), equalTo(nested1Mapper.nestedTypePathAsString())); @@ -152,7 +152,7 @@ public void testMultiNested() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.docs().size(), equalTo(7)); assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6")); @@ -204,7 +204,7 @@ public void testMultiObjectAndNested1() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.docs().size(), equalTo(7)); assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6")); @@ -256,7 +256,7 @@ public void testMultiObjectAndNested2() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.docs().size(), equalTo(7)); assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6")); @@ -308,7 +308,7 @@ public void testMultiRootAndNested1() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.docs().size(), equalTo(7)); assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6")); @@ -355,7 +355,7 @@ public void testNestedArrayStrict() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.docs().size(), equalTo(3)); assertThat(doc.docs().get(0).get("nested1.field1"), equalTo("4")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java index 8a46f24998db9..6bc8e7033aa53 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/NullValueObjectMappingTests.java @@ -44,7 +44,7 @@ public void testNullValueObject() throws IOException { .field("value1", "test1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("value1"), equalTo("test1")); @@ -54,7 +54,7 @@ public void testNullValueObject() throws IOException { .field("value1", "test1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("value1"), equalTo("test1")); @@ -64,7 +64,7 @@ public void testNullValueObject() throws IOException { .field("value1", "test1") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().get("obj1.field"), equalTo("value")); assertThat(doc.rootDoc().get("value1"), equalTo("test1")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java index 871d62d8bd6be..72a6a454db598 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java @@ -53,7 +53,7 @@ public void doTestDefaults(String type) throws Exception { .field("field", 123) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -81,7 +81,7 @@ public void doTestNotIndexed(String type) throws Exception { .field("field", 123) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -104,7 +104,7 @@ public void doTestNoDocValues(String type) throws Exception { .field("field", 123) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -128,7 +128,7 @@ public void doTestStore(String type) throws Exception { .field("field", 123) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(3, fields.length); @@ -157,7 +157,7 @@ public void doTestCoerce(String type) throws IOException { .field("field", "123") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -180,7 +180,7 @@ public void doTestCoerce(String type) throws IOException { .field("field", "123") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); MapperParsingException e = expectThrows(MapperParsingException.class, runnable); assertThat(e.getCause().getMessage(), containsString("passed as String")); } @@ -205,7 +205,7 @@ private void doTestIgnoreMalformed(String type) throws IOException { .field("field", "a") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); MapperParsingException e = expectThrows(MapperParsingException.class, runnable); assertThat(e.getCause().getMessage(), containsString("For input string: \"a\"")); @@ -220,7 +220,7 @@ private void doTestIgnoreMalformed(String type) throws IOException { .field("field", "a") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); @@ -262,7 +262,7 @@ protected void doTestNullValue(String type) throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); Object missing; @@ -289,7 +289,7 @@ protected void doTestNullValue(String type) throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); IndexableField pointField = fields[0]; diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java index 0e1bead111452..78dfe339cfd91 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java @@ -62,7 +62,7 @@ public void testDifferentInnerObjectTokenFailure() throws Exception { " },\n" + " \"value\":\"value\"\n" + " }"), - XContentType.JSON)); + XContentType.JSON, 0)); }); assertTrue(e.getMessage(), e.getMessage().contains("different type")); } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java index 935562a2bc4a3..5d9dfe99a8c2e 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java @@ -63,7 +63,7 @@ public void testParentSetInDocNotAllowed() throws Exception { try { docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder() - .startObject().field("_parent", "1122").endObject().bytes(), XContentType.JSON)); + .startObject().field("_parent", "1122").endObject().bytes(), XContentType.JSON, 0)); fail("Expected failure to parse metadata field"); } catch (MapperParsingException e) { assertTrue(e.getMessage(), e.getMessage().contains("Field [_parent] is a metadata field and cannot be added inside a document")); @@ -83,13 +83,13 @@ public void testJoinFieldSet() throws Exception { // Indexing parent doc: DocumentMapper parentDocMapper = indexService.mapperService().documentMapper("parent_type"); ParsedDocument doc = - parentDocMapper.parse(SourceToParse.source("test", "parent_type", "1122", new BytesArray("{}"), XContentType.JSON)); + parentDocMapper.parse(SourceToParse.source("test", "parent_type", "1122", new BytesArray("{}"), XContentType.JSON, 0)); assertEquals(1, getNumberOfFieldWithParentPrefix(doc.rootDoc())); assertEquals("1122", doc.rootDoc().getBinaryValue("_parent#parent_type").utf8ToString()); // Indexing child doc: DocumentMapper childDocMapper = indexService.mapperService().documentMapper("child_type"); - doc = childDocMapper.parse(SourceToParse.source("test", "child_type", "1", new BytesArray("{}"), XContentType.JSON).parent("1122")); + doc = childDocMapper.parse(SourceToParse.source("test", "child_type", "1", new BytesArray("{}"), XContentType.JSON, 0).parent("1122")); assertEquals(1, getNumberOfFieldWithParentPrefix(doc.rootDoc())); assertEquals("1122", doc.rootDoc().getBinaryValue("_parent#parent_type").utf8ToString()); @@ -103,7 +103,7 @@ public void testJoinFieldNotSet() throws Exception { .startObject() .field("x_field", "x_value") .endObject() - .bytes(), XContentType.JSON)); + .bytes(), XContentType.JSON, 0)); assertEquals(0, getNumberOfFieldWithParentPrefix(doc.rootDoc())); } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java b/core/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java index 3ad53513c5185..55bdd29bf0890 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java @@ -41,7 +41,7 @@ public void testSimple() throws Exception { DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-data.json"); ParsedDocument parsedDoc = docMapper.parse(SourceToParse.source("test", "person", "1", new BytesArray(json), - XContentType.JSON)); + XContentType.JSON, 0)); client().admin().indices().preparePutMapping("test").setType("person") .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("person"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java index 9aa62d037031a..e61d1c67ad3c0 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java @@ -115,7 +115,7 @@ public void doTestDefaults(String type) throws Exception { .field(getToField(), getTo(type)) .endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -146,7 +146,7 @@ protected void doTestNotIndexed(String type) throws Exception { .field(getToField(), getTo(type)) .endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -170,7 +170,7 @@ protected void doTestNoDocValues(String type) throws Exception { .field(getToField(), getTo(type)) .endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -196,7 +196,7 @@ protected void doTestStore(String type) throws Exception { .field(getToField(), getTo(type)) .endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(3, fields.length); @@ -235,7 +235,7 @@ public void doTestCoerce(String type) throws IOException { .field(getToField(), getTo(type)) .endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -258,7 +258,7 @@ public void doTestCoerce(String type) throws IOException { .field(getToField(), "10") .endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); MapperParsingException e = expectThrows(MapperParsingException.class, runnable); assertThat(e.getCause().getMessage(), anyOf(containsString("passed as String"), containsString("failed to parse date"), containsString("is not an IP string literal"))); @@ -284,7 +284,7 @@ protected void doTestNullValue(String type) throws IOException { .nullField(getToField()) .endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertEquals(3, doc.rootDoc().getFields("field").length); IndexableField[] fields = doc.rootDoc().getFields("field"); IndexableField storedField = fields[2]; @@ -299,7 +299,7 @@ protected void doTestNullValue(String type) throws IOException { .nullField(getToField()) .endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); fields = doc.rootDoc().getFields("field"); assertEquals(3, fields.length); @@ -343,7 +343,7 @@ public void doTestNoBounds(String type) throws IOException { .startObject("field") .endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(3, fields.length); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java index fb98f42f105eb..4dc77b9bc6199 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/RoutingFieldMapperTests.java @@ -42,7 +42,7 @@ public void testRoutingMapper() throws Exception { .field("field", "value") .endObject() .bytes(), - XContentType.JSON).routing("routing_value")); + XContentType.JSON, 0).routing("routing_value")); assertThat(doc.rootDoc().get("_routing"), equalTo("routing_value")); assertThat(doc.rootDoc().get("field"), equalTo("value")); @@ -54,7 +54,7 @@ public void testIncludeInObjectNotAllowed() throws Exception { try { docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder() - .startObject().field("_routing", "foo").endObject().bytes(),XContentType.JSON)); + .startObject().field("_routing", "foo").endObject().bytes(),XContentType.JSON, 0)); fail("Expected failure to parse metadata field"); } catch (MapperParsingException e) { assertTrue(e.getMessage(), e.getMessage().contains("Field [_routing] is a metadata field and cannot be added inside a document")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java index c2d0317ea070f..867e008a8e283 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java @@ -66,7 +66,7 @@ public void testDefaults() throws Exception { .field("field", 123) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -116,7 +116,7 @@ public void testNotIndexed() throws Exception { .field("field", 123) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -140,7 +140,7 @@ public void testNoDocValues() throws Exception { .field("field", 123) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -164,7 +164,7 @@ public void testStore() throws Exception { .field("field", 123) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(3, fields.length); @@ -193,7 +193,7 @@ public void testCoerce() throws Exception { .field("field", "123") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -217,7 +217,7 @@ public void testCoerce() throws Exception { .field("field", "123") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); MapperParsingException e = expectThrows(MapperParsingException.class, runnable); assertThat(e.getCause().getMessage(), containsString("passed as String")); } @@ -237,7 +237,7 @@ public void testIgnoreMalformed() throws Exception { .field("field", "a") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); MapperParsingException e = expectThrows(MapperParsingException.class, runnable); assertThat(e.getCause().getMessage(), containsString("For input string: \"a\"")); @@ -253,7 +253,7 @@ public void testIgnoreMalformed() throws Exception { .field("field", "a") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); @@ -278,7 +278,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); mapping = XContentFactory.jsonBuilder().startObject() @@ -300,7 +300,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); IndexableField pointField = fields[0]; diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java index 86a17eb2ecfe1..e5090936f9bc8 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java @@ -152,7 +152,7 @@ public void testFieldData() throws IOException { // single-valued ft.setName("scaled_float1"); - IndexNumericFieldData fielddata = (IndexNumericFieldData) ft.fielddataBuilder().build(indexSettings, ft, null, null, null); + IndexNumericFieldData fielddata = (IndexNumericFieldData) ft.fielddataBuilder().build(indexSettings, ft, null, null, null, 0); assertEquals(fielddata.getNumericType(), IndexNumericFieldData.NumericType.DOUBLE); AtomicNumericFieldData leafFieldData = fielddata.load(reader.leaves().get(0)); SortedNumericDoubleValues values = leafFieldData.getDoubleValues(); @@ -162,7 +162,7 @@ public void testFieldData() throws IOException { // multi-valued ft.setName("scaled_float2"); - fielddata = (IndexNumericFieldData) ft.fielddataBuilder().build(indexSettings, ft, null, null, null); + fielddata = (IndexNumericFieldData) ft.fielddataBuilder().build(indexSettings, ft, null, null, null, 0); leafFieldData = fielddata.load(reader.leaves().get(0)); values = leafFieldData.getDoubleValues(); assertTrue(values.advanceExact(0)); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ShardIdFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ShardIdFieldMapperTests.java new file mode 100644 index 0000000000000..ec16e63308bbc --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/mapper/ShardIdFieldMapperTests.java @@ -0,0 +1,66 @@ +/* + * 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.index.mapper; + +import org.apache.lucene.index.DocValuesType; +import org.apache.lucene.index.IndexableField; +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.Version; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.compress.CompressedXContent; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.index.mapper.MapperService.MergeReason; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +public class ShardIdFieldMapperTests extends ESSingleNodeTestCase { + + @Override + protected Collection> getPlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + + public void testDefaults() throws IOException { + MapperService mapperService = createIndex("test", Settings.EMPTY).mapperService(); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); + ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON, 3)); + IndexableField[] fields = document.rootDoc().getFields(ShardIdFieldMapper.NAME); + assertEquals(1, fields.length); + assertEquals(DocValuesType.SORTED, fields[0].fieldType().docValuesType()); + assertEquals(new BytesRef("3"), fields[0].binaryValue()); + } + + public void testBwCompat() throws IOException { + Settings indexSettings = Settings.builder() + .put("index.version.created", Version.V_5_6_0) + .build(); + MapperService mapperService = createIndex("test", indexSettings).mapperService(); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); + ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON, 3)); + assertEquals(Collections.emptyList(), Arrays.asList(document.rootDoc().getFields(ShardIdFieldMapper.NAME))); + } +} diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ShardIdFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ShardIdFieldTypeTests.java new file mode 100644 index 0000000000000..9320dbe0c4fc8 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/mapper/ShardIdFieldTypeTests.java @@ -0,0 +1,79 @@ +/* + * 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.index.mapper; + +import org.apache.lucene.document.SortedDocValuesField; +import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.MatchNoDocsQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.UUIDs; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.query.QueryShardContext; +import org.mockito.Mockito; + +public class ShardIdFieldTypeTests extends FieldTypeTestCase { + + @Override + protected MappedFieldType createDefaultFieldType() { + return new ShardIdFieldMapper.ShardIdFieldType(); + } + + public void testTermQuery() { + QueryShardContext context = Mockito.mock(QueryShardContext.class); + Settings indexSettings = Settings.builder() + .put(IndexSettings.INDEX_MAPPING_SINGLE_TYPE_SETTING_KEY, true) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_6_0_0_beta1) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build(); + IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); + IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); + Mockito.when(context.getIndexSettings()).thenReturn(mockSettings); + Mockito.when(context.indexVersionCreated()).thenReturn(indexSettings.getAsVersion(IndexMetaData.SETTING_VERSION_CREATED, null)); + Mockito.when(context.getShardId()).thenReturn(3); + MappedFieldType ft = createDefaultFieldType(); + Query query = ft.termQuery(1, context); + assertEquals(SortedDocValuesField.newExactQuery("_shard", new BytesRef("1")), query); + } + + public void testTermQueryBwCompat() { + QueryShardContext context = Mockito.mock(QueryShardContext.class); + Settings indexSettings = Settings.builder() + .put(IndexSettings.INDEX_MAPPING_SINGLE_TYPE_SETTING_KEY, true) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build(); + IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); + IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); + Mockito.when(context.getIndexSettings()).thenReturn(mockSettings); + Mockito.when(context.indexVersionCreated()).thenReturn(indexSettings.getAsVersion(IndexMetaData.SETTING_VERSION_CREATED, null)); + Mockito.when(context.getShardId()).thenReturn(3); + MappedFieldType ft = createDefaultFieldType(); + Query query = ft.termQuery(1, context); + assertEquals(new MatchNoDocsQuery(), query); + query = ft.termQuery(3, context); + assertEquals(new MatchAllDocsQuery(), query); + } +} diff --git a/core/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java index 3b73b5dfd3770..8bd1d5389aac8 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java @@ -57,7 +57,7 @@ public void testNoFormat() throws Exception { ParsedDocument doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject() .field("field", "value") .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(XContentFactory.xContentType(doc.source()), equalTo(XContentType.JSON)); @@ -65,7 +65,7 @@ public void testNoFormat() throws Exception { doc = documentMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.smileBuilder().startObject() .field("field", "value") .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(XContentFactory.xContentType(doc.source()), equalTo(XContentType.SMILE)); } @@ -81,7 +81,7 @@ public void testIncludes() throws Exception { .startObject("path1").field("field1", "value1").endObject() .startObject("path2").field("field2", "value2").endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField sourceField = doc.rootDoc().getField("_source"); Map sourceAsMap; @@ -103,7 +103,7 @@ public void testExcludes() throws Exception { .startObject("path1").field("field1", "value1").endObject() .startObject("path2").field("field2", "value2").endObject() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField sourceField = doc.rootDoc().getField("_source"); Map sourceAsMap; @@ -285,7 +285,7 @@ public void testSourceObjectContainsExtraTokens() throws Exception { DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); try { - documentMapper.parse(SourceToParse.source("test", "type", "1", new BytesArray("{}}"), XContentType.JSON)); // extra end object (invalid JSON) + documentMapper.parse(SourceToParse.source("test", "type", "1", new BytesArray("{}}"), XContentType.JSON, 0)); // extra end object (invalid JSON) fail("Expected parse exception"); } catch (MapperParsingException e) { assertNotNull(e.getRootCause()); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java b/core/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java index 438ccd5fa8688..f395db2e427ab 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/StoredNumericValuesTests.java @@ -78,7 +78,7 @@ public void testBytesAndNumericRepresentation() throws Exception { .field("field10", true) .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); writer.addDocument(doc.rootDoc()); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java index 854164063e3b4..0750890f68314 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java @@ -85,7 +85,7 @@ public void testDefaults() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -117,7 +117,7 @@ public void testEnableStore() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -138,7 +138,7 @@ public void testDisableIndex() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); @@ -161,7 +161,7 @@ public void testDisableNorms() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -188,7 +188,7 @@ public void testIndexOptions() throws IOException { jsonDoc.field(option, "1234"); } ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "1", jsonDoc.endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); for (Map.Entry entry : supportedOptions.entrySet()) { String field = entry.getKey(); @@ -214,7 +214,7 @@ public void testDefaultPositionIncrementGap() throws IOException { .array("field", new String[] {"a", "b"}) .endObject() .bytes(), - XContentType.JSON); + XContentType.JSON, 0); ParsedDocument doc = mapper.parse(sourceToParse); IndexableField[] fields = doc.rootDoc().getFields("field"); @@ -256,7 +256,7 @@ public void testPositionIncrementGap() throws IOException { .array("field", new String[]{"a", "b"}) .endObject() .bytes(), - XContentType.JSON); + XContentType.JSON, 0); ParsedDocument doc = mapper.parse(sourceToParse); IndexableField[] fields = doc.rootDoc().getFields("field"); @@ -420,7 +420,7 @@ public void testTermVectors() throws IOException { .field("field6", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("field1").fieldType().storeTermVectors(), equalTo(false)); assertThat(doc.rootDoc().getField("field1").fieldType().storeTermVectorOffsets(), equalTo(false)); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java index 861586370aef8..843397ede2c25 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java @@ -190,7 +190,7 @@ private SourceToParse createDocument(String fieldValue) throws Exception { .field("test", fieldValue) .endObject().bytes(); - return SourceToParse.source("test", "person", "1", request, XContentType.JSON); + return SourceToParse.source("test", "person", "1", request, XContentType.JSON, 0); } private ParseContext.Document parseDocument(DocumentMapper mapper, SourceToParse request) { diff --git a/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java index cf7b4a233a1e0..0484c4898039f 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java @@ -67,7 +67,7 @@ public void testDocValues(boolean singleType) throws IOException { .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON, 0)); Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig()); @@ -77,7 +77,7 @@ public void testDocValues(boolean singleType) throws IOException { MappedFieldType ft = mapperService.fullName(TypeFieldMapper.NAME); IndexOrdinalsFieldData fd = (IndexOrdinalsFieldData) ft.fielddataBuilder().build(mapperService.getIndexSettings(), - ft, new IndexFieldDataCache.None(), new NoneCircuitBreakerService(), mapperService); + ft, new IndexFieldDataCache.None(), new NoneCircuitBreakerService(), mapperService, 0); AtomicOrdinalsFieldData afd = fd.load(r.leaves().get(0)); SortedSetDocValues values = afd.getOrdinalsValues(); assertTrue(values.advanceExact(0)); @@ -94,7 +94,7 @@ public void testDefaultsMultipleTypes() throws IOException { .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON, 0)); IndexableField[] fields = document.rootDoc().getFields(TypeFieldMapper.NAME); assertEquals(IndexOptions.DOCS, fields[0].fieldType().indexOptions()); assertEquals(DocValuesType.SORTED_SET, fields[1].fieldType().docValuesType()); @@ -104,7 +104,7 @@ public void testDefaultsSingleType() throws IOException { Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON, 0)); assertEquals(Collections.emptyList(), Arrays.asList(document.rootDoc().getFields(TypeFieldMapper.NAME))); } } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java index c5816de2e1920..3cdb577212fac 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java @@ -49,7 +49,7 @@ public void testDefaultsMultipleTypes() throws IOException { .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON, 0)); IndexableField[] fields = document.rootDoc().getFields(UidFieldMapper.NAME); assertEquals(1, fields.length); assertEquals(IndexOptions.DOCS, fields[0].fieldType().indexOptions()); @@ -61,7 +61,7 @@ public void testDefaultsSingleType() throws IOException { Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); - ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); + ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON, 0)); assertEquals(Collections.emptyList(), Arrays.asList(document.rootDoc().getFields(UidFieldMapper.NAME))); } } diff --git a/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java b/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java index 784682c3e9738..04c11141af7d7 100644 --- a/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java +++ b/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java @@ -180,7 +180,7 @@ public void testRecoveryToReplicaThatReceivedExtraDocument() throws Exception { VersionType.EXTERNAL, randomNonNegativeLong(), false, - SourceToParse.source("index", "type", "replica", new BytesArray("{}"), XContentType.JSON), + SourceToParse.source("index", "type", "replica", new BytesArray("{}"), XContentType.JSON, 0), mapping -> {}); shards.promoteReplicaToPrimary(promotedReplica); oldPrimary.close("demoted", randomBoolean()); @@ -194,7 +194,7 @@ public void testRecoveryToReplicaThatReceivedExtraDocument() throws Exception { promotedReplica.applyIndexOperationOnPrimary( Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source("index", "type", "primary", new BytesArray("{}"), XContentType.JSON), + SourceToParse.source("index", "type", "primary", new BytesArray("{}"), XContentType.JSON, 0), randomNonNegativeLong(), false, mapping -> { diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java index 0c07f4cf7703f..16e9f81076776 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java @@ -346,7 +346,7 @@ public void testMaybeFlush() throws Exception { .setSource("{}", XContentType.JSON).setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get(); assertFalse(shard.shouldFlush()); shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source("test", "test", "1", new BytesArray("{}"), XContentType.JSON), + SourceToParse.source("test", "test", "1", new BytesArray("{}"), XContentType.JSON, 0), IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, update -> {}); assertTrue(shard.shouldFlush()); final Translog translog = shard.getEngine().getTranslog(); @@ -396,7 +396,7 @@ public void testMaybeRollTranslogGeneration() throws Exception { for (int i = 0; i < numberOfDocuments; i++) { assertThat(translog.currentFileGeneration(), equalTo(generation + rolls)); final Engine.IndexResult result = shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, - SourceToParse.source("test", "test", "1", new BytesArray("{}"), XContentType.JSON), + SourceToParse.source("test", "test", "1", new BytesArray("{}"), XContentType.JSON, 0), IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, update -> {}); final Translog.Location location = result.getTranslogLocation(); shard.afterWriteOperation(); diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index 9749798b91172..2d69bbb41a32d 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -1433,7 +1433,7 @@ public void testRecoverFromStoreWithNoOps() throws IOException { final IndexShard otherShard = newStartedShard(false); updateMappings(otherShard, shard.indexSettings().getIndexMetaData()); SourceToParse sourceToParse = SourceToParse.source(shard.shardId().getIndexName(), "test", "1", - new BytesArray("{}"), XContentType.JSON); + new BytesArray("{}"), XContentType.JSON, 0); otherShard.applyIndexOperationOnReplica(1, 1, 1, VersionType.EXTERNAL, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse, update -> {}); @@ -1678,7 +1678,7 @@ public IndexSearcher wrap(IndexSearcher searcher) throws EngineException { // test global ordinals are evicted MappedFieldType foo = shard.mapperService().fullName("foo"); - IndexFieldData.Global ifd = shard.indexFieldDataService().getForField(foo); + IndexFieldData.Global ifd = shard.indexFieldDataService().getForField(foo, 0); FieldDataStats before = shard.fieldData().stats("foo"); assertThat(before.getMemorySizeInBytes(), equalTo(0L)); FieldDataStats after = null; @@ -2130,7 +2130,7 @@ private Result indexOnReplicaWithGaps( if (!rarely()) { final String id = Integer.toString(i); SourceToParse sourceToParse = SourceToParse.source(indexShard.shardId().getIndexName(), "test", id, - new BytesArray("{}"), XContentType.JSON); + new BytesArray("{}"), XContentType.JSON, 0); indexShard.applyIndexOperationOnReplica(i, indexShard.getPrimaryTerm(), 1, VersionType.EXTERNAL, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, sourceToParse, getMappingUpdater(indexShard, sourceToParse.type())); diff --git a/core/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java b/core/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java index f8c971c4405d5..8cacc95dec3a8 100644 --- a/core/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java +++ b/core/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java @@ -60,7 +60,7 @@ Path translogLocation() { for (int i = 0; i < docs; i++) { replica.applyIndexOperationOnReplica(seqNo++, replica.getPrimaryTerm(), 1, VersionType.EXTERNAL, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, - SourceToParse.source(index, "type", "doc_" + i, new BytesArray("{}"), XContentType.JSON), + SourceToParse.source(index, "type", "doc_" + i, new BytesArray("{}"), XContentType.JSON, 0), update -> {}); if (rarely()) { // insert a gap diff --git a/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java b/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java index 07513b7641d7e..373f218d4ff86 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java @@ -84,7 +84,7 @@ public void testIndexingWithNoContexts() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 7); } @@ -118,7 +118,7 @@ public void testIndexingWithSimpleContexts() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } @@ -152,7 +152,7 @@ public void testIndexingWithSimpleNumberContexts() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } @@ -186,7 +186,7 @@ public void testIndexingWithSimpleBooleanContexts() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } @@ -219,7 +219,7 @@ public void testIndexingWithSimpleNULLContexts() throws Exception { .endObject(); Exception e = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", builder.bytes(), XContentType.JSON))); + () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", builder.bytes(), XContentType.JSON, 0))); assertEquals("contexts must be a string, number or boolean or a list of string, number or boolean, but was [VALUE_NULL]", e.getCause().getMessage()); } @@ -250,7 +250,7 @@ public void testIndexingWithContextList() throws Exception { .endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } @@ -282,7 +282,7 @@ public void testIndexingWithMixedTypeContextList() throws Exception { .endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } @@ -313,7 +313,7 @@ public void testIndexingWithMixedTypeContextListHavingNULL() throws Exception { .endObject(); Exception e = expectThrows(MapperParsingException.class, - () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", builder.bytes(), XContentType.JSON))); + () -> defaultMapper.parse(SourceToParse.source("test", "type1", "1", builder.bytes(), XContentType.JSON, 0))); assertEquals("context array must have string, number or boolean values, but was [VALUE_NULL]", e.getCause().getMessage()); } @@ -351,7 +351,7 @@ public void testIndexingWithMultipleContexts() throws Exception { .endArray() .endObject(); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", builder.bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } diff --git a/core/src/test/java/org/elasticsearch/search/suggest/completion/GeoContextMappingTests.java b/core/src/test/java/org/elasticsearch/search/suggest/completion/GeoContextMappingTests.java index 9e22ad64d5c1e..fba284afe7bd0 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/completion/GeoContextMappingTests.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/completion/GeoContextMappingTests.java @@ -81,7 +81,7 @@ public void testIndexingWithNoContexts() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 7); } @@ -119,7 +119,7 @@ public void testIndexingWithSimpleContexts() throws Exception { .endArray() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } @@ -160,7 +160,7 @@ public void testIndexingWithContextList() throws Exception { .endObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } @@ -199,7 +199,7 @@ public void testIndexingWithMultipleContexts() throws Exception { .endArray() .endObject(); ParsedDocument parsedDocument = defaultMapper.parse(SourceToParse.source("test", "type1", "1", builder.bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } diff --git a/docs/reference/mapping/fields.asciidoc b/docs/reference/mapping/fields.asciidoc index 9361c6b26dd9d..c58e074086c89 100644 --- a/docs/reference/mapping/fields.asciidoc +++ b/docs/reference/mapping/fields.asciidoc @@ -48,6 +48,10 @@ can be customised when a mapping type is created. All fields in the document which contain non-null values. +<>:: + + A field that stores the shard id of the shard that the document was indexed into. + [float] === Routing meta-field @@ -62,6 +66,10 @@ can be customised when a mapping type is created. Application specific metadata. +<>:: + + An internal field that stores a sequence number. + include::fields/all-field.asciidoc[] @@ -81,3 +89,6 @@ include::fields/type-field.asciidoc[] include::fields/uid-field.asciidoc[] +include::fields/shard-field.asciidoc[] + +include::fields/seq-no-field.asciidoc[] diff --git a/docs/reference/mapping/fields/seq-no-field.asciidoc b/docs/reference/mapping/fields/seq-no-field.asciidoc new file mode 100644 index 0000000000000..36fabbfb06b95 --- /dev/null +++ b/docs/reference/mapping/fields/seq-no-field.asciidoc @@ -0,0 +1,12 @@ +[[mapping-seq-no-field]] +=== `_seq_no` field + +A sequence number is assigned with each operation to the index. This is mostly +an internal field, which is especially useful to speed up recovery. + +An interesting property of this field is that each document in a given shard +has a unique value for the `_seq_no` field, so it can be used as a tie breaker +combined with <>. + +NOTE: This field was introduced in 6.0. As a consequence, 5.x indices do not +have values for this field. diff --git a/docs/reference/mapping/fields/shard-field.asciidoc b/docs/reference/mapping/fields/shard-field.asciidoc new file mode 100644 index 0000000000000..0f754027120f6 --- /dev/null +++ b/docs/reference/mapping/fields/shard-field.asciidoc @@ -0,0 +1,11 @@ +[[mapping-shard-field]] +=== `_shard` field + +Each document stores the shard id that it went into at index time. This is +typically useful for stable pagination when using `_shard` and either `_doc` +or <> as tie-breakers. + +NOTE: This field was introduced in 6.0. As a consequence, 5.x indices do not +know its value and behave as if the shard id was the current shard, which might +be different from the shard that the document was initially indexed into in +the case of <> indices. diff --git a/docs/reference/search/request/search-after.asciidoc b/docs/reference/search/request/search-after.asciidoc index 87f5abba8b2e3..3916074cb08c8 100644 --- a/docs/reference/search/request/search-after.asciidoc +++ b/docs/reference/search/request/search-after.asciidoc @@ -20,8 +20,9 @@ GET twitter/tweet/_search } }, "sort": [ - {"date": "asc"}, - {"_id": "desc"} + {"date": "asc"}, + {"_shard": "asc"}, + {"_seq_no": "asc"} ] } -------------------------------------------------- @@ -29,8 +30,9 @@ GET twitter/tweet/_search // TEST[setup:twitter] NOTE: A field with one unique value per document should be used as the tiebreaker of the sort specification. -Otherwise the sort order for documents that have the same sort values would be undefined. The recommended way is to use -the field `_id` which is certain to contain one unique value for each document. +Otherwise the sort order for documents that have the same sort values would be undefined. The recommended way +is to use <> on 5.x indices and <> plus +<> on 6.x indices. The result from the above request includes an array of `sort values` for each document. These `sort values` can be used in conjunction with the `search_after` parameter to start returning results "after" any @@ -47,10 +49,11 @@ GET twitter/tweet/_search "title" : "elasticsearch" } }, - "search_after": [1463538857, "654323"], + "search_after": [1463538857, "2", 30], "sort": [ {"date": "asc"}, - {"_id": "desc"} + {"_shard": "asc"}, + {"_seq_no": "asc"} ] } -------------------------------------------------- diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceAggregationBuilder.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceAggregationBuilder.java index 8ac189167b63b..45b7bae8f197d 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceAggregationBuilder.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceAggregationBuilder.java @@ -270,7 +270,7 @@ public ValuesSourceConfig config(SearchContext context, String field, Script return config.unmapped(true); } - IndexFieldData indexFieldData = context.fieldData().getForField(fieldType); + IndexFieldData indexFieldData = context.fieldData().getForField(fieldType, context.getQueryShardContext().getShardId()); ValuesSourceConfig config; if (valuesSourceType == ValuesSourceType.ANY) { diff --git a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java index a29eab27cc0ca..4363f43e2edc6 100644 --- a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java +++ b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java @@ -186,7 +186,7 @@ private SearchScript.LeafFactory newSearchScript(Expression expr, SearchLookup l throw new ParseException("Field [" + fieldname + "] does not exist in mappings", 5); } - IndexFieldData fieldData = lookup.doc().fieldDataService().getForField(fieldType); + IndexFieldData fieldData = lookup.doc().fieldDataService().getForField(fieldType, -1); // delegate valuesource creation based on field's type // there are three types of "fields" to expressions, and each one has a different "api" of variables and methods. diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregationBuilder.java b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregationBuilder.java index c0dba06ffa065..9c26b09672bea 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregationBuilder.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregationBuilder.java @@ -108,7 +108,8 @@ private void joinFieldResolveConfig(SearchContext context, ValuesSourceConfig docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject() .field("join_field", "unknown") - .endObject().bytes(), XContentType.JSON))); + .endObject().bytes(), XContentType.JSON, 0))); assertThat(exc.getRootCause().getMessage(), containsString("unknown join name [unknown] for field [join_field]")); } @@ -113,7 +113,7 @@ public void testParentIdSpecifiedAsNumber() throws Exception { .field("name", "child") .field("parent", 1) .endObject() - .endObject().bytes(), XContentType.JSON).routing("1")); + .endObject().bytes(), XContentType.JSON, 0).routing("1")); assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); doc = docMapper.parse(SourceToParse.source("test", "type", "2", @@ -122,7 +122,7 @@ public void testParentIdSpecifiedAsNumber() throws Exception { .field("name", "child") .field("parent", 1.0) .endObject() - .endObject().bytes(), XContentType.JSON).routing("1")); + .endObject().bytes(), XContentType.JSON, 0).routing("1")); assertEquals("1.0", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); } @@ -146,7 +146,7 @@ public void testMultipleLevels() throws Exception { // Doc without join ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "0", - XContentFactory.jsonBuilder().startObject().endObject().bytes(), XContentType.JSON)); + XContentFactory.jsonBuilder().startObject().endObject().bytes(), XContentType.JSON, 0)); assertNull(doc.rootDoc().getBinaryValue("join_field")); // Doc parent @@ -154,7 +154,7 @@ public void testMultipleLevels() throws Exception { XContentFactory.jsonBuilder() .startObject() .field("join_field", "parent") - .endObject().bytes(), XContentType.JSON)); + .endObject().bytes(), XContentType.JSON, 0)); assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); @@ -165,7 +165,7 @@ public void testMultipleLevels() throws Exception { .field("name", "child") .field("parent", "1") .endObject() - .endObject().bytes(), XContentType.JSON).routing("1")); + .endObject().bytes(), XContentType.JSON, 0).routing("1")); assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString()); assertEquals("2", doc.rootDoc().getBinaryValue("join_field#child").utf8ToString()); assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); @@ -175,7 +175,7 @@ public void testMultipleLevels() throws Exception { () -> docMapper.parse(SourceToParse.source("test", "type", "2", XContentFactory.jsonBuilder().startObject() .field("join_field", "child") - .endObject().bytes(), XContentType.JSON).routing("1"))); + .endObject().bytes(), XContentType.JSON, 0).routing("1"))); assertThat(exc.getRootCause().getMessage(), containsString("[parent] is missing for join field [join_field]")); // Doc child missing routing @@ -186,7 +186,7 @@ public void testMultipleLevels() throws Exception { .field("name", "child") .field("parent", "1") .endObject() - .endObject().bytes(), XContentType.JSON))); + .endObject().bytes(), XContentType.JSON, 0))); assertThat(exc.getRootCause().getMessage(), containsString("[routing] is missing for join field [join_field]")); // Doc grand_child @@ -196,7 +196,7 @@ public void testMultipleLevels() throws Exception { .field("name", "grand_child") .field("parent", "2") .endObject() - .endObject().bytes(), XContentType.JSON).routing("1")); + .endObject().bytes(), XContentType.JSON, 0).routing("1")); assertEquals("2", doc.rootDoc().getBinaryValue("join_field#child").utf8ToString()); assertEquals("grand_child", doc.rootDoc().getBinaryValue("join_field").utf8ToString()); @@ -205,7 +205,7 @@ public void testMultipleLevels() throws Exception { () -> docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject() .field("join_field", "unknown") - .endObject().bytes(), XContentType.JSON))); + .endObject().bytes(), XContentType.JSON, 0))); assertThat(exc.getRootCause().getMessage(), containsString("unknown join name [unknown] for field [join_field]")); } diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java index aa9f2904b11a9..f55bf3553613f 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java @@ -450,14 +450,14 @@ protected Query doToQuery(QueryShardContext context) throws IOException { } } docMapper = mapperService.documentMapper(type); - doc = docMapper.parse(source(context.index().getName(), type, "_temp_id", document, documentXContentType)); + doc = docMapper.parse(source(context.index().getName(), type, "_temp_id", document, documentXContentType, 0)); } else { if (documentType == null) { throw new IllegalArgumentException("[percolate] query is missing required [document_type] parameter"); } DocumentMapperForType docMapperForType = mapperService.documentMapperWithAutoCreate(documentType); docMapper = docMapperForType.getDocumentMapper(); - doc = docMapper.parse(source(context.index().getName(), documentType, "_temp_id", document, documentXContentType)); + doc = docMapper.parse(source(context.index().getName(), documentType, "_temp_id", document, documentXContentType, 0)); } FieldNameAnalyzer fieldNameAnalyzer = (FieldNameAnalyzer) docMapper.mappers().indexAnalyzer(); @@ -591,7 +591,7 @@ public > IFD getForField(MappedFieldType fieldType IndexFieldDataCache cache = new IndexFieldDataCache.None(); CircuitBreakerService circuitBreaker = new NoneCircuitBreakerService(); return (IFD) builder.build(shardContext.getIndexSettings(), fieldType, cache, circuitBreaker, - shardContext.getMapperService()); + shardContext.getMapperService(), getShardId()); } }; } diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java index ecd75969692bc..b10b1e07e95ac 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java @@ -248,7 +248,7 @@ public void testPercolatorFieldMapper() throws Exception { .startObject() .field(fieldName, queryBuilder) .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getFields(fieldType.queryTermsField.name()).length, equalTo(1)); assertThat(doc.rootDoc().getFields(fieldType.queryTermsField.name())[0].binaryValue().utf8ToString(), equalTo("field\0value")); @@ -266,7 +266,7 @@ public void testPercolatorFieldMapper() throws Exception { .startObject() .field(fieldName, queryBuilder) .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getFields(fieldType.extractionResultField.name()).length, equalTo(1)); assertThat(doc.rootDoc().getFields(fieldType.extractionResultField.name())[0].stringValue(), equalTo(EXTRACTION_FAILED)); @@ -291,7 +291,7 @@ public void testStoringQueries() throws Exception { XContentFactory.jsonBuilder().startObject() .field(fieldName, query) .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); BytesRef qbSource = doc.rootDoc().getFields(fieldType.queryBuilderField.name())[0].binaryValue(); assertQueryBuilder(qbSource, query); } @@ -306,7 +306,7 @@ public void testQueryWithRewrite() throws Exception { .startObject() .field(fieldName, queryBuilder) .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); BytesRef qbSource = doc.rootDoc().getFields(fieldType.queryBuilderField.name())[0].binaryValue(); assertQueryBuilder(qbSource, queryBuilder.rewrite(indexService.newQueryShardContext( randomInt(20), null, () -> { throw new UnsupportedOperationException(); }))); @@ -321,7 +321,7 @@ public void testPercolatorFieldMapperUnMappedField() throws Exception { .startObject() .field(fieldName, termQuery("unmapped_field", "value")) .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); }); assertThat(exception.getCause(), instanceOf(QueryShardException.class)); assertThat(exception.getCause().getMessage(), equalTo("No field mapping can be found for the field with name [unmapped_field]")); @@ -335,7 +335,7 @@ public void testPercolatorFieldMapper_noQuery() throws Exception { .startObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getFields(fieldType.queryBuilderField.name()).length, equalTo(0)); try { @@ -344,7 +344,7 @@ public void testPercolatorFieldMapper_noQuery() throws Exception { .startObject() .nullField(fieldName) .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); } catch (MapperParsingException e) { assertThat(e.getDetailedMessage(), containsString("query malformed, must start with start_object")); } @@ -381,7 +381,7 @@ public void testMultiplePercolatorFields() throws Exception { .field("query_field1", queryBuilder) .field("query_field2", queryBuilder) .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getFields().size(), equalTo(12)); // also includes all other meta fields BytesRef queryBuilderAsBytes = doc.rootDoc().getField("query_field1.query_builder_field").binaryValue(); assertQueryBuilder(queryBuilderAsBytes, queryBuilder); @@ -411,7 +411,7 @@ public void testNestedPercolatorField() throws Exception { jsonBuilder().startObject().startObject("object_field") .field("query_field", queryBuilder) .endObject().endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getFields().size(), equalTo(9)); // also includes all other meta fields BytesRef queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue(); assertQueryBuilder(queryBuilderAsBytes, queryBuilder); @@ -422,7 +422,7 @@ public void testNestedPercolatorField() throws Exception { .startObject().field("query_field", queryBuilder).endObject() .endArray() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertThat(doc.rootDoc().getFields().size(), equalTo(9)); // also includes all other meta fields queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue(); assertQueryBuilder(queryBuilderAsBytes, queryBuilder); @@ -435,7 +435,7 @@ public void testNestedPercolatorField() throws Exception { .startObject().field("query_field", queryBuilder).endObject() .endArray() .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); } ); assertThat(e.getCause(), instanceOf(IllegalArgumentException.class)); @@ -508,7 +508,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { XContentFactory.jsonBuilder().startObject() .rawField(fieldName, new BytesArray(query.string()), query.contentType()) .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); BytesRef querySource = doc.rootDoc().getFields(fieldType.queryBuilderField.name())[0].binaryValue(); Map parsedQuery = XContentHelper.convertToMap(new BytesArray(querySource), true).v2(); assertEquals(Script.DEFAULT_SCRIPT_LANG, XContentMapValues.extractValue("script.script.lang", parsedQuery)); @@ -536,7 +536,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { XContentFactory.jsonBuilder().startObject() .rawField(fieldName, new BytesArray(query.string()), query.contentType()) .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); querySource = doc.rootDoc().getFields(fieldType.queryBuilderField.name())[0].binaryValue(); parsedQuery = XContentHelper.convertToMap(new BytesArray(querySource), true).v2(); assertEquals(Script.DEFAULT_SCRIPT_LANG, diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java index ebe909837e999..558da50fa8ce0 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java @@ -75,7 +75,7 @@ public void testDefaults() throws Exception { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -115,7 +115,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); mapping = XContentFactory.jsonBuilder().startObject().startObject("type") @@ -131,7 +131,7 @@ public void testNullValue() throws IOException { .startObject() .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(0, fields.length); @@ -141,7 +141,7 @@ public void testNullValue() throws IOException { .nullField("field") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); Collator collator = Collator.getInstance(); RawCollationKey key = collator.getRawCollationKey("1234", null); @@ -167,7 +167,7 @@ public void testEnableStore() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -189,7 +189,7 @@ public void testDisableIndex() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -212,7 +212,7 @@ public void testDisableDocValues() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); @@ -234,7 +234,7 @@ public void testIndexOptions() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -267,7 +267,7 @@ public void testEnableNorms() throws IOException { .field("field", "1234") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); @@ -291,7 +291,7 @@ public void testCollator() throws IOException { .field("field", "I WİLL USE TURKİSH CASING") .endObject() .bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); Collator collator = Collator.getInstance(new ULocale("tr")); collator.setStrength(Collator.PRIMARY); diff --git a/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java b/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java index 6afefc5cf0361..424cc5d005e19 100644 --- a/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java +++ b/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java @@ -79,7 +79,7 @@ public void testDefaults() throws Exception { .startObject() .field("field", "value") .endObject().bytes(), - XContentType.JSON)); + XContentType.JSON, 0)); IndexableField[] fields = parsedDoc.rootDoc().getFields("field"); assertNotNull(fields); assertEquals(Arrays.toString(fields), 1, fields.length); diff --git a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java index 2cde1b1bd07d2..283dc7d5c0cfa 100644 --- a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java +++ b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java @@ -61,7 +61,7 @@ public void testSizeEnabled() throws Exception { .field("field", "value") .endObject() .bytes(); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON, 0)); boolean stored = false; boolean points = false; @@ -82,7 +82,7 @@ public void testSizeDisabled() throws Exception { .field("field", "value") .endObject() .bytes(); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("_size"), nullValue()); } @@ -96,7 +96,7 @@ public void testSizeNotSet() throws Exception { .field("field", "value") .endObject() .bytes(); - ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON)); + ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON, 0)); assertThat(doc.rootDoc().getField("_size"), nullValue()); } diff --git a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java index d0ce47c97fcf8..14627bf867c7f 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java @@ -538,7 +538,8 @@ protected Engine.IndexResult indexDoc(IndexShard shard, String type, String id, protected Engine.IndexResult indexDoc(IndexShard shard, String type, String id, String source, XContentType xContentType) throws IOException { - SourceToParse sourceToParse = SourceToParse.source(shard.shardId().getIndexName(), type, id, new BytesArray(source), xContentType); + SourceToParse sourceToParse = SourceToParse.source(shard.shardId().getIndexName(), type, id, new BytesArray(source), + xContentType, 0); if (shard.routingEntry().primary()) { return shard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, sourceToParse, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, getMappingUpdater(shard, type)); diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java index 074ce1f8c477b..e116d08640470 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java @@ -196,7 +196,7 @@ protected QueryShardContext queryShardContextMock(MapperService mapperService, M when(queryShardContext.fieldMapper(fieldType.name())).thenReturn(fieldType); when(queryShardContext.getForField(fieldType)).then(invocation -> fieldType.fielddataBuilder().build( mapperService.getIndexSettings(), fieldType, new IndexFieldDataCache.None(), circuitBreakerService, - mapperService)); + mapperService, 0)); } NestedScope nestedScope = new NestedScope(); when(queryShardContext.isFilter()).thenCallRealMethod();