Merge pull request #11074 from rjernst/pr/include-in-object-removal

Mappings: Remove ability to set meta fields inside documents
This commit is contained in:
Ryan Ernst 2015-05-12 23:24:36 -07:00
commit 1b15333f34
48 changed files with 293 additions and 371 deletions

View File

@ -279,6 +279,11 @@ to provide special features. They now have limited configuration options.
* `_field_names` configuration is limited to disabling the field.
* `_size` configuration is limited to enabling the field.
==== Meta fields in documents
Meta fields can no longer be specified within a document. They should be specified
via the API. For example, instead of adding a field `_parent` within a document,
use the `parent` url parameter when indexing that document.
==== Source field limitations
The `_source` field could previously be disabled dynamically. Since this field
is a critical piece of many features like the Update API, it is no longer

View File

@ -30,6 +30,7 @@ import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.elasticsearch.ElasticsearchGenerationException;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
@ -194,6 +195,7 @@ public class DocumentMapper implements ToXContent {
this.type = rootObjectMapper.name();
this.typeText = new StringAndBytesText(this.type);
this.mapping = new Mapping(
Version.indexCreated(indexSettings),
rootObjectMapper,
rootMappers.values().toArray(new RootMapper[rootMappers.values().size()]),
sourceTransforms.toArray(new SourceTransform[sourceTransforms.size()]),
@ -210,7 +212,7 @@ public class DocumentMapper implements ToXContent {
// collect all the mappers for this type
List<ObjectMapper> newObjectMappers = new ArrayList<>();
List<FieldMapper<?>> newFieldMappers = new ArrayList<>();
for (RootMapper rootMapper : this.mapping.rootMappersNotIncludedInObject) {
for (RootMapper rootMapper : this.mapping.rootMappers) {
if (rootMapper instanceof FieldMapper) {
newFieldMappers.add((FieldMapper) rootMapper);
}

View File

@ -1,28 +0,0 @@
/*
* 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;
/**
* A marker interface for internal mappings.
*
*
*/
public interface InternalMapper {
}

View File

@ -267,8 +267,8 @@ public class MapperService extends AbstractIndexComponent {
List<ObjectMapper> newObjectMappers = new ArrayList<>();
List<FieldMapper<?>> newFieldMappers = new ArrayList<>();
for (RootMapper rootMapper : mapper.mapping().rootMappers) {
if (!rootMapper.includeInObject() && rootMapper instanceof FieldMapper) {
newFieldMappers.add((FieldMapper<?>) rootMapper);
if (rootMapper instanceof FieldMapper<?>) {
newFieldMappers.add((FieldMapper<?>)rootMapper);
}
}
MapperUtils.collect(mapper.mapping().root, newObjectMappers, newFieldMappers);

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -28,7 +29,8 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.object.RootObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
@ -38,6 +40,8 @@ import java.util.Map;
*/
public final class Mapping implements ToXContent {
public static final List<String> LEGACY_INCLUDE_IN_OBJECT = Arrays.asList("_all", "_id", "_parent", "_routing", "_timestamp", "_ttl");
/**
* Transformations to be applied to the source before indexing and/or after loading.
*/
@ -50,27 +54,31 @@ public final class Mapping implements ToXContent {
Map<String, Object> transformSourceAsMap(Map<String, Object> sourceAsMap);
}
final Version indexCreated;
final RootObjectMapper root;
final RootMapper[] rootMappers;
final RootMapper[] rootMappersNotIncludedInObject;
final ImmutableMap<Class<? extends RootMapper>, RootMapper> rootMappersMap;
final SourceTransform[] sourceTransforms;
volatile ImmutableMap<String, Object> meta;
public Mapping(RootObjectMapper rootObjectMapper, RootMapper[] rootMappers, SourceTransform[] sourceTransforms, ImmutableMap<String, Object> meta) {
public Mapping(Version indexCreated, RootObjectMapper rootObjectMapper, RootMapper[] rootMappers, SourceTransform[] sourceTransforms, ImmutableMap<String, Object> meta) {
this.indexCreated = indexCreated;
this.root = rootObjectMapper;
this.rootMappers = rootMappers;
List<RootMapper> rootMappersNotIncludedInObject = new ArrayList<>();
ImmutableMap.Builder<Class<? extends RootMapper>, RootMapper> builder = ImmutableMap.builder();
for (RootMapper rootMapper : rootMappers) {
if (rootMapper.includeInObject()) {
if (indexCreated.before(Version.V_2_0_0) && LEGACY_INCLUDE_IN_OBJECT.contains(rootMapper.name())) {
root.putMapper(rootMapper);
} else {
rootMappersNotIncludedInObject.add(rootMapper);
}
builder.put(rootMapper.getClass(), rootMapper);
}
this.rootMappersNotIncludedInObject = rootMappersNotIncludedInObject.toArray(new RootMapper[rootMappersNotIncludedInObject.size()]);
// keep root mappers sorted for consistent serialization
Arrays.sort(rootMappers, new Comparator<Mapper>() {
@Override
public int compare(Mapper o1, Mapper o2) {
return o1.name().compareTo(o2.name());
}
});
this.rootMappersMap = builder.build();
this.sourceTransforms = sourceTransforms;
this.meta = meta;
@ -85,7 +93,7 @@ public final class Mapping implements ToXContent {
* Generate a mapping update for the given root object mapper.
*/
public Mapping mappingUpdate(Mapper rootObjectMapper) {
return new Mapping((RootObjectMapper) rootObjectMapper, rootMappers, sourceTransforms, meta);
return new Mapping(indexCreated, (RootObjectMapper) rootObjectMapper, rootMappers, sourceTransforms, meta);
}
/** Get the root mapper with the given class. */
@ -100,10 +108,6 @@ public final class Mapping implements ToXContent {
root.merge(mergeWith.root, mergeResult);
for (RootMapper rootMapper : rootMappers) {
// root mappers included in root object will get merge in the rootObjectMapper
if (rootMapper.includeInObject()) {
continue;
}
RootMapper mergeWithRootMapper = mergeWith.rootMapper(rootMapper.getClass());
if (mergeWithRootMapper != null) {
rootMapper.merge(mergeWithRootMapper, mergeResult);
@ -137,11 +141,12 @@ public final class Mapping implements ToXContent {
if (meta != null && !meta.isEmpty()) {
builder.field("_meta", meta);
}
for (Mapper mapper : rootMappers) {
mapper.toXContent(builder, params);
}
return builder;
}
// no need to pass here id and boost, since they are added to the root object mapper
// in the constructor
}, rootMappersNotIncludedInObject);
});
return builder;
}

View File

@ -39,15 +39,4 @@ public interface RootMapper extends Mapper {
*/
void postParse(ParseContext context) throws IOException;
/**
* Should the mapper be included in the root
* {@link org.elasticsearch.index.mapper.object.ObjectMapper}.
*
* If this method returns true, then {@link #parse(ParseContext)} will be
* called if the context has a property that matches the name of this
* {@link RootMapper}. Otherwise {@link #parse(ParseContext)} will not
* be called.
*/
boolean includeInObject();
}

View File

@ -36,11 +36,10 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
@ -61,7 +60,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class AllFieldMapper extends AbstractFieldMapper<String> implements InternalMapper, RootMapper {
public class AllFieldMapper extends AbstractFieldMapper<String> implements RootMapper {
public interface IncludeInAll extends Mapper {
@ -212,11 +211,6 @@ public class AllFieldMapper extends AbstractFieldMapper<String> implements Inter
return null;
}
@Override
public boolean includeInObject() {
return true;
}
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (!enabledState.enabled) {

View File

@ -22,10 +22,8 @@ package org.elasticsearch.index.mapper.internal;
import com.google.common.collect.UnmodifiableIterator;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
@ -33,11 +31,10 @@ import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
@ -58,7 +55,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
*
* Added in Elasticsearch 1.3.
*/
public class FieldNamesFieldMapper extends AbstractFieldMapper<String> implements InternalMapper, RootMapper {
public class FieldNamesFieldMapper extends AbstractFieldMapper<String> implements RootMapper {
public static final String NAME = "_field_names";
@ -188,11 +185,6 @@ public class FieldNamesFieldMapper extends AbstractFieldMapper<String> implement
return null;
}
@Override
public boolean includeInObject() {
return false;
}
static Iterable<String> extractFieldNames(final String fullPath) {
return new Iterable<String>() {
@Override

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.mapper.internal;
import com.google.common.collect.Iterables;
import org.apache.lucene.document.BinaryDocValuesField;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
@ -44,7 +43,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeMappingException;
@ -57,7 +55,6 @@ import org.elasticsearch.index.query.QueryParseContext;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -68,7 +65,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class IdFieldMapper extends AbstractFieldMapper<String> implements InternalMapper, RootMapper {
public class IdFieldMapper extends AbstractFieldMapper<String> implements RootMapper {
public static final String NAME = "_id";
@ -264,11 +261,6 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
// it either get built in the preParse phase, or get parsed...
}
@Override
public boolean includeInObject() {
return true;
}
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
XContentParser parser = context.parser();

View File

@ -30,12 +30,11 @@ import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperBuilders;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
@ -51,7 +50,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class IndexFieldMapper extends AbstractFieldMapper<String> implements InternalMapper, RootMapper {
public class IndexFieldMapper extends AbstractFieldMapper<String> implements RootMapper {
public static final String NAME = "_index";
@ -170,11 +169,6 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
return null;
}
@Override
public boolean includeInObject() {
return false;
}
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (!enabledState.enabled) {

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.mapper.internal;
import com.google.common.base.Objects;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.IndexOptions;
@ -36,7 +35,6 @@ import org.elasticsearch.common.settings.loader.SettingsLoader;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeMappingException;
@ -62,7 +60,7 @@ import static org.elasticsearch.index.mapper.MapperBuilders.parent;
/**
*
*/
public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements InternalMapper, RootMapper {
public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements RootMapper {
public static final String NAME = "_parent";
@ -181,11 +179,6 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements Inter
parse(context);
}
@Override
public boolean includeInObject() {
return true;
}
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (!active()) {

View File

@ -30,11 +30,10 @@ import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
@ -51,7 +50,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class RoutingFieldMapper extends AbstractFieldMapper<String> implements InternalMapper, RootMapper {
public class RoutingFieldMapper extends AbstractFieldMapper<String> implements RootMapper {
public static final String NAME = "_routing";
public static final String CONTENT_TYPE = "_routing";
@ -189,11 +188,6 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
return null;
}
@Override
public boolean includeInObject() {
return true;
}
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (context.sourceToParse().routing() != null) {

View File

@ -139,11 +139,6 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
return null;
}
@Override
public boolean includeInObject() {
return false;
}
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (!enabledState.enabled) {

View File

@ -45,7 +45,12 @@ import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import java.io.IOException;
@ -60,7 +65,7 @@ import static org.elasticsearch.index.mapper.MapperBuilders.source;
/**
*
*/
public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements InternalMapper, RootMapper {
public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements RootMapper {
public static final String NAME = "_source";
@ -257,11 +262,6 @@ public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements In
return null;
}
@Override
public boolean includeInObject() {
return false;
}
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (!enabled) {

View File

@ -30,11 +30,10 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.AlreadyExpiredException;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.SourceToParse;
@ -52,7 +51,7 @@ import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBo
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeTimeValue;
import static org.elasticsearch.index.mapper.MapperBuilders.ttl;
public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, RootMapper {
public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
public static final String NAME = "_ttl";
public static final String CONTENT_TYPE = "_ttl";
@ -191,11 +190,6 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
return null;
}
@Override
public boolean includeInObject() {
return true;
}
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException, AlreadyExpiredException {
if (enabledState.enabled && !context.sourceToParse().flyweight()) {

View File

@ -32,11 +32,10 @@ import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.joda.Joda;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
@ -54,7 +53,7 @@ import static org.elasticsearch.index.mapper.MapperBuilders.timestamp;
import static org.elasticsearch.index.mapper.core.TypeParsers.parseDateTimeFormatter;
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
public class TimestampFieldMapper extends DateFieldMapper implements InternalMapper, RootMapper {
public class TimestampFieldMapper extends DateFieldMapper implements RootMapper {
public static final String NAME = "_timestamp";
public static final String CONTENT_TYPE = "_timestamp";
@ -215,7 +214,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), dateTimeFormatter,
Defaults.PRECISION_STEP_64_BIT, Defaults.BOOST, fieldType, docValues,
Defaults.NULL_VALUE, TimeUnit.MILLISECONDS /*always milliseconds*/,
ignoreMalformed, coerce, null, normsLoading, fieldDataSettings,
ignoreMalformed, coerce, null, normsLoading, fieldDataSettings,
indexSettings, MultiFields.empty(), null);
this.enabledState = enabledState;
this.path = path;
@ -278,11 +277,6 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
return null;
}
@Override
public boolean includeInObject() {
return true;
}
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (enabledState.enabled) {

View File

@ -36,7 +36,6 @@ import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeMappingException;
@ -57,7 +56,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class TypeFieldMapper extends AbstractFieldMapper<String> implements InternalMapper, RootMapper {
public class TypeFieldMapper extends AbstractFieldMapper<String> implements RootMapper {
public static final String NAME = "_type";
@ -157,11 +156,6 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
return null;
}
@Override
public boolean includeInObject() {
return false;
}
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (fieldType.indexOptions() == IndexOptions.NONE && !fieldType.stored()) {

View File

@ -32,11 +32,10 @@ import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.RootMapper;
@ -53,7 +52,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class UidFieldMapper extends AbstractFieldMapper<Uid> implements InternalMapper, RootMapper {
public class UidFieldMapper extends AbstractFieldMapper<Uid> implements RootMapper {
public static final String NAME = "_uid";
@ -167,11 +166,6 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
return null;
}
@Override
public boolean includeInObject() {
return false;
}
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
Field uid = new Field(NAME, Uid.createUid(context.stringBuilder(), context.type(), context.id()), Defaults.FIELD_TYPE);

View File

@ -27,11 +27,10 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.RootMapper;
@ -45,7 +44,7 @@ import java.util.Map;
import static org.elasticsearch.index.mapper.MapperBuilders.version;
/** Mapper for the _version field. */
public class VersionFieldMapper extends AbstractFieldMapper<Long> implements InternalMapper, RootMapper {
public class VersionFieldMapper extends AbstractFieldMapper<Long> implements RootMapper {
public static final String NAME = "_version";
public static final String CONTENT_TYPE = "_version";
@ -136,11 +135,6 @@ public class VersionFieldMapper extends AbstractFieldMapper<Long> implements Int
}
}
@Override
public boolean includeInObject() {
return false;
}
@Override
public FieldType defaultFieldType() {
return Defaults.FIELD_TYPE;

View File

@ -37,12 +37,12 @@ import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.InternalMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MapperUtils;
import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.internal.AllFieldMapper;
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.index.settings.IndexSettings;
@ -57,7 +57,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import static com.google.common.collect.Lists.newArrayList;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
@ -524,7 +523,8 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll, Clonea
mappersToPut.add(mergeWithMapper);
MapperUtils.collect(mergeWithMapper, newObjectMappers, newFieldMappers);
}
} else {
} else if (mergeIntoMapper instanceof RootMapper == false) {
// root mappers can only exist here for backcompat, and are merged in Mapping
mergeIntoMapper.merge(mergeWithMapper, mergeResult);
}
}
@ -553,11 +553,11 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll, Clonea
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
toXContent(builder, params, null, Mapper.EMPTY_ARRAY);
toXContent(builder, params, null);
return builder;
}
public void toXContent(XContentBuilder builder, Params params, ToXContent custom, Mapper... additionalMappers) throws IOException {
public void toXContent(XContentBuilder builder, Params params, ToXContent custom) throws IOException {
builder.startObject(name);
if (nested.isNested()) {
builder.field("type", NESTED_CONTENT_TYPE);
@ -567,7 +567,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll, Clonea
if (nested.isIncludeInRoot()) {
builder.field("include_in_root", true);
}
} else if (mappers.isEmpty()) { // only write the object content type if there are no properties, otherwise, it is automatically detected
} else if (mappers.isEmpty() && custom == null) { // only write the object content type if there are no properties, otherwise, it is automatically detected
builder.field("type", CONTENT_TYPE);
}
if (dynamic != null) {
@ -598,26 +598,9 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll, Clonea
}
});
// check internal mappers first (this is only relevant for root object)
for (Mapper mapper : sortedMappers) {
if (mapper instanceof InternalMapper) {
mapper.toXContent(builder, params);
}
}
if (additionalMappers != null && additionalMappers.length > 0) {
TreeMap<String, Mapper> additionalSortedMappers = new TreeMap<>();
for (Mapper mapper : additionalMappers) {
additionalSortedMappers.put(mapper.name(), mapper);
}
for (Mapper mapper : additionalSortedMappers.values()) {
mapper.toXContent(builder, params);
}
}
int count = 0;
for (Mapper mapper : sortedMappers) {
if (!(mapper instanceof InternalMapper)) {
if (!(mapper instanceof RootMapper)) {
if (count++ == 0) {
builder.startObject("properties");
}

View File

@ -34,6 +34,7 @@ import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.engine.VersionConflictEngineException;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
@ -977,11 +978,8 @@ public class GetActionTests extends ElasticsearchIntegrationTest {
"}";
assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource));
ensureGreen();
String doc = "{\n" +
" \"_ttl\": \"1h\"\n" +
"}";
client().prepareIndex("test", "doc").setId("1").setSource(doc).setParent("1").get();
client().prepareIndex("test", "doc").setId("1").setSource("{}").setParent("1").setTTL(TimeValue.timeValueHours(1).getMillis()).get();
String[] fieldsList = {"_ttl", "_parent"};
// before refresh - document is only in translog

View File

@ -1651,7 +1651,7 @@ public class InternalEngineTests extends ElasticsearchTestCase {
private Mapping dynamicUpdate() {
BuilderContext context = new BuilderContext(ImmutableSettings.EMPTY, new ContentPath());
final RootObjectMapper root = MapperBuilders.rootObject("some_type").build(context);
return new Mapping(root, new RootMapper[0], new Mapping.SourceTransform[0], ImmutableMap.<String, Object>of());
return new Mapping(Version.CURRENT, root, new RootMapper[0], new Mapping.SourceTransform[0], ImmutableMap.<String, Object>of());
}
public void testTranslogReplay() throws IOException {

View File

@ -41,12 +41,12 @@ import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.engine.Engine.Searcher;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.internal.AllFieldMapper;
import org.elasticsearch.index.mapper.internal.IndexFieldMapper;
import org.elasticsearch.index.mapper.internal.SizeFieldMapper;
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.hamcrest.Matchers;
import org.junit.Test;
@ -61,7 +61,6 @@ import java.util.Map;
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
@ -70,17 +69,13 @@ import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
/**
*
*/
public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void testSimpleAllMappers() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping.json");
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
Document doc = docMapper.parse("person", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
// One field is boosted so we should see AllTokenStream used:
assertThat(field.tokenStream(docMapper.mappers().indexAnalyzer(), null), Matchers.instanceOf(AllTokenStream.class));
@ -89,53 +84,49 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
assertThat(allEntries.fields().contains("address.last.location"), equalTo(true));
assertThat(allEntries.fields().contains("name.last"), equalTo(true));
assertThat(allEntries.fields().contains("simple1"), equalTo(true));
FieldMapper mapper = docMapper.mappers().smartNameFieldMapper("_all");
AllFieldMapper mapper = docMapper.allFieldMapper();
assertThat(field.fieldType().omitNorms(), equalTo(true));
assertThat(mapper.queryStringTermQuery(new Term("_all", "foobar")), Matchers.instanceOf(AllTermQuery.class));
}
@Test
public void testAllMappersNoBoost() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/noboost-mapping.json");
IndexService index = createIndex("test");
DocumentMapper docMapper = index.mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
Document doc = docMapper.parse("person", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
AllEntries allEntries = field.getAllEntries();
assertThat(allEntries.fields().size(), equalTo(3));
assertThat(allEntries.fields().contains("address.last.location"), equalTo(true));
assertThat(allEntries.fields().contains("name.last"), equalTo(true));
assertThat(allEntries.fields().contains("simple1"), equalTo(true));
FieldMapper mapper = docMapper.mappers().smartNameFieldMapper("_all");
assertThat(field.fieldType().omitNorms(), equalTo(false));
}
@Test
public void testAllMappersTermQuery() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping_omit_positions_on_all.json");
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
Document doc = docMapper.parse("person", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
AllEntries allEntries = field.getAllEntries();
assertThat(allEntries.fields().size(), equalTo(3));
assertThat(allEntries.fields().contains("address.last.location"), equalTo(true));
assertThat(allEntries.fields().contains("name.last"), equalTo(true));
assertThat(allEntries.fields().contains("simple1"), equalTo(true));
FieldMapper mapper = docMapper.mappers().smartNameFieldMapper("_all");
AllFieldMapper mapper = docMapper.allFieldMapper();
assertThat(field.fieldType().omitNorms(), equalTo(false));
assertThat(mapper.queryStringTermQuery(new Term("_all", "foobar")), Matchers.instanceOf(AllTermQuery.class));
}
// #6187: make sure we see AllTermQuery even when offsets are indexed in the _all field:
@Test
public void testAllMappersWithOffsetsTermQuery() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping_offsets_on_all.json");
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
Document doc = docMapper.parse("person", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
// _all field indexes positions, and mapping has boosts, so we should see AllTokenStream:
assertThat(field.tokenStream(docMapper.mappers().indexAnalyzer(), null), Matchers.instanceOf(AllTokenStream.class));
@ -144,37 +135,33 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
assertThat(allEntries.fields().contains("address.last.location"), equalTo(true));
assertThat(allEntries.fields().contains("name.last"), equalTo(true));
assertThat(allEntries.fields().contains("simple1"), equalTo(true));
FieldMapper mapper = docMapper.mappers().smartNameFieldMapper("_all");
AllFieldMapper mapper = docMapper.allFieldMapper();
assertThat(field.fieldType().omitNorms(), equalTo(false));
assertThat(mapper.queryStringTermQuery(new Term("_all", "foobar")), Matchers.instanceOf(AllTermQuery.class));
}
// #6187: if _all doesn't index positions then we never use AllTokenStream, even if some fields have boost
@Test
public void testBoostWithOmitPositions() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping_boost_omit_positions_on_all.json");
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
Document doc = docMapper.parse("person", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
// _all field omits positions, so we should not get AllTokenStream even though fields are boosted
assertThat(field.tokenStream(docMapper.mappers().indexAnalyzer(), null), Matchers.not(Matchers.instanceOf(AllTokenStream.class)));
}
// #6187: if no fields were boosted, we shouldn't use AllTokenStream
@Test
public void testNoBoost() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/noboost-mapping.json");
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
Document doc = docMapper.parse("person", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
// no fields have boost, so we should not see AllTokenStream:
assertThat(field.tokenStream(docMapper.mappers().indexAnalyzer(), null), Matchers.not(Matchers.instanceOf(AllTokenStream.class)));
}
@Test
public void testSimpleAllMappersWithReparse() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping.json");
@ -183,23 +170,22 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
// reparse it
DocumentMapper builtDocMapper = parser.parse(builtMapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = builtDocMapper.parse(new BytesArray(json)).rootDoc();
Document doc = builtDocMapper.parse("person", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
AllEntries allEntries = field.getAllEntries();
assertThat(allEntries.fields().size(), equalTo(3));
assertThat(allEntries.fields().toString(), allEntries.fields().size(), equalTo(3));
assertThat(allEntries.fields().contains("address.last.location"), equalTo(true));
assertThat(allEntries.fields().contains("name.last"), equalTo(true));
assertThat(allEntries.fields().contains("simple1"), equalTo(true));
assertThat(field.fieldType().omitNorms(), equalTo(true));
}
@Test
public void testSimpleAllMappersWithStore() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/store-mapping.json");
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
Document doc = docMapper.parse("person", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
AllEntries allEntries = field.getAllEntries();
assertThat(allEntries.fields().size(), equalTo(2));
@ -211,7 +197,6 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
assertThat(field.fieldType().omitNorms(), equalTo(false));
}
@Test
public void testSimpleAllMappersWithReparseWithStore() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/store-mapping.json");
@ -220,7 +205,7 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
// reparse it
DocumentMapper builtDocMapper = parser.parse(builtMapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = builtDocMapper.parse(new BytesArray(json)).rootDoc();
Document doc = builtDocMapper.parse("person", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
AllEntries allEntries = field.getAllEntries();
@ -233,7 +218,6 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
assertThat(field.fieldType().omitNorms(), equalTo(false));
}
@Test
public void testRandom() throws Exception {
boolean omitNorms = false;
boolean stored = false;
@ -299,10 +283,9 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
byte[] json = jsonBuilder().startObject()
.field("foo", "bar")
.field("_id", 1)
.field("foobar", "foobar")
.endObject().bytes().toBytes();
Document doc = builtDocMapper.parse(new BytesArray(json)).rootDoc();
Document doc = builtDocMapper.parse("test", "1", new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
if (enabled) {
assertThat(field.fieldType().omitNorms(), equalTo(omitNorms));
@ -339,41 +322,37 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
}
@Test
public void testMultiField_includeInAllSetToFalse() throws IOException {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/multifield-mapping_include_in_all_set_to_false.json");
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject()
.field("_id", "1")
.field("foo")
.startObject()
.field("bar", "Elasticsearch rules!")
.endObject()
.endObject();
Document doc = docMapper.parse(builder.bytes()).rootDoc();
Document doc = docMapper.parse("test", "1", builder.bytes()).rootDoc();
AllField field = (AllField) doc.getField("_all");
AllEntries allEntries = field.getAllEntries();
assertThat(allEntries.fields(), empty());
}
@Test
public void testMultiField_defaults() throws IOException {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/multifield-mapping_default.json");
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject()
.field("_id", "1")
.field("foo")
.startObject()
.field("bar", "Elasticsearch rules!")
.endObject()
.endObject();
Document doc = docMapper.parse(builder.bytes()).rootDoc();
Document doc = docMapper.parse("test", "1", builder.bytes()).rootDoc();
AllField field = (AllField) doc.getField("_all");
AllEntries allEntries = field.getAllEntries();
assertThat(allEntries.fields(), hasSize(1));
@ -402,7 +381,6 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
// issue https://github.com/elasticsearch/elasticsearch/issues/5864
// test that RootObjectMapping still works
@Test
public void testRootObjectMapperPropertiesDoNotCauseException() throws IOException {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/type_dynamic_template_mapping.json");
@ -416,7 +394,6 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
}
// issue https://github.com/elasticsearch/elasticsearch/issues/5864
@Test
public void testRootMappersStillWorking() {
String mapping = "{";
Map<String, String> rootTypes = new HashMap<>();
@ -475,4 +452,17 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
}
}
}
public void testIncludeInObjectBackcompat() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type").endObject().endObject().string();
Settings settings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
DocumentMapper docMapper = createIndex("test", settings).mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject().field("_all", "foo").endObject().bytes());
assertNull(doc.rootDoc().get("_all"));
AllField field = (AllField) doc.rootDoc().getField("_all");
// the backcompat behavior is actually ignoring directly specifying _all
assertFalse(field.getAllEntries().fields().iterator().hasNext());
}
}

View File

@ -1,5 +1,4 @@
{
"_id":"1",
"name":{
"first":"shay",
"last":"banon"

View File

@ -48,7 +48,7 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
.string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference json = XContentFactory.jsonBuilder().startObject().field("_id", "1")
BytesReference json = XContentFactory.jsonBuilder().startObject()
.startObject("str_field").field("boost", 2.0).field("value", "some name").endObject()
.startObject("int_field").field("boost", 3.0).field("value", 10).endObject()
.startObject("byte_field").field("boost", 4.0).field("value", 20).endObject()
@ -58,7 +58,7 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
.startObject("long_field").field("boost", 8.0).field("value", 50).endObject()
.startObject("short_field").field("boost", 9.0).field("value", 60).endObject()
.bytes();
Document doc = docMapper.parse(json).rootDoc();
Document doc = docMapper.parse("person", "1", json).rootDoc();
IndexableField f = doc.getField("str_field");
assertThat((double) f.boost(), closeTo(2.0, 0.001));
@ -100,8 +100,8 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
try {
docMapper.parse(XContentFactory.jsonBuilder().startObject()
.field("_id", "1").startObject("str_field").field("foo", "bar")
docMapper.parse("person", "1", XContentFactory.jsonBuilder().startObject()
.startObject("str_field").field("foo", "bar")
.endObject().bytes()).rootDoc();
fail();
} catch (MapperParsingException ex) {
@ -109,8 +109,8 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
}
try {
docMapper.parse(XContentFactory.jsonBuilder().startObject()
.field("_id", "1").startObject("int_field").field("foo", "bar")
docMapper.parse("person", "1", XContentFactory.jsonBuilder().startObject()
.startObject("int_field").field("foo", "bar")
.endObject().bytes()).rootDoc();
fail();
} catch (MapperParsingException ex) {
@ -118,8 +118,8 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
}
try {
docMapper.parse(XContentFactory.jsonBuilder().startObject()
.field("_id", "1").startObject("byte_field").field("foo", "bar")
docMapper.parse("person", "1", XContentFactory.jsonBuilder().startObject()
.startObject("byte_field").field("foo", "bar")
.endObject().bytes()).rootDoc();
fail();
} catch (MapperParsingException ex) {
@ -127,8 +127,8 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
}
try {
docMapper.parse(XContentFactory.jsonBuilder().startObject()
.field("_id", "1").startObject("date_field").field("foo", "bar")
docMapper.parse("person", "1", XContentFactory.jsonBuilder().startObject()
.startObject("date_field").field("foo", "bar")
.endObject().bytes()).rootDoc();
fail();
} catch (MapperParsingException ex) {
@ -136,8 +136,8 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
}
try {
docMapper.parse(XContentFactory.jsonBuilder().startObject()
.field("_id", "1").startObject("double_field").field("foo", "bar")
docMapper.parse("person", "1", XContentFactory.jsonBuilder().startObject()
.startObject("double_field").field("foo", "bar")
.endObject().bytes()).rootDoc();
fail();
} catch (MapperParsingException ex) {
@ -145,8 +145,8 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
}
try {
docMapper.parse(XContentFactory.jsonBuilder().startObject()
.field("_id", "1").startObject("float_field").field("foo", "bar")
docMapper.parse("person", "1", XContentFactory.jsonBuilder().startObject()
.startObject("float_field").field("foo", "bar")
.endObject().bytes()).rootDoc();
fail();
} catch (MapperParsingException ex) {
@ -154,8 +154,8 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
}
try {
docMapper.parse(XContentFactory.jsonBuilder().startObject()
.field("_id", "1").startObject("long_field").field("foo", "bar")
docMapper.parse("person", "1", XContentFactory.jsonBuilder().startObject()
.startObject("long_field").field("foo", "bar")
.endObject().bytes()).rootDoc();
fail();
} catch (MapperParsingException ex) {
@ -163,8 +163,8 @@ public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
}
try {
docMapper.parse(XContentFactory.jsonBuilder().startObject()
.field("_id", "1").startObject("short_field").field("foo", "bar")
docMapper.parse("person", "1", XContentFactory.jsonBuilder().startObject()
.startObject("short_field").field("foo", "bar")
.endObject().bytes()).rootDoc();
fail();
} catch (MapperParsingException ex) {

View File

@ -46,7 +46,7 @@ public class GenericStoreDynamicTemplateTests extends ElasticsearchSingleNodeTes
client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping).get();
DocumentMapper docMapper = index.mapperService().documentMapper("person");
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/genericstore/test-data.json");
ParsedDocument parsedDoc = docMapper.parse(new BytesArray(json));
ParsedDocument parsedDoc = docMapper.parse("person", "1", new BytesArray(json));
client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get();
Document doc = parsedDoc.rootDoc();

View File

@ -1,5 +1,4 @@
{
"_id":"1",
"name":"some name",
"age":1
}

View File

@ -47,7 +47,7 @@ public class PathMatchDynamicTemplateTests extends ElasticsearchSingleNodeTest {
client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping).get();
DocumentMapper docMapper = index.mapperService().documentMapper("person");
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-data.json");
ParsedDocument parsedDoc = docMapper.parse(new BytesArray(json));
ParsedDocument parsedDoc = docMapper.parse("person", "1", new BytesArray(json));
client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get();
Document doc = parsedDoc.rootDoc();

View File

@ -1,5 +1,4 @@
{
"_id":"1",
"name":"top_level",
"obj1":{
"name":"obj1_level",

View File

@ -51,8 +51,8 @@ public class SimpleDynamicTemplatesTests extends ElasticsearchSingleNodeTest {
client().admin().indices().preparePutMapping("test").setType("person").setSource(builder.string()).get();
DocumentMapper docMapper = index.mapperService().documentMapper("person");
builder = JsonXContent.contentBuilder();
builder.startObject().field("_id", "1").field("s", "hello").field("l", 1).endObject();
ParsedDocument parsedDoc = docMapper.parse(builder.bytes());
builder.startObject().field("s", "hello").field("l", 1).endObject();
ParsedDocument parsedDoc = docMapper.parse("person", "1", builder.bytes());
client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get();
DocumentFieldMappers mappers = docMapper.mappers();
@ -74,7 +74,7 @@ public class SimpleDynamicTemplatesTests extends ElasticsearchSingleNodeTest {
client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping).get();
DocumentMapper docMapper = index.mapperService().documentMapper("person");
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json");
ParsedDocument parsedDoc = docMapper.parse(new BytesArray(json));
ParsedDocument parsedDoc = docMapper.parse("person", "1", new BytesArray(json));
client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get();
Document doc = parsedDoc.rootDoc();
@ -131,7 +131,7 @@ public class SimpleDynamicTemplatesTests extends ElasticsearchSingleNodeTest {
client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping).get();
DocumentMapper docMapper = index.mapperService().documentMapper("person");
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json");
ParsedDocument parsedDoc = docMapper.parse(new BytesArray(json));
ParsedDocument parsedDoc = docMapper.parse("person", "1", new BytesArray(json));
client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get();
Document doc = parsedDoc.rootDoc();

View File

@ -1,5 +1,4 @@
{
"_id":"1",
"name":"some name",
"age":1,
"multi1":"multi 1",

View File

@ -70,11 +70,6 @@ public class ExternalRootMapper implements RootMapper {
context.doc().add(new StringField(FIELD_NAME, FIELD_VALUE, Store.YES));
}
@Override
public boolean includeInObject() {
return false;
}
public static class Builder extends Mapper.Builder<Builder, ExternalRootMapper> {
protected Builder() {

View File

@ -29,6 +29,8 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.internal.IdFieldMapper;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
@ -39,7 +41,7 @@ import static org.hamcrest.Matchers.nullValue;
public class IdMappingTests extends ElasticsearchSingleNodeTest {
public void simpleIdTests() throws Exception {
public void testId() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
@ -57,18 +59,10 @@ public class IdMappingTests extends ElasticsearchSingleNodeTest {
.startObject()
.endObject()
.bytes());
fail();
fail("expect missing id");
} catch (MapperParsingException e) {
assertTrue(e.getMessage().contains("No id found"));
}
doc = docMapper.parse("type", null, XContentFactory.jsonBuilder()
.startObject()
.field("_id", 1)
.endObject()
.bytes());
assertThat(doc.rootDoc().get(UidFieldMapper.NAME), notNullValue());
assertThat(doc.rootDoc().get(IdFieldMapper.NAME), nullValue());
}
public void testIdIndexedBackcompat() throws Exception {
@ -85,15 +79,6 @@ public class IdMappingTests extends ElasticsearchSingleNodeTest {
assertThat(doc.rootDoc().get(UidFieldMapper.NAME), notNullValue());
assertThat(doc.rootDoc().get(IdFieldMapper.NAME), notNullValue());
doc = docMapper.parse("type", null, XContentFactory.jsonBuilder()
.startObject()
.field("_id", 1)
.endObject()
.bytes());
assertThat(doc.rootDoc().get(UidFieldMapper.NAME), notNullValue());
assertThat(doc.rootDoc().get(IdFieldMapper.NAME), notNullValue());
}
public void testIdPathBackcompat() throws Exception {
@ -115,4 +100,19 @@ public class IdMappingTests extends ElasticsearchSingleNodeTest {
assertThat(serialized_id_mapping, equalTo(expected_id_mapping));
}
public void testIncludeInObjectBackcompat() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
Settings settings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
DocumentMapper docMapper = createIndex("test", settings).mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse(SourceToParse.source(XContentFactory.jsonBuilder()
.startObject()
.field("_id", "1")
.endObject()
.bytes()).type("type"));
// _id is not indexed so we need to check _uid
assertEquals(Uid.createUid("type", "1"), doc.rootDoc().get(UidFieldMapper.NAME));
}
}

View File

@ -40,9 +40,8 @@ public class IndexTypeMapperTests extends ElasticsearchSingleNodeTest {
.startObject("_index").field("enabled", true).endObject()
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
IndexFieldMapper indexMapper = docMapper.rootMapper(IndexFieldMapper.class);
IndexFieldMapper indexMapper = docMapper.indexMapper();
assertThat(indexMapper.enabled(), equalTo(true));
assertThat(docMapper.mappers().getMapper("_index"), instanceOf(IndexFieldMapper.class));
ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -69,7 +69,7 @@ public class MultiFieldTests extends ElasticsearchSingleNodeTest {
private void testMultiField(String mapping) throws Exception {
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
Document doc = docMapper.parse(json).rootDoc();
Document doc = docMapper.parse("person", "1", json).rootDoc();
IndexableField f = doc.getField("name");
assertThat(f.name(), equalTo("name"));
@ -157,7 +157,7 @@ public class MultiFieldTests extends ElasticsearchSingleNodeTest {
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
Document doc = docMapper.parse(json).rootDoc();
Document doc = docMapper.parse("person", "1", json).rootDoc();
IndexableField f = doc.getField("name");
assertThat(f.name(), equalTo("name"));
@ -184,7 +184,7 @@ public class MultiFieldTests extends ElasticsearchSingleNodeTest {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/test-multi-field-type-no-default-field.json");
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
Document doc = docMapper.parse(json).rootDoc();
Document doc = docMapper.parse("person", "1", json).rootDoc();
assertNull(doc.getField("name"));
IndexableField f = doc.getField("name.indexed");
@ -267,10 +267,9 @@ public class MultiFieldTests extends ElasticsearchSingleNodeTest {
assertThat(docMapper.mappers().getMapper("a.b").fieldType().tokenized(), equalTo(false));
BytesReference json = jsonBuilder().startObject()
.field("_id", "1")
.field("a", "-1,-1")
.endObject().bytes();
Document doc = docMapper.parse(json).rootDoc();
Document doc = docMapper.parse("type", "1", json).rootDoc();
IndexableField f = doc.getField("a");
assertThat(f, notNullValue());
@ -299,10 +298,9 @@ public class MultiFieldTests extends ElasticsearchSingleNodeTest {
assertThat(docMapper.mappers().getMapper("b.a").fieldType().tokenized(), equalTo(false));
json = jsonBuilder().startObject()
.field("_id", "1")
.field("b", "-1,-1")
.endObject().bytes();
doc = docMapper.parse(json).rootDoc();
doc = docMapper.parse("type", "1", json).rootDoc();
f = doc.getField("b");
assertThat(f, notNullValue());
@ -319,10 +317,9 @@ public class MultiFieldTests extends ElasticsearchSingleNodeTest {
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
json = jsonBuilder().startObject()
.field("_id", "1")
.startArray("b").startArray().value(-1).value(-1).endArray().startArray().value(-2).value(-2).endArray().endArray()
.endObject().bytes();
doc = docMapper.parse(json).rootDoc();
doc = docMapper.parse("type", "1", json).rootDoc();
f = doc.getFields("b")[0];
assertThat(f, notNullValue());
@ -367,10 +364,9 @@ public class MultiFieldTests extends ElasticsearchSingleNodeTest {
assertThat(docMapper.mappers().getMapper("a.b").fieldType().tokenized(), equalTo(true));
BytesReference json = jsonBuilder().startObject()
.field("_id", "1")
.field("a", "complete me")
.endObject().bytes();
Document doc = docMapper.parse(json).rootDoc();
Document doc = docMapper.parse("type", "1", json).rootDoc();
IndexableField f = doc.getField("a");
assertThat(f, notNullValue());
@ -399,10 +395,9 @@ public class MultiFieldTests extends ElasticsearchSingleNodeTest {
assertThat(docMapper.mappers().getMapper("b.a").fieldType().tokenized(), equalTo(false));
json = jsonBuilder().startObject()
.field("_id", "1")
.field("b", "complete me")
.endObject().bytes();
doc = docMapper.parse(json).rootDoc();
doc = docMapper.parse("type", "1", json).rootDoc();
f = doc.getField("b");
assertThat(f, notNullValue());

View File

@ -23,6 +23,7 @@ import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.IndexableField;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.MergeResult;
@ -51,14 +52,13 @@ public class JavaMultiFieldMergeTests extends ElasticsearchSingleNodeTest {
assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name").fieldType().indexOptions());
assertThat(docMapper.mappers().getMapper("name.indexed"), nullValue());
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-data.json"));
Document doc = docMapper.parse(json).rootDoc();
BytesReference json = XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject().bytes();
Document doc = docMapper.parse("person", "1", json).rootDoc();
IndexableField f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
assertThat(f, nullValue());
mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping2.json");
DocumentMapper docMapper2 = parser.parse(mapping);
@ -75,8 +75,7 @@ public class JavaMultiFieldMergeTests extends ElasticsearchSingleNodeTest {
assertThat(docMapper.mappers().getMapper("name.not_indexed2"), nullValue());
assertThat(docMapper.mappers().getMapper("name.not_indexed3"), nullValue());
json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-data.json"));
doc = docMapper.parse(json).rootDoc();
doc = docMapper.parse("person", "1", json).rootDoc();
f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
@ -98,11 +97,9 @@ public class JavaMultiFieldMergeTests extends ElasticsearchSingleNodeTest {
assertThat(docMapper.mappers().getMapper("name.not_indexed2"), notNullValue());
assertThat(docMapper.mappers().getMapper("name.not_indexed3"), nullValue());
mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping4.json");
DocumentMapper docMapper4 = parser.parse(mapping);
mergeResult = docMapper.merge(docMapper4.mapping(), true);
assertThat(Arrays.toString(mergeResult.buildConflicts()), mergeResult.hasConflicts(), equalTo(false));
@ -127,8 +124,8 @@ public class JavaMultiFieldMergeTests extends ElasticsearchSingleNodeTest {
assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name").fieldType().indexOptions());
assertThat(docMapper.mappers().getMapper("name.indexed"), nullValue());
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-data.json"));
Document doc = docMapper.parse(json).rootDoc();
BytesReference json = XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject().bytes();
Document doc = docMapper.parse("person", "1", json).rootDoc();
IndexableField f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");
@ -151,8 +148,7 @@ public class JavaMultiFieldMergeTests extends ElasticsearchSingleNodeTest {
assertThat(docMapper.mappers().getMapper("name.not_indexed2"), nullValue());
assertThat(docMapper.mappers().getMapper("name.not_indexed3"), nullValue());
json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-data.json"));
doc = docMapper.parse(json).rootDoc();
doc = docMapper.parse("person", "1", json).rootDoc();
f = doc.getField("name");
assertThat(f, notNullValue());
f = doc.getField("name.indexed");

View File

@ -1,5 +1,4 @@
{
"_id":1,
"age":28,
"name":"some name",
"object1":{

View File

@ -18,6 +18,10 @@
*/
package org.elasticsearch.index.mapper.parent;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.ParsedDocument;
@ -29,13 +33,9 @@ import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
/**
*
*/
public class ParentMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void parentNotMapped() throws Exception {
public void testParentNotSet() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
@ -47,17 +47,17 @@ public class ParentMappingTests extends ElasticsearchSingleNodeTest {
.endObject()
.bytes()).type("type").id("1"));
// no _parent mapping, used as a simple field
assertThat(doc.parent(), nullValue());
assertThat(doc.rootDoc().get("_parent"), nullValue());
// no _parent mapping, dynamically used as a string field
assertNull(doc.parent());
assertNotNull(doc.rootDoc().get("_parent"));
}
@Test
public void parentSetInDocNotExternally() throws Exception {
public void testParentSetInDocBackcompat() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_parent").field("type", "p_type").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
Settings settings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
DocumentMapper docMapper = createIndex("test", settings).mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse(SourceToParse.source(XContentFactory.jsonBuilder()
.startObject()
@ -66,12 +66,11 @@ public class ParentMappingTests extends ElasticsearchSingleNodeTest {
.endObject()
.bytes()).type("type").id("1"));
assertThat(doc.parent(), equalTo("1122"));
assertThat(doc.rootDoc().get("_parent"), equalTo(Uid.createUid("p_type", "1122")));
assertEquals("1122", doc.parent());
assertEquals(Uid.createUid("p_type", "1122"), doc.rootDoc().get("_parent"));
}
@Test
public void parentNotSetInDocSetExternally() throws Exception {
public void testParentSet() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_parent").field("type", "p_type").endObject()
.endObject().endObject().string();
@ -83,23 +82,6 @@ public class ParentMappingTests extends ElasticsearchSingleNodeTest {
.endObject()
.bytes()).type("type").id("1").parent("1122"));
assertThat(doc.rootDoc().get("_parent"), equalTo(Uid.createUid("p_type", "1122")));
}
@Test
public void parentSetInDocSetExternally() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_parent").field("type", "p_type").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse(SourceToParse.source(XContentFactory.jsonBuilder()
.startObject()
.field("_parent", "1122")
.field("x_field", "x_value")
.endObject()
.bytes()).type("type").id("1").parent("1122"));
assertThat(doc.rootDoc().get("_parent"), equalTo(Uid.createUid("p_type", "1122")));
assertEquals(Uid.createUid("p_type", "1122"), doc.rootDoc().get("_parent"));
}
}

View File

@ -21,7 +21,10 @@ package org.elasticsearch.index.mapper.routing;
import org.apache.lucene.index.IndexOptions;
import org.elasticsearch.Version;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
@ -38,28 +41,23 @@ import java.util.Map;
import static org.hamcrest.Matchers.*;
/**
*
*/
public class RoutingTypeMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void simpleRoutingMapperTests() throws Exception {
public void testRoutingMapper() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse(SourceToParse.source(XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
.endObject()
.bytes()).type("type").id("1").routing("routing_value"));
.startObject()
.field("field", "value")
.endObject()
.bytes()).type("type").id("1").routing("routing_value"));
assertThat(doc.rootDoc().get("_routing"), equalTo("routing_value"));
assertThat(doc.rootDoc().get("field"), equalTo("value"));
}
@Test
public void testFieldTypeSettingsBackcompat() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_routing")
@ -73,7 +71,6 @@ public class RoutingTypeMapperTests extends ElasticsearchSingleNodeTest {
assertEquals(IndexOptions.NONE, docMapper.routingFieldMapper().fieldType().indexOptions());
}
@Test
public void testFieldTypeSettingsSerializationBackcompat() throws Exception {
String enabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_routing").field("store", "no").field("index", "no").endObject()
@ -93,4 +90,34 @@ public class RoutingTypeMapperTests extends ElasticsearchSingleNodeTest {
assertThat(routingConfiguration, hasKey("index"));
assertThat(routingConfiguration.get("index").toString(), is("no"));
}
public void testPathBackcompat() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_routing").field("path", "custom_routing").endObject()
.endObject().endObject().string();
Settings settings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
DocumentMapper docMapper = createIndex("test", settings).mapperService().documentMapperParser().parse(mapping);
XContentBuilder doc = XContentFactory.jsonBuilder().startObject().field("custom_routing", "routing_value").endObject();
MappingMetaData mappingMetaData = new MappingMetaData(docMapper);
IndexRequest request = new IndexRequest("test", "type", "1").source(doc);
request.process(MetaData.builder().build(), mappingMetaData, true, "test");
assertEquals(request.routing(), "routing_value");
}
public void testIncludeInObjectBackcompat() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
Settings settings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
DocumentMapper docMapper = createIndex("test", settings).mapperService().documentMapperParser().parse(mapping);
XContentBuilder doc = XContentFactory.jsonBuilder().startObject().field("_timestamp", 2000000).endObject();
MappingMetaData mappingMetaData = new MappingMetaData(docMapper);
IndexRequest request = new IndexRequest("test", "type", "1").source(doc);
request.process(MetaData.builder().build(), mappingMetaData, true, "test");
// _routing in a document never worked, so backcompat is ignoring the field
assertNull(request.routing());
assertNull(docMapper.parse("type", "1", doc.bytes()).rootDoc().get("_routing"));
}
}

View File

@ -56,7 +56,7 @@ public class SimpleMapperTests extends ElasticsearchSingleNodeTest {
assertThat(doc.get(docMapper.mappers().getMapper("name.first").names().indexName()), equalTo("shay"));
// System.out.println("Document: " + doc);
// System.out.println("Json: " + docMapper.sourceMapper().value(doc));
doc = docMapper.parse(json).rootDoc();
doc = docMapper.parse("person", "1", json).rootDoc();
// System.out.println("Document: " + doc);
// System.out.println("Json: " + docMapper.sourceMapper().value(doc));
}
@ -71,7 +71,7 @@ public class SimpleMapperTests extends ElasticsearchSingleNodeTest {
// reparse it
DocumentMapper builtDocMapper = parser.parse(builtMapping);
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
Document doc = builtDocMapper.parse(json).rootDoc();
Document doc = builtDocMapper.parse("person", "1", json).rootDoc();
assertThat(doc.get(docMapper.uidMapper().names().indexName()), equalTo(Uid.createUid("person", "1")));
assertThat(doc.get(docMapper.mappers().getMapper("name.first").names().indexName()), equalTo("shay"));
// System.out.println("Document: " + doc);
@ -86,7 +86,7 @@ public class SimpleMapperTests extends ElasticsearchSingleNodeTest {
assertThat((String) docMapper.meta().get("param1"), equalTo("value1"));
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
Document doc = docMapper.parse(json).rootDoc();
Document doc = docMapper.parse("person", "1", json).rootDoc();
assertThat(doc.get(docMapper.uidMapper().names().indexName()), equalTo(Uid.createUid("person", "1")));
assertThat(doc.get(docMapper.mappers().getMapper("name.first").names().indexName()), equalTo("shay"));
// System.out.println("Document: " + doc);

View File

@ -1,5 +1,4 @@
{
_id:"1",
name:{
first:"shay",
last:"banon"

View File

@ -37,7 +37,12 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.mapper.internal.TimestampFieldMapper;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
@ -53,7 +58,14 @@ import static org.elasticsearch.Version.V_1_5_0;
import static org.elasticsearch.Version.V_2_0_0;
import static org.elasticsearch.test.VersionUtils.randomVersion;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isIn;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.notNullValue;
/**
*/
@ -577,12 +589,17 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest {
.endObject().endObject().string();
MergeResult mergeResult = docMapper.merge(parser.parse(mapping).mapping(), true);
String[] expectedConflicts = {"mapper [_timestamp] has different index values", "mapper [_timestamp] has different store values", "Cannot update default in _timestamp value. Value is 1970-01-01 now encountering 1970-01-02", "Cannot update path in _timestamp value. Value is foo path in merged mapping is bar", "mapper [_timestamp] has different tokenize values"};
List<String> expectedConflicts = new ArrayList<>(Arrays.asList(
"mapper [_timestamp] has different index values",
"mapper [_timestamp] has different store values",
"Cannot update default in _timestamp value. Value is 1970-01-01 now encountering 1970-01-02",
"Cannot update path in _timestamp value. Value is foo path in merged mapping is bar",
"mapper [_timestamp] has different tokenize values"));
for (String conflict : mergeResult.buildConflicts()) {
assertThat(conflict, isIn(expectedConflicts));
assertTrue("found unexpected conflict [" + conflict + "]", expectedConflicts.remove(conflict));
}
assertThat(mergeResult.buildConflicts().length, equalTo(expectedConflicts.length));
assertTrue("missing conflicts: " + Arrays.toString(expectedConflicts.toArray()), expectedConflicts.isEmpty());
assertThat(docMapper.timestampFieldMapper().fieldDataType().getLoading(), equalTo(FieldMapper.Loading.LAZY));
assertTrue(docMapper.timestampFieldMapper().enabled());
assertThat(docMapper.timestampFieldMapper().fieldDataType().getFormat(indexSettings), equalTo("doc_values"));
@ -672,7 +689,7 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest {
docMapper.refreshSource();
docMapper = parser.parse(docMapper.mappingSource().string());
MergeResult mergeResult = docMapper.merge(parser.parse(mapping2).mapping(), true);
assertThat(mergeResult.buildConflicts().length, equalTo(conflict == null ? 0:1));
assertThat(mergeResult.buildConflicts().length, equalTo(conflict == null ? 0 : 1));
if (conflict != null) {
assertThat(mergeResult.buildConflicts()[0], containsString(conflict));
}
@ -732,4 +749,35 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest {
assertThat(docMapper.timestampFieldMapper().hasDocValues(), equalTo(docValues));
assertAcked(client().admin().indices().prepareDelete("test_doc_values"));
}
public void testPath() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_timestamp").field("enabled", true).field("path", "custom_timestamp").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
XContentBuilder doc = XContentFactory.jsonBuilder().startObject().field("custom_timestamp", 1).endObject();
MappingMetaData mappingMetaData = new MappingMetaData(docMapper);
IndexRequest request = new IndexRequest("test", "type", "1").source(doc);
request.process(MetaData.builder().build(), mappingMetaData, true, "test");
assertEquals(request.timestamp(), "1");
}
public void testIncludeInObjectBackcompat() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_timestamp").field("enabled", true).field("default", "1970").field("format", "YYYY").endObject()
.endObject().endObject().string();
Settings settings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
DocumentMapper docMapper = createIndex("test", settings).mapperService().documentMapperParser().parse(mapping);
XContentBuilder doc = XContentFactory.jsonBuilder().startObject().field("_timestamp", 2000000).endObject();
MappingMetaData mappingMetaData = new MappingMetaData(docMapper);
IndexRequest request = new IndexRequest("test", "type", "1").source(doc);
request.process(MetaData.builder().build(), mappingMetaData, true, "test");
// _timestamp in a document never worked, so backcompat is ignoring the field
assertEquals(MappingMetaData.Timestamp.parseStringTimestamp("1970", Joda.forPattern("YYYY")), request.timestamp());
assertNull(docMapper.parse("type", "1", doc.bytes()).rootDoc().get("_timestamp"));
}
}

View File

@ -22,7 +22,10 @@ package org.elasticsearch.index.mapper.ttl;
import org.apache.lucene.index.IndexOptions;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.common.settings.ImmutableSettings;
@ -291,6 +294,23 @@ public class TTLMappingTests extends ElasticsearchSingleNodeTest {
}
public void testIncludeInObjectBackcompat() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_ttl").field("enabled", true).endObject()
.endObject().endObject().string();
Settings settings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
DocumentMapper docMapper = createIndex("test", settings).mapperService().documentMapperParser().parse(mapping);
XContentBuilder doc = XContentFactory.jsonBuilder().startObject().field("_ttl", "2d").endObject();
MappingMetaData mappingMetaData = new MappingMetaData(docMapper);
IndexRequest request = new IndexRequest("test", "type", "1").source(doc);
request.process(MetaData.builder().build(), mappingMetaData, true, "test");
// _ttl in a document never worked, so backcompat is ignoring the field
assertEquals(-1, request.ttl());
assertNull(docMapper.parse("type", "1", doc.bytes()).rootDoc().get("_ttl"));
}
private org.elasticsearch.common.xcontent.XContentBuilder getMappingWithTtlEnabled() throws IOException {
return getMappingWithTtlEnabled(null);
}

View File

@ -1 +1 @@
{"type":{"_timestamp":{"enabled":false},"_index":{"enabled":false},"_size":{"enabled":false}}}
{"type":{"_index":{"enabled":false},"_size":{"enabled":false},"_timestamp":{"enabled":false}}}

View File

@ -58,7 +58,7 @@ public class IndexQueryParserFilterDateRangeFormatTests extends ElasticsearchSin
MapperService mapperService = indexService.mapperService();
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/query/mapping.json");
mapperService.merge("person", new CompressedString(mapping), true);
ParsedDocument doc = mapperService.documentMapper("person").parse(new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
ParsedDocument doc = mapperService.documentMapper("person").parse("person", "1", new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
assertNotNull(doc.dynamicMappingsUpdate());
client().admin().indices().preparePutMapping("test").setType("person").setSource(doc.dynamicMappingsUpdate().toString()).get();
queryParser = injector.getInstance(IndexQueryParserService.class);

View File

@ -59,7 +59,7 @@ public class IndexQueryParserFilterDateRangeTimezoneTests extends ElasticsearchS
MapperService mapperService = indexService.mapperService();
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/query/mapping.json");
mapperService.merge("person", new CompressedString(mapping), true);
ParsedDocument doc = mapperService.documentMapper("person").parse(new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
ParsedDocument doc = mapperService.documentMapper("person").parse("person", "1", new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
assertNotNull(doc.dynamicMappingsUpdate());
client().admin().indices().preparePutMapping("test").setType("person").setSource(doc.dynamicMappingsUpdate().toString()).get();
queryParser = injector.getInstance(IndexQueryParserService.class);

View File

@ -166,7 +166,7 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/query/mapping.json");
mapperService.merge("person", new CompressedString(mapping), true);
ParsedDocument doc = mapperService.documentMapper("person").parse(new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
ParsedDocument doc = mapperService.documentMapper("person").parse("person", "1", new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
assertNotNull(doc.dynamicMappingsUpdate());
client().admin().indices().preparePutMapping("test").setType("person").setSource(doc.dynamicMappingsUpdate().toString()).get();

View File

@ -1,6 +1,4 @@
{
_boost:3.7,
_id:"1",
name:{
first:"shay",
last:"banon"