Merge pull request #11962 from rjernst/pr/root-mappers-rename

Rename "root" mappers to "metadata" mappers
This commit is contained in:
Ryan Ernst 2015-07-01 09:13:14 -07:00
commit ac8896c10e
35 changed files with 334 additions and 311 deletions

View File

@ -41,7 +41,6 @@ import org.elasticsearch.common.util.concurrent.ReleasableLock;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.Mapping.SourceTransform;
import org.elasticsearch.index.mapper.internal.AllFieldMapper;
import org.elasticsearch.index.mapper.internal.FieldNamesFieldMapper;
@ -81,7 +80,7 @@ public class DocumentMapper implements ToXContent {
public static class Builder {
private Map<Class<? extends RootMapper>, RootMapper> rootMappers = new LinkedHashMap<>();
private Map<Class<? extends MetadataFieldMapper>, MetadataFieldMapper> rootMappers = new LinkedHashMap<>();
private List<SourceTransform> sourceTransforms = new ArrayList<>(1);
@ -128,9 +127,9 @@ public class DocumentMapper implements ToXContent {
return this;
}
public Builder put(RootMapper.Builder mapper) {
RootMapper rootMapper = (RootMapper) mapper.build(builderContext);
rootMappers.put(rootMapper.getClass(), rootMapper);
public Builder put(MetadataFieldMapper.Builder<?, ?> mapper) {
MetadataFieldMapper metadataMapper = mapper.build(builderContext);
rootMappers.put(metadataMapper.getClass(), metadataMapper);
return this;
}
@ -180,7 +179,7 @@ public class DocumentMapper implements ToXContent {
public DocumentMapper(MapperService mapperService, String index, @Nullable Settings indexSettings, DocumentMapperParser docMapperParser,
RootObjectMapper rootObjectMapper,
ImmutableMap<String, Object> meta,
Map<Class<? extends RootMapper>, RootMapper> rootMappers,
Map<Class<? extends MetadataFieldMapper>, MetadataFieldMapper> rootMappers,
List<SourceTransform> sourceTransforms,
ReentrantReadWriteLock mappingLock) {
this.mapperService = mapperService;
@ -189,7 +188,7 @@ public class DocumentMapper implements ToXContent {
this.mapping = new Mapping(
Version.indexCreated(indexSettings),
rootObjectMapper,
rootMappers.values().toArray(new RootMapper[rootMappers.values().size()]),
rootMappers.values().toArray(new MetadataFieldMapper[rootMappers.values().size()]),
sourceTransforms.toArray(new SourceTransform[sourceTransforms.size()]),
meta);
this.documentParser = new DocumentParser(index, indexSettings, docMapperParser, this, new ReleasableLock(mappingLock.readLock()));
@ -206,9 +205,9 @@ 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.rootMappers) {
if (rootMapper instanceof FieldMapper) {
newFieldMappers.add((FieldMapper) rootMapper);
for (MetadataFieldMapper metadataMapper : this.mapping.metadataMappers) {
if (metadataMapper instanceof FieldMapper) {
newFieldMappers.add((FieldMapper) metadataMapper);
}
}
MapperUtils.collect(this.mapping.root, newObjectMappers, newFieldMappers);
@ -258,7 +257,7 @@ public class DocumentMapper implements ToXContent {
}
@SuppressWarnings({"unchecked"})
public <T extends RootMapper> T rootMapper(Class<T> type) {
public <T extends MetadataFieldMapper> T rootMapper(Class<T> type) {
return mapping.rootMapper(type);
}

View File

@ -255,7 +255,7 @@ public class DocumentMapperParser extends AbstractIndexComponent {
if (typeParser != null) {
iterator.remove();
Map<String, Object> fieldNodeMap = (Map<String, Object>) fieldNode;
docBuilder.put(typeParser.parse(fieldName, fieldNodeMap, parserContext));
docBuilder.put((MetadataFieldMapper.Builder)typeParser.parse(fieldName, fieldNodeMap, parserContext));
fieldNodeMap.remove("type");
checkNoRemainingFields(fieldName, fieldNodeMap, parserContext.indexVersionCreated());
}

View File

@ -33,12 +33,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper.Builder;
import org.elasticsearch.index.mapper.core.DateFieldMapper.DateFieldType;
import org.elasticsearch.index.mapper.core.LongFieldMapper.LongFieldType;
import org.elasticsearch.index.mapper.core.StringFieldMapper.StringFieldType;
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
@ -117,8 +114,8 @@ class DocumentParser implements Closeable {
throw new MapperParsingException("Malformed content, after first object, either the type field or the actual properties should exist");
}
for (RootMapper rootMapper : mapping.rootMappers) {
rootMapper.preParse(context);
for (MetadataFieldMapper metadataMapper : mapping.metadataMappers) {
metadataMapper.preParse(context);
}
if (!emptyDoc) {
@ -132,8 +129,8 @@ class DocumentParser implements Closeable {
parser.nextToken();
}
for (RootMapper rootMapper : mapping.rootMappers) {
rootMapper.postParse(context);
for (MetadataFieldMapper metadataMapper : mapping.metadataMappers) {
metadataMapper.postParse(context);
}
} catch (Throwable e) {
// if its already a mapper parsing exception, no need to wrap it...

View File

@ -296,10 +296,8 @@ public class MapperService extends AbstractIndexComponent {
} else {
List<ObjectMapper> newObjectMappers = new ArrayList<>();
List<FieldMapper> newFieldMappers = new ArrayList<>();
for (RootMapper rootMapper : mapper.mapping().rootMappers) {
if (rootMapper instanceof FieldMapper) {
newFieldMappers.add((FieldMapper) rootMapper);
}
for (MetadataFieldMapper metadataMapper : mapper.mapping().metadataMappers) {
newFieldMappers.add(metadataMapper);
}
MapperUtils.collect(mapper.mapping().root, newObjectMappers, newFieldMappers);
checkNewMappersCompatibility(newObjectMappers, newFieldMappers, updateAllTypes);

View File

@ -56,24 +56,24 @@ public final class Mapping implements ToXContent {
final Version indexCreated;
final RootObjectMapper root;
final RootMapper[] rootMappers;
final ImmutableMap<Class<? extends RootMapper>, RootMapper> rootMappersMap;
final MetadataFieldMapper[] metadataMappers;
final ImmutableMap<Class<? extends MetadataFieldMapper>, MetadataFieldMapper> rootMappersMap;
final SourceTransform[] sourceTransforms;
volatile ImmutableMap<String, Object> meta;
public Mapping(Version indexCreated, RootObjectMapper rootObjectMapper, RootMapper[] rootMappers, SourceTransform[] sourceTransforms, ImmutableMap<String, Object> meta) {
public Mapping(Version indexCreated, RootObjectMapper rootObjectMapper, MetadataFieldMapper[] metadataMappers, SourceTransform[] sourceTransforms, ImmutableMap<String, Object> meta) {
this.indexCreated = indexCreated;
this.root = rootObjectMapper;
this.rootMappers = rootMappers;
ImmutableMap.Builder<Class<? extends RootMapper>, RootMapper> builder = ImmutableMap.builder();
for (RootMapper rootMapper : rootMappers) {
if (indexCreated.before(Version.V_2_0_0) && LEGACY_INCLUDE_IN_OBJECT.contains(rootMapper.name())) {
root.putMapper(rootMapper);
this.metadataMappers = metadataMappers;
ImmutableMap.Builder<Class<? extends MetadataFieldMapper>, MetadataFieldMapper> builder = ImmutableMap.builder();
for (MetadataFieldMapper metadataMapper : metadataMappers) {
if (indexCreated.before(Version.V_2_0_0) && LEGACY_INCLUDE_IN_OBJECT.contains(metadataMapper.name())) {
root.putMapper(metadataMapper);
}
builder.put(rootMapper.getClass(), rootMapper);
builder.put(metadataMapper.getClass(), metadataMapper);
}
// keep root mappers sorted for consistent serialization
Arrays.sort(rootMappers, new Comparator<Mapper>() {
Arrays.sort(metadataMappers, new Comparator<Mapper>() {
@Override
public int compare(Mapper o1, Mapper o2) {
return o1.name().compareTo(o2.name());
@ -93,24 +93,24 @@ public final class Mapping implements ToXContent {
* Generate a mapping update for the given root object mapper.
*/
public Mapping mappingUpdate(Mapper rootObjectMapper) {
return new Mapping(indexCreated, (RootObjectMapper) rootObjectMapper, rootMappers, sourceTransforms, meta);
return new Mapping(indexCreated, (RootObjectMapper) rootObjectMapper, metadataMappers, sourceTransforms, meta);
}
/** Get the root mapper with the given class. */
@SuppressWarnings("unchecked")
public <T extends RootMapper> T rootMapper(Class<T> clazz) {
public <T extends MetadataFieldMapper> T rootMapper(Class<T> clazz) {
return (T) rootMappersMap.get(clazz);
}
/** @see DocumentMapper#merge(Mapping, boolean) */
public void merge(Mapping mergeWith, MergeResult mergeResult) {
assert rootMappers.length == mergeWith.rootMappers.length;
assert metadataMappers.length == mergeWith.metadataMappers.length;
root.merge(mergeWith.root, mergeResult);
for (RootMapper rootMapper : rootMappers) {
RootMapper mergeWithRootMapper = mergeWith.rootMapper(rootMapper.getClass());
if (mergeWithRootMapper != null) {
rootMapper.merge(mergeWithRootMapper, mergeResult);
for (MetadataFieldMapper metadataMapper : metadataMappers) {
MetadataFieldMapper mergeWithMetadataMapper = mergeWith.rootMapper(metadataMapper.getClass());
if (mergeWithMetadataMapper != null) {
metadataMapper.merge(mergeWithMetadataMapper, mergeResult);
}
}
@ -141,7 +141,7 @@ public final class Mapping implements ToXContent {
if (meta != null && !meta.isEmpty()) {
builder.field("_meta", meta);
}
for (Mapper mapper : rootMappers) {
for (Mapper mapper : metadataMappers) {
mapper.toXContent(builder, params);
}
return builder;

View File

@ -0,0 +1,55 @@
/*
* 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.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.mapper.object.RootObjectMapper;
import java.io.IOException;
/**
* A mapper for a builtin field containing metadata about a document.
*/
public abstract class MetadataFieldMapper extends AbstractFieldMapper {
public abstract static class Builder<T extends Builder, Y extends MetadataFieldMapper> extends AbstractFieldMapper.Builder<T, Y> {
public Builder(String name, MappedFieldType fieldType) {
super(name, fieldType);
}
}
protected MetadataFieldMapper(MappedFieldType fieldType, Boolean docValues, @Nullable Settings fieldDataSettings, Settings indexSettings) {
super(fieldType, docValues, fieldDataSettings, indexSettings, MultiFields.empty(), null);
}
/**
* Called before {@link FieldMapper#parse(ParseContext)} on the {@link RootObjectMapper}.
*/
public abstract void preParse(ParseContext context) throws IOException;
/**
* Called after {@link FieldMapper#parse(ParseContext)} on the {@link RootObjectMapper}.
*/
public abstract void postParse(ParseContext context) throws IOException;
}

View File

@ -1,42 +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;
import org.elasticsearch.index.mapper.object.RootObjectMapper;
import java.io.IOException;
/**
* A mapper that exists only as a mapper within a root object.
*/
public interface RootMapper extends Mapper {
/**
* Called before {@link #parse(ParseContext)} on the {@link RootObjectMapper}.
*/
void preParse(ParseContext context) throws IOException;
/**
* Called after {@link #parse(ParseContext)} on the {@link RootObjectMapper}.
*/
void postParse(ParseContext context) throws IOException;
}

View File

@ -299,7 +299,7 @@ public class ByteFieldMapper extends NumberFieldMapper {
}
}
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
CustomByteNumericField field = new CustomByteNumericField(this, value, fieldType());
CustomByteNumericField field = new CustomByteNumericField(value, fieldType());
field.setBoost(boost);
fields.add(field);
}
@ -334,18 +334,15 @@ public class ByteFieldMapper extends NumberFieldMapper {
private final byte number;
private final NumberFieldMapper mapper;
public CustomByteNumericField(NumberFieldMapper mapper, byte number, MappedFieldType fieldType) {
super(mapper, number, fieldType);
this.mapper = mapper;
public CustomByteNumericField(byte number, MappedFieldType fieldType) {
super(number, fieldType);
this.number = number;
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) {
if (fieldType().indexOptions() != IndexOptions.NONE) {
return mapper.popCachedStream().setIntValue(number);
return getCachedStream().setIntValue(number);
}
return null;
}

View File

@ -502,7 +502,7 @@ public class DateFieldMapper extends NumberFieldMapper {
if (value != null) {
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
CustomLongNumericField field = new CustomLongNumericField(this, value, fieldType());
CustomLongNumericField field = new CustomLongNumericField(value, fieldType());
field.setBoost(boost);
fields.add(field);
}

View File

@ -297,7 +297,7 @@ public class DoubleFieldMapper extends NumberFieldMapper {
}
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
CustomDoubleNumericField field = new CustomDoubleNumericField(this, value, fieldType());
CustomDoubleNumericField field = new CustomDoubleNumericField(value, fieldType());
field.setBoost(boost);
fields.add(field);
}
@ -343,18 +343,15 @@ public class DoubleFieldMapper extends NumberFieldMapper {
private final double number;
private final NumberFieldMapper mapper;
public CustomDoubleNumericField(NumberFieldMapper mapper, double number, NumberFieldType fieldType) {
super(mapper, number, fieldType);
this.mapper = mapper;
public CustomDoubleNumericField(double number, NumberFieldType fieldType) {
super(number, fieldType);
this.number = number;
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) throws IOException {
if (fieldType().indexOptions() != IndexOptions.NONE) {
return mapper.popCachedStream().setDoubleValue(number);
return getCachedStream().setDoubleValue(number);
}
return null;
}

View File

@ -309,7 +309,7 @@ public class FloatFieldMapper extends NumberFieldMapper {
}
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
CustomFloatNumericField field = new CustomFloatNumericField(this, value, fieldType());
CustomFloatNumericField field = new CustomFloatNumericField(value, fieldType());
field.setBoost(boost);
fields.add(field);
}
@ -355,18 +355,15 @@ public class FloatFieldMapper extends NumberFieldMapper {
private final float number;
private final NumberFieldMapper mapper;
public CustomFloatNumericField(NumberFieldMapper mapper, float number, NumberFieldType fieldType) {
super(mapper, number, fieldType);
this.mapper = mapper;
public CustomFloatNumericField(float number, NumberFieldType fieldType) {
super(number, fieldType);
this.number = number;
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) throws IOException {
if (fieldType().indexOptions() != IndexOptions.NONE) {
return mapper.popCachedStream().setFloatValue(number);
return getCachedStream().setFloatValue(number);
}
return null;
}

View File

@ -313,7 +313,7 @@ public class IntegerFieldMapper extends NumberFieldMapper {
protected void addIntegerFields(ParseContext context, List<Field> fields, int value, float boost) {
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
CustomIntegerNumericField field = new CustomIntegerNumericField(this, value, fieldType());
CustomIntegerNumericField field = new CustomIntegerNumericField(value, fieldType());
field.setBoost(boost);
fields.add(field);
}
@ -349,18 +349,15 @@ public class IntegerFieldMapper extends NumberFieldMapper {
private final int number;
private final NumberFieldMapper mapper;
public CustomIntegerNumericField(NumberFieldMapper mapper, int number, MappedFieldType fieldType) {
super(mapper, number, fieldType);
this.mapper = mapper;
public CustomIntegerNumericField(int number, MappedFieldType fieldType) {
super(number, fieldType);
this.number = number;
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) throws IOException {
if (fieldType().indexOptions() != IndexOptions.NONE) {
return mapper.popCachedStream().setIntValue(number);
return getCachedStream().setIntValue(number);
}
return null;
}

View File

@ -298,7 +298,7 @@ public class LongFieldMapper extends NumberFieldMapper {
}
}
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
CustomLongNumericField field = new CustomLongNumericField(this, value, fieldType());
CustomLongNumericField field = new CustomLongNumericField(value, fieldType());
field.setBoost(boost);
fields.add(field);
}
@ -333,18 +333,15 @@ public class LongFieldMapper extends NumberFieldMapper {
private final long number;
private final NumberFieldMapper mapper;
public CustomLongNumericField(NumberFieldMapper mapper, long number, MappedFieldType fieldType) {
super(mapper, number, fieldType);
this.mapper = mapper;
public CustomLongNumericField(long number, MappedFieldType fieldType) {
super(number, fieldType);
this.number = number;
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) throws IOException {
if (fieldType().indexOptions() != IndexOptions.NONE) {
return mapper.popCachedStream().setLongValue(number);
return getCachedStream().setLongValue(number);
}
return null;
}

View File

@ -184,41 +184,6 @@ public abstract class NumberFieldMapper extends AbstractFieldMapper implements A
* otherwise for older indexes we must continue to write BINARY (for now)
*/
protected final boolean useSortedNumericDocValues;
private ThreadLocal<NumericTokenStream> tokenStream = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(fieldType().numericPrecisionStep());
}
};
private static ThreadLocal<NumericTokenStream> tokenStream4 = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(4);
}
};
private static ThreadLocal<NumericTokenStream> tokenStream8 = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(8);
}
};
private static ThreadLocal<NumericTokenStream> tokenStream16 = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(16);
}
};
private static ThreadLocal<NumericTokenStream> tokenStreamMax = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(Integer.MAX_VALUE);
}
};
protected NumberFieldMapper(MappedFieldType fieldType, Boolean docValues,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, @Nullable Settings fieldDataSettings, Settings indexSettings,
@ -335,32 +300,64 @@ public abstract class NumberFieldMapper extends AbstractFieldMapper implements A
}
}
protected NumericTokenStream popCachedStream() {
if (fieldType().numericPrecisionStep() == 4) {
return tokenStream4.get();
} else if (fieldType().numericPrecisionStep() == 8) {
return tokenStream8.get();
} else if (fieldType().numericPrecisionStep() == 16) {
return tokenStream16.get();
} else if (fieldType().numericPrecisionStep() == Integer.MAX_VALUE) {
return tokenStreamMax.get();
}
return tokenStream.get();
}
// used to we can use a numeric field in a document that is then parsed twice!
public abstract static class CustomNumericField extends Field {
protected final NumberFieldMapper mapper;
private ThreadLocal<NumericTokenStream> tokenStream = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(fieldType().numericPrecisionStep());
}
};
public CustomNumericField(NumberFieldMapper mapper, Number value, MappedFieldType fieldType) {
super(mapper.fieldType().names().indexName(), fieldType);
this.mapper = mapper;
private static ThreadLocal<NumericTokenStream> tokenStream4 = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(4);
}
};
private static ThreadLocal<NumericTokenStream> tokenStream8 = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(8);
}
};
private static ThreadLocal<NumericTokenStream> tokenStream16 = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(16);
}
};
private static ThreadLocal<NumericTokenStream> tokenStreamMax = new ThreadLocal<NumericTokenStream>() {
@Override
protected NumericTokenStream initialValue() {
return new NumericTokenStream(Integer.MAX_VALUE);
}
};
public CustomNumericField(Number value, MappedFieldType fieldType) {
super(fieldType.names().indexName(), fieldType);
if (value != null) {
this.fieldsData = value;
}
}
protected NumericTokenStream getCachedStream() {
if (fieldType().numericPrecisionStep() == 4) {
return tokenStream4.get();
} else if (fieldType().numericPrecisionStep() == 8) {
return tokenStream8.get();
} else if (fieldType().numericPrecisionStep() == 16) {
return tokenStream16.get();
} else if (fieldType().numericPrecisionStep() == Integer.MAX_VALUE) {
return tokenStreamMax.get();
}
return tokenStream.get();
}
@Override
public String stringValue() {
return null;

View File

@ -307,7 +307,7 @@ public class ShortFieldMapper extends NumberFieldMapper {
}
}
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
CustomShortNumericField field = new CustomShortNumericField(this, value, fieldType());
CustomShortNumericField field = new CustomShortNumericField(value, fieldType());
field.setBoost(boost);
fields.add(field);
}
@ -343,18 +343,15 @@ public class ShortFieldMapper extends NumberFieldMapper {
private final short number;
private final NumberFieldMapper mapper;
public CustomShortNumericField(NumberFieldMapper mapper, short number, NumberFieldType fieldType) {
super(mapper, number, fieldType);
this.mapper = mapper;
public CustomShortNumericField(short number, NumberFieldType fieldType) {
super(number, fieldType);
this.number = number;
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) throws IOException {
if (fieldType().indexOptions() != IndexOptions.NONE) {
return mapper.popCachedStream().setIntValue(number);
return getCachedStream().setIntValue(number);
}
return null;
}

View File

@ -40,7 +40,7 @@ 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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.similarity.SimilarityLookupService;
@ -57,7 +57,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class AllFieldMapper extends AbstractFieldMapper implements RootMapper {
public class AllFieldMapper extends MetadataFieldMapper {
public interface IncludeInAll extends Mapper {
@ -87,7 +87,7 @@ public class AllFieldMapper extends AbstractFieldMapper implements RootMapper {
}
}
public static class Builder extends AbstractFieldMapper.Builder<Builder, AllFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, AllFieldMapper> {
private EnabledAttributeMapper enabled = Defaults.ENABLED;

View File

@ -33,10 +33,8 @@ import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.MappedFieldType;
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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import java.io.IOException;
@ -55,7 +53,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
*
* Added in Elasticsearch 1.3.
*/
public class FieldNamesFieldMapper extends AbstractFieldMapper implements RootMapper {
public class FieldNamesFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_field_names";
@ -79,7 +77,7 @@ public class FieldNamesFieldMapper extends AbstractFieldMapper implements RootMa
}
}
public static class Builder extends AbstractFieldMapper.Builder<Builder, FieldNamesFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, FieldNamesFieldMapper> {
private boolean enabled = Defaults.ENABLED;
public Builder(MappedFieldType existing) {

View File

@ -47,7 +47,7 @@ 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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.query.QueryParseContext;
@ -63,7 +63,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class IdFieldMapper extends AbstractFieldMapper implements RootMapper {
public class IdFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_id";
@ -87,7 +87,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements RootMapper {
public static final String PATH = null;
}
public static class Builder extends AbstractFieldMapper.Builder<Builder, IdFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, IdFieldMapper> {
private String path = Defaults.PATH;

View File

@ -31,12 +31,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperBuilders;
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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import java.io.IOException;
@ -50,7 +49,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class IndexFieldMapper extends AbstractFieldMapper implements RootMapper {
public class IndexFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_index";
@ -75,7 +74,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements RootMapper
public static final EnabledAttributeMapper ENABLED_STATE = EnabledAttributeMapper.UNSET_DISABLED;
}
public static class Builder extends AbstractFieldMapper.Builder<Builder, IndexFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, IndexFieldMapper> {
private EnabledAttributeMapper enabledState = EnabledAttributeMapper.UNSET_DISABLED;

View File

@ -37,12 +37,11 @@ import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperBuilders;
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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.query.QueryParseContext;
@ -54,14 +53,13 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.common.settings.Settings.builder;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeMapValue;
/**
*
*/
public class ParentFieldMapper extends AbstractFieldMapper implements RootMapper {
public class ParentFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_parent";
public static final String CONTENT_TYPE = "_parent";
@ -84,7 +82,7 @@ public class ParentFieldMapper extends AbstractFieldMapper implements RootMapper
}
}
public static class Builder extends AbstractFieldMapper.Builder<Builder, ParentFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, ParentFieldMapper> {
protected String indexName;

View File

@ -23,7 +23,6 @@ import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexOptions;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
@ -35,7 +34,7 @@ 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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import java.io.IOException;
@ -49,7 +48,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class RoutingFieldMapper extends AbstractFieldMapper implements RootMapper {
public class RoutingFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_routing";
public static final String CONTENT_TYPE = "_routing";
@ -74,7 +73,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements RootMappe
public static final String PATH = null;
}
public static class Builder extends AbstractFieldMapper.Builder<Builder, RoutingFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, RoutingFieldMapper> {
private boolean required = Defaults.REQUIRED;

View File

@ -21,19 +21,20 @@ package org.elasticsearch.index.mapper.internal;
import org.apache.lucene.document.Field;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.analysis.NumericIntegerAnalyzer;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.MappedFieldType;
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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.mapper.core.IntegerFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
@ -45,7 +46,7 @@ import java.util.Map;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
import static org.elasticsearch.index.mapper.core.TypeParsers.parseStore;
public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
public class SizeFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_size";
public static final String CONTENT_TYPE = "_size";
@ -66,12 +67,12 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
}
}
public static class Builder extends NumberFieldMapper.Builder<Builder, IntegerFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, SizeFieldMapper> {
protected EnabledAttributeMapper enabledState = EnabledAttributeMapper.UNSET_DISABLED;
public Builder(MappedFieldType existing) {
super(Defaults.NAME, existing == null ? Defaults.SIZE_FIELD_TYPE : existing, Defaults.PRECISION_STEP_32_BIT);
super(Defaults.NAME, existing == null ? Defaults.SIZE_FIELD_TYPE : existing);
builder = this;
}
@ -85,16 +86,6 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
setupFieldType(context);
return new SizeFieldMapper(enabledState, fieldType, context.indexSettings());
}
@Override
protected NamedAnalyzer makeNumberAnalyzer(int precisionStep) {
return NumericIntegerAnalyzer.buildNamedAnalyzer(precisionStep);
}
@Override
protected int maxPrecisionStep() {
return 32;
}
}
public static class TypeParser implements Mapper.TypeParser {
@ -124,8 +115,9 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
}
public SizeFieldMapper(EnabledAttributeMapper enabled, MappedFieldType fieldType, Settings indexSettings) {
super(fieldType, false, Defaults.IGNORE_MALFORMED, Defaults.COERCE, null, indexSettings, MultiFields.empty(), null);
super(fieldType, false, null, indexSettings);
this.enabledState = enabled;
}
@Override
@ -147,6 +139,16 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
super.parse(context);
}
@Override
public MappedFieldType defaultFieldType() {
return Defaults.SIZE_FIELD_TYPE;
}
@Override
public FieldDataType defaultFieldDataType() {
return new FieldDataType("int");
}
@Override
public Mapper parse(ParseContext context) throws IOException {
// nothing to do here, we call the parent in postParse
@ -154,14 +156,14 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
}
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException {
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (!enabledState.enabled) {
return;
}
if (context.flyweight()) {
return;
}
fields.add(new CustomIntegerNumericField(this, context.source().length(), fieldType()));
fields.add(new IntegerFieldMapper.CustomIntegerNumericField(context.source().length(), fieldType()));
}
@Override

View File

@ -48,8 +48,8 @@ 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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import java.io.BufferedInputStream;
@ -66,7 +66,7 @@ import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeSt
/**
*
*/
public class SourceFieldMapper extends AbstractFieldMapper implements RootMapper {
public class SourceFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_source";
@ -92,7 +92,7 @@ public class SourceFieldMapper extends AbstractFieldMapper implements RootMapper
}
public static class Builder extends Mapper.Builder<Builder, SourceFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, SourceFieldMapper> {
private boolean enabled = Defaults.ENABLED;
@ -106,7 +106,7 @@ public class SourceFieldMapper extends AbstractFieldMapper implements RootMapper
private String[] excludes = null;
public Builder() {
super(Defaults.NAME);
super(Defaults.NAME, Defaults.FIELD_TYPE);
}
public Builder enabled(boolean enabled) {

View File

@ -31,14 +31,16 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.AlreadyExpiredException;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.analysis.NumericLongAnalyzer;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.MappedFieldType;
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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
import org.elasticsearch.search.internal.SearchContext;
@ -52,7 +54,7 @@ import java.util.Map;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeTimeValue;
public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
public class TTLFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_ttl";
public static final String CONTENT_TYPE = "_ttl";
@ -60,7 +62,7 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
public static class Defaults extends LongFieldMapper.Defaults {
public static final String NAME = TTLFieldMapper.CONTENT_TYPE;
public static final MappedFieldType TTL_FIELD_TYPE = new TTLFieldType();
public static final TTLFieldType TTL_FIELD_TYPE = new TTLFieldType();
static {
TTL_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS);
@ -77,13 +79,13 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
public static final long DEFAULT = -1;
}
public static class Builder extends NumberFieldMapper.Builder<Builder, TTLFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, TTLFieldMapper> {
private EnabledAttributeMapper enabledState = EnabledAttributeMapper.UNSET_DISABLED;
private long defaultTTL = Defaults.DEFAULT;
public Builder() {
super(Defaults.NAME, Defaults.TTL_FIELD_TYPE, Defaults.PRECISION_STEP_64_BIT);
super(Defaults.NAME, Defaults.TTL_FIELD_TYPE);
}
public Builder enabled(EnabledAttributeMapper enabled) {
@ -99,17 +101,7 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
@Override
public TTLFieldMapper build(BuilderContext context) {
setupFieldType(context);
return new TTLFieldMapper(fieldType, enabledState, defaultTTL, ignoreMalformed(context),coerce(context), fieldDataSettings, context.indexSettings());
}
@Override
protected NamedAnalyzer makeNumberAnalyzer(int precisionStep) {
return NumericLongAnalyzer.buildNamedAnalyzer(precisionStep);
}
@Override
protected int maxPrecisionStep() {
return 64;
return new TTLFieldMapper(fieldType, enabledState, defaultTTL, fieldDataSettings, context.indexSettings());
}
}
@ -137,7 +129,7 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
}
}
static final class TTLFieldType extends LongFieldType {
public static final class TTLFieldType extends LongFieldMapper.LongFieldType {
public TTLFieldType() {
}
@ -147,7 +139,7 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
}
@Override
public LongFieldType clone() {
public TTLFieldType clone() {
return new TTLFieldType(this);
}
@ -170,13 +162,12 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
private long defaultTTL;
public TTLFieldMapper(Settings indexSettings) {
this(Defaults.TTL_FIELD_TYPE.clone(), Defaults.ENABLED_STATE, Defaults.DEFAULT, Defaults.IGNORE_MALFORMED, Defaults.COERCE, null, indexSettings);
this(Defaults.TTL_FIELD_TYPE.clone(), Defaults.ENABLED_STATE, Defaults.DEFAULT, null, indexSettings);
}
protected TTLFieldMapper(MappedFieldType fieldType, EnabledAttributeMapper enabled, long defaultTTL, Explicit<Boolean> ignoreMalformed,
Explicit<Boolean> coerce, @Nullable Settings fieldDataSettings, Settings indexSettings) {
super(fieldType, false, ignoreMalformed, coerce,
fieldDataSettings, indexSettings, MultiFields.empty(), null);
protected TTLFieldMapper(MappedFieldType fieldType, EnabledAttributeMapper enabled, long defaultTTL,
@Nullable Settings fieldDataSettings, Settings indexSettings) {
super(fieldType, false, fieldDataSettings, indexSettings);
this.enabledState = enabled;
this.defaultTTL = defaultTTL;
}
@ -203,6 +194,16 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
super.parse(context);
}
@Override
public MappedFieldType defaultFieldType() {
return Defaults.TTL_FIELD_TYPE;
}
@Override
public FieldDataType defaultFieldDataType() {
return new FieldDataType("long");
}
@Override
public Mapper parse(ParseContext context) throws IOException, MapperParsingException {
if (context.sourceToParse().ttl() < 0) { // no ttl has been provided externally
@ -210,7 +211,7 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
if (context.parser().currentToken() == XContentParser.Token.VALUE_STRING) {
ttl = TimeValue.parseTimeValue(context.parser().text(), null, "ttl").millis();
} else {
ttl = context.parser().longValue(coerce.value());
ttl = context.parser().longValue(true);
}
if (ttl <= 0) {
throw new MapperParsingException("TTL value must be > 0. Illegal value provided [" + ttl + "]");
@ -221,7 +222,7 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
}
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException, AlreadyExpiredException {
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException, AlreadyExpiredException {
if (enabledState.enabled && !context.sourceToParse().flyweight()) {
long ttl = context.sourceToParse().ttl();
if (ttl <= 0 && defaultTTL > 0) { // no ttl provided so we use the default value
@ -237,7 +238,7 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
throw new AlreadyExpiredException(context.index(), context.type(), context.id(), timestamp, ttl, now);
}
// the expiration timestamp (timestamp + ttl) is set as field
fields.add(new CustomLongNumericField(this, expire, fieldType()));
fields.add(new LongFieldMapper.CustomLongNumericField(expire, fieldType()));
}
}
}
@ -261,6 +262,11 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
return builder;
}
@Override
protected String contentType() {
return NAME;
}
@Override
public void merge(Mapper mergeWith, MergeResult mergeResult) throws MergeMappingException {
TTLFieldMapper ttlMergeWith = (TTLFieldMapper) mergeWith;

View File

@ -33,13 +33,15 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.analysis.NumericDateAnalyzer;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.MappedFieldType;
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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
@ -53,7 +55,7 @@ import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBo
import static org.elasticsearch.index.mapper.core.TypeParsers.parseDateTimeFormatter;
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
public class TimestampFieldMapper extends DateFieldMapper implements RootMapper {
public class TimestampFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_timestamp";
public static final String CONTENT_TYPE = "_timestamp";
@ -65,7 +67,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
// TODO: this should be removed
public static final MappedFieldType PRE_20_FIELD_TYPE;
public static final FormatDateTimeFormatter DATE_TIME_FORMATTER = Joda.forPattern(DEFAULT_DATE_TIME_FORMAT);
public static final DateFieldType FIELD_TYPE = new TimestampFieldType();
public static final TimestampFieldType FIELD_TYPE = new TimestampFieldType();
static {
FIELD_TYPE.setStored(true);
@ -86,7 +88,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
public static final String DEFAULT_TIMESTAMP = "now";
}
public static class Builder extends NumberFieldMapper.Builder<Builder, TimestampFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, TimestampFieldMapper> {
private EnabledAttributeMapper enabledState = EnabledAttributeMapper.UNSET_DISABLED;
private String path = Defaults.PATH;
@ -95,15 +97,15 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
private Boolean ignoreMissing = null;
public Builder(MappedFieldType existing) {
super(Defaults.NAME, existing == null ? Defaults.FIELD_TYPE : existing, Defaults.PRECISION_STEP_64_BIT);
super(Defaults.NAME, existing == null ? Defaults.FIELD_TYPE : existing);
if (existing != null) {
// if there is an existing type, always use that store value (only matters for < 2.0)
explicitStore = true;
}
}
DateFieldType fieldType() {
return (DateFieldType)fieldType;
DateFieldMapper.DateFieldType fieldType() {
return (DateFieldMapper.DateFieldType)fieldType;
}
public Builder enabled(EnabledAttributeMapper enabledState) {
@ -144,18 +146,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
}
setupFieldType(context);
return new TimestampFieldMapper(fieldType, docValues, enabledState, path, defaultTimestamp,
ignoreMissing,
ignoreMalformed(context), coerce(context), fieldDataSettings, context.indexSettings());
}
@Override
protected NamedAnalyzer makeNumberAnalyzer(int precisionStep) {
return NumericDateAnalyzer.buildNamedAnalyzer(fieldType().dateTimeFormatter(), precisionStep);
}
@Override
protected int maxPrecisionStep() {
return 64;
ignoreMissing, fieldDataSettings, context.indexSettings());
}
}
@ -214,7 +205,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
}
}
static final class TimestampFieldType extends DateFieldType {
public static final class TimestampFieldType extends DateFieldMapper.DateFieldType {
public TimestampFieldType() {}
@ -223,7 +214,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
}
@Override
public DateFieldType clone() {
public TimestampFieldType clone() {
return new TimestampFieldType(this);
}
@ -251,17 +242,14 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
private final Boolean ignoreMissing;
public TimestampFieldMapper(Settings indexSettings, MappedFieldType existing) {
this(defaultFieldType(indexSettings, existing).clone(), null, Defaults.ENABLED, Defaults.PATH, Defaults.DEFAULT_TIMESTAMP,
null, Defaults.IGNORE_MALFORMED, Defaults.COERCE,
this(defaultFieldType(indexSettings, existing).clone(), null, Defaults.ENABLED, Defaults.PATH, Defaults.DEFAULT_TIMESTAMP, null,
existing == null ? null : (existing.fieldDataType() == null ? null : existing.fieldDataType().getSettings()),
indexSettings);
}
protected TimestampFieldMapper(MappedFieldType fieldType, Boolean docValues, EnabledAttributeMapper enabledState, String path,
String defaultTimestamp, Boolean ignoreMissing, Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce,
@Nullable Settings fieldDataSettings, Settings indexSettings) {
super(fieldType, docValues, ignoreMalformed, coerce, fieldDataSettings,
indexSettings, MultiFields.empty(), null);
String defaultTimestamp, Boolean ignoreMissing, @Nullable Settings fieldDataSettings, Settings indexSettings) {
super(fieldType, docValues, fieldDataSettings, indexSettings);
this.enabledState = enabledState;
this.path = path;
this.defaultTimestamp = defaultTimestamp;
@ -269,11 +257,21 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
this.ignoreMissing = ignoreMissing;
}
@Override
public TimestampFieldType fieldType() {
return (TimestampFieldType)super.fieldType();
}
@Override
public MappedFieldType defaultFieldType() {
return defaultFieldType;
}
@Override
public FieldDataType defaultFieldDataType() {
return new FieldDataType("long");
}
public boolean enabled() {
return this.enabledState.enabled;
}
@ -306,14 +304,14 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
}
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException {
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
if (enabledState.enabled) {
long timestamp = context.sourceToParse().timestamp();
if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored() && !fieldType().hasDocValues()) {
context.ignoredValue(fieldType().names().indexName(), String.valueOf(timestamp));
}
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
fields.add(new LongFieldMapper.CustomLongNumericField(this, timestamp, fieldType()));
fields.add(new LongFieldMapper.CustomLongNumericField(timestamp, fieldType()));
}
if (fieldType().hasDocValues()) {
fields.add(new NumericDocValuesField(fieldType().names().indexName(), timestamp));

View File

@ -41,7 +41,7 @@ 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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.query.QueryParseContext;
@ -55,7 +55,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class TypeFieldMapper extends AbstractFieldMapper implements RootMapper {
public class TypeFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_type";
@ -78,7 +78,7 @@ public class TypeFieldMapper extends AbstractFieldMapper implements RootMapper {
}
}
public static class Builder extends AbstractFieldMapper.Builder<Builder, TypeFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, TypeFieldMapper> {
public Builder(MappedFieldType existing) {
super(Defaults.NAME, existing == null ? Defaults.FIELD_TYPE : existing);

View File

@ -38,7 +38,7 @@ 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;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
@ -51,7 +51,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
/**
*
*/
public class UidFieldMapper extends AbstractFieldMapper implements RootMapper {
public class UidFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_uid";
@ -79,7 +79,7 @@ public class UidFieldMapper extends AbstractFieldMapper implements RootMapper {
}
}
public static class Builder extends AbstractFieldMapper.Builder<Builder, UidFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, UidFieldMapper> {
public Builder(MappedFieldType existing) {
super(Defaults.NAME, existing == null ? Defaults.FIELD_TYPE : existing);

View File

@ -32,10 +32,9 @@ 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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.RootMapper;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import java.io.IOException;
import java.util.Iterator;
@ -43,7 +42,7 @@ import java.util.List;
import java.util.Map;
/** Mapper for the _version field. */
public class VersionFieldMapper extends AbstractFieldMapper implements RootMapper {
public class VersionFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_version";
public static final String CONTENT_TYPE = "_version";
@ -60,10 +59,10 @@ public class VersionFieldMapper extends AbstractFieldMapper implements RootMappe
}
}
public static class Builder extends Mapper.Builder<Builder, VersionFieldMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, VersionFieldMapper> {
public Builder() {
super(Defaults.NAME);
super(Defaults.NAME, Defaults.FIELD_TYPE);
}
@Override

View File

@ -288,7 +288,7 @@ public class IpFieldMapper extends NumberFieldMapper {
final long value = ipToLong(ipAsString);
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
CustomLongNumericField field = new CustomLongNumericField(this, value, fieldType());
CustomLongNumericField field = new CustomLongNumericField(value, fieldType());
field.setBoost(fieldType().boost());
fields.add(field);
}

View File

@ -42,7 +42,7 @@ 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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.internal.AllFieldMapper;
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.index.settings.IndexSettings;
@ -523,7 +523,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll, Clonea
mappersToPut.add(mergeWithMapper);
MapperUtils.collect(mergeWithMapper, newObjectMappers, newFieldMappers);
}
} else if (mergeIntoMapper instanceof RootMapper == false) {
} else if (mergeIntoMapper instanceof MetadataFieldMapper == false) {
// root mappers can only exist here for backcompat, and are merged in Mapping
mergeIntoMapper.merge(mergeWithMapper, mergeResult);
}
@ -593,7 +593,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll, Clonea
int count = 0;
for (Mapper mapper : sortedMappers) {
if (!(mapper instanceof RootMapper)) {
if (!(mapper instanceof MetadataFieldMapper)) {
if (count++ == 0) {
builder.startObject("properties");
}

View File

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

View File

@ -19,30 +19,66 @@
package org.elasticsearch.index.mapper.externalvalues;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.StringField;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.MappedFieldType;
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.MetadataFieldMapper;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.core.BooleanFieldMapper;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class ExternalRootMapper implements RootMapper {
public class ExternalMetadataMapper extends MetadataFieldMapper {
static final String CONTENT_TYPE = "_external_root";
static final String FIELD_NAME = "_is_external";
static final String FIELD_VALUE = "true";
private static MappedFieldType FIELD_TYPE = new BooleanFieldMapper.BooleanFieldType();
static {
FIELD_TYPE.setNames(new MappedFieldType.Names(FIELD_NAME));
FIELD_TYPE.freeze();
}
protected ExternalMetadataMapper(Settings indexSettings) {
super(FIELD_TYPE, true, null, indexSettings);
}
@Override
public String name() {
return CONTENT_TYPE;
}
@Override
public MappedFieldType defaultFieldType() {
return FIELD_TYPE;
}
@Override
public FieldDataType defaultFieldDataType() {
return new FieldDataType("string");
}
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
// handled in post parse
}
@Override
public void merge(Mapper mergeWith, MergeResult mergeResult) throws MergeMappingException {
if (!(mergeWith instanceof ExternalRootMapper)) {
if (!(mergeWith instanceof ExternalMetadataMapper)) {
mergeResult.addConflict("Trying to merge " + mergeWith + " with " + this);
}
}
@ -57,6 +93,11 @@ public class ExternalRootMapper implements RootMapper {
return builder.startObject(CONTENT_TYPE).endObject();
}
@Override
protected String contentType() {
return CONTENT_TYPE;
}
@Override
public void preParse(ParseContext context) throws IOException {
}
@ -66,15 +107,15 @@ public class ExternalRootMapper implements RootMapper {
context.doc().add(new StringField(FIELD_NAME, FIELD_VALUE, Store.YES));
}
public static class Builder extends Mapper.Builder<Builder, ExternalRootMapper> {
public static class Builder extends MetadataFieldMapper.Builder<Builder, ExternalMetadataMapper> {
protected Builder() {
super(CONTENT_TYPE);
super(CONTENT_TYPE, FIELD_TYPE);
}
@Override
public ExternalRootMapper build(BuilderContext context) {
return new ExternalRootMapper();
public ExternalMetadataMapper build(BuilderContext context) {
return new ExternalMetadataMapper(context.indexSettings());
}
}

View File

@ -30,9 +30,6 @@ import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
/**
*/
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE)
public class ExternalValuesMapperIntegrationTests extends ElasticsearchIntegrationTest {
@Override
@ -47,7 +44,7 @@ public class ExternalValuesMapperIntegrationTests extends ElasticsearchIntegrati
public void testExternalValues() throws Exception {
prepareCreate("test-idx").addMapping("type",
XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject(ExternalRootMapper.CONTENT_TYPE)
.startObject(ExternalMetadataMapper.CONTENT_TYPE)
.endObject()
.startObject("properties")
.startObject("field").field("type", RegisterExternalTypes.EXTERNAL).endObject()

View File

@ -35,7 +35,7 @@ public class RegisterExternalTypes extends AbstractIndexComponent {
public RegisterExternalTypes(Index index, @IndexSettings Settings indexSettings, MapperService mapperService) {
super(index, indexSettings);
mapperService.documentMapperParser().putRootTypeParser(ExternalRootMapper.CONTENT_TYPE, new ExternalRootMapper.TypeParser());
mapperService.documentMapperParser().putRootTypeParser(ExternalMetadataMapper.CONTENT_TYPE, new ExternalMetadataMapper.TypeParser());
mapperService.documentMapperParser().putTypeParser(EXTERNAL, new ExternalMapper.TypeParser(EXTERNAL, "foo"));
mapperService.documentMapperParser().putTypeParser(EXTERNAL_BIS, new ExternalMapper.TypeParser(EXTERNAL_BIS, "bar"));
mapperService.documentMapperParser().putTypeParser(EXTERNAL_UPPER, new ExternalMapper.TypeParser(EXTERNAL_UPPER, "FOO BAR"));

View File

@ -36,14 +36,14 @@ public class SimpleExternalMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testExternalValues() throws Exception {
MapperService mapperService = createIndex("test").mapperService();
mapperService.documentMapperParser().putRootTypeParser(ExternalRootMapper.CONTENT_TYPE,
new ExternalRootMapper.TypeParser());
mapperService.documentMapperParser().putRootTypeParser(ExternalMetadataMapper.CONTENT_TYPE,
new ExternalMetadataMapper.TypeParser());
mapperService.documentMapperParser().putTypeParser(RegisterExternalTypes.EXTERNAL,
new ExternalMapper.TypeParser(RegisterExternalTypes.EXTERNAL, "foo"));
DocumentMapper documentMapper = mapperService.documentMapperParser().parse(
XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject(ExternalRootMapper.CONTENT_TYPE)
.startObject(ExternalMetadataMapper.CONTENT_TYPE)
.endObject()
.startObject("properties")
.startObject("field").field("type", "external").endObject()
@ -68,7 +68,7 @@ public class SimpleExternalMappingTests extends ElasticsearchSingleNodeTest {
assertThat(doc.rootDoc().getField("field.field"), notNullValue());
assertThat(doc.rootDoc().getField("field.field").stringValue(), is("foo"));
assertThat(doc.rootDoc().getField(ExternalRootMapper.FIELD_NAME).stringValue(), is(ExternalRootMapper.FIELD_VALUE));
assertThat(doc.rootDoc().getField(ExternalMetadataMapper.FIELD_NAME).stringValue(), is(ExternalMetadataMapper.FIELD_VALUE));
}