lucene 4: Converted most Mappers over to FieldType API
This commit is contained in:
parent
e75301b781
commit
549900a082
|
@ -5,7 +5,6 @@ import com.spatial4j.core.shape.Point;
|
|||
import com.spatial4j.core.shape.Rectangle;
|
||||
import com.spatial4j.core.shape.Shape;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.geo.GeoShapeConstants;
|
||||
|
@ -56,12 +55,13 @@ public abstract class SpatialStrategy {
|
|||
* @param shape Shape to convert ints its indexable format
|
||||
* @return Fieldable for indexing the Shape
|
||||
*/
|
||||
public Fieldable createField(Shape shape) {
|
||||
public Field createField(Shape shape) {
|
||||
int detailLevel = prefixTree.getLevelForDistance(
|
||||
calcDistanceFromErrPct(shape, distanceErrorPct, GeoShapeConstants.SPATIAL_CONTEXT));
|
||||
List<Node> nodes = prefixTree.getNodes(shape, detailLevel, true);
|
||||
NodeTokenStream tokenStream = nodeTokenStream.get();
|
||||
tokenStream.setNodes(nodes);
|
||||
// LUCENE 4 Upgrade: We should pass in the FieldType and use it here
|
||||
return new Field(fieldName.indexName(), tokenStream);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import java.io.Reader;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class UidField extends AbstractField {
|
||||
public class UidField extends Field {
|
||||
|
||||
public static class DocIdAndVersion {
|
||||
public final int docId;
|
||||
|
|
|
@ -24,7 +24,6 @@ import com.google.common.collect.Maps;
|
|||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.elasticsearch.common.Booleans;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -114,13 +113,13 @@ public class DocumentMapper implements ToXContent {
|
|||
* Called before a field is added to the document. Return <tt>true</tt> to include
|
||||
* it in the document.
|
||||
*/
|
||||
boolean beforeFieldAdded(FieldMapper fieldMapper, Fieldable fieldable, ParseContext parseContent);
|
||||
boolean beforeFieldAdded(FieldMapper fieldMapper, Field fieldable, ParseContext parseContent);
|
||||
}
|
||||
|
||||
public static class ParseListenerAdapter implements ParseListener {
|
||||
|
||||
@Override
|
||||
public boolean beforeFieldAdded(FieldMapper fieldMapper, Fieldable fieldable, Object parseContext) {
|
||||
public boolean beforeFieldAdded(FieldMapper fieldMapper, Field fieldable, Object parseContext) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper;
|
|||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Filter;
|
||||
|
@ -120,17 +119,21 @@ public interface FieldMapper<T> {
|
|||
|
||||
Names names();
|
||||
|
||||
Field.Index index();
|
||||
// LUCENE 4 UPGRADE Consider replacing these all with fieldType() and letting consumer pick and choose
|
||||
|
||||
boolean indexed();
|
||||
|
||||
boolean analyzed();
|
||||
|
||||
Field.Store store();
|
||||
|
||||
boolean stored();
|
||||
|
||||
Field.TermVector termVector();
|
||||
boolean storeTermVectors();
|
||||
|
||||
boolean storeTermVectorOffsets();
|
||||
|
||||
boolean storeTermVectorPositions();
|
||||
|
||||
boolean storeTermVectorPayloads();
|
||||
|
||||
float boost();
|
||||
|
||||
|
@ -156,19 +159,19 @@ public interface FieldMapper<T> {
|
|||
/**
|
||||
* Returns the value that will be used as a result for search. Can be only of specific types... .
|
||||
*/
|
||||
Object valueForSearch(Fieldable field);
|
||||
Object valueForSearch(Field field);
|
||||
|
||||
/**
|
||||
* Returns the actual value of the field.
|
||||
*/
|
||||
T value(Fieldable field);
|
||||
T value(Field field);
|
||||
|
||||
T valueFromString(String value);
|
||||
|
||||
/**
|
||||
* Returns the actual value of the field as string.
|
||||
*/
|
||||
String valueAsString(Fieldable field);
|
||||
String valueAsString(Field field);
|
||||
|
||||
/**
|
||||
* Returns the indexed value.
|
||||
|
|
|
@ -21,11 +21,11 @@ package org.elasticsearch.index.mapper.core;
|
|||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
|
@ -44,33 +44,60 @@ import java.io.IOException;
|
|||
public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
||||
|
||||
public static class Defaults {
|
||||
public static final Field.Index INDEX = Field.Index.ANALYZED;
|
||||
public static final Field.Store STORE = Field.Store.NO;
|
||||
public static final Field.TermVector TERM_VECTOR = Field.TermVector.NO;
|
||||
public static final FieldType FIELD_TYPE = new FieldType();
|
||||
|
||||
static {
|
||||
FIELD_TYPE.setIndexed(true);
|
||||
FIELD_TYPE.setTokenized(true);
|
||||
FIELD_TYPE.setStored(false);
|
||||
FIELD_TYPE.setStoreTermVectors(false);
|
||||
FIELD_TYPE.setOmitNorms(false);
|
||||
FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
|
||||
FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final float BOOST = 1.0f;
|
||||
public static final boolean OMIT_NORMS = false;
|
||||
public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
|
||||
}
|
||||
|
||||
public abstract static class OpenBuilder<T extends Builder, Y extends AbstractFieldMapper> extends AbstractFieldMapper.Builder<T, Y> {
|
||||
|
||||
protected OpenBuilder(String name) {
|
||||
super(name);
|
||||
protected OpenBuilder(String name, FieldType fieldType) {
|
||||
super(name, fieldType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T index(Field.Index index) {
|
||||
public T index(boolean index) {
|
||||
return super.index(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T store(Field.Store store) {
|
||||
public T store(boolean store) {
|
||||
return super.store(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T termVector(Field.TermVector termVector) {
|
||||
return super.termVector(termVector);
|
||||
protected T storeTermVectors(boolean termVectors) {
|
||||
return super.storeTermVectors(termVectors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T storeTermVectorOffsets(boolean termVectorOffsets) {
|
||||
return super.storeTermVectorOffsets(termVectorOffsets);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T storeTermVectorPositions(boolean termVectorPositions) {
|
||||
return super.storeTermVectorPositions(termVectorPositions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T storeTermVectorPayloads(boolean termVectorPayloads) {
|
||||
return super.storeTermVectorPayloads(termVectorPayloads);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T tokenized(boolean tokenized) {
|
||||
return super.tokenized(tokenized);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -106,35 +133,55 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
|
||||
public abstract static class Builder<T extends Builder, Y extends AbstractFieldMapper> extends Mapper.Builder<T, Y> {
|
||||
|
||||
protected Field.Index index = Defaults.INDEX;
|
||||
protected Field.Store store = Defaults.STORE;
|
||||
protected Field.TermVector termVector = Defaults.TERM_VECTOR;
|
||||
protected final FieldType fieldType;
|
||||
protected float boost = Defaults.BOOST;
|
||||
protected boolean omitNorms = Defaults.OMIT_NORMS;
|
||||
protected boolean omitNormsSet = false;
|
||||
protected String indexName;
|
||||
protected NamedAnalyzer indexAnalyzer;
|
||||
protected NamedAnalyzer searchAnalyzer;
|
||||
protected Boolean includeInAll;
|
||||
protected IndexOptions indexOptions = Defaults.INDEX_OPTIONS;
|
||||
protected boolean indexOptionsSet = false;
|
||||
|
||||
protected Builder(String name) {
|
||||
protected Builder(String name, FieldType fieldType) {
|
||||
super(name);
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
protected T index(Field.Index index) {
|
||||
this.index = index;
|
||||
protected T index(boolean index) {
|
||||
this.fieldType.setIndexed(index);
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected T store(Field.Store store) {
|
||||
this.store = store;
|
||||
protected T store(boolean store) {
|
||||
this.fieldType.setStored(store);
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected T termVector(Field.TermVector termVector) {
|
||||
this.termVector = termVector;
|
||||
protected T storeTermVectors(boolean termVectors) {
|
||||
this.fieldType.setStoreTermVectors(termVectors);
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected T storeTermVectorOffsets(boolean termVectorOffsets) {
|
||||
this.fieldType.setStoreTermVectors(termVectorOffsets);
|
||||
this.fieldType.setStoreTermVectorOffsets(termVectorOffsets);
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected T storeTermVectorPositions(boolean termVectorPositions) {
|
||||
this.fieldType.setStoreTermVectors(termVectorPositions);
|
||||
this.fieldType.setStoreTermVectorPositions(termVectorPositions);
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected T storeTermVectorPayloads(boolean termVectorPayloads) {
|
||||
this.fieldType.setStoreTermVectors(termVectorPayloads);
|
||||
this.fieldType.setStoreTermVectorPayloads(termVectorPayloads);
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected T tokenized(boolean tokenized) {
|
||||
this.fieldType.setTokenized(tokenized);
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
@ -144,13 +191,13 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
}
|
||||
|
||||
protected T omitNorms(boolean omitNorms) {
|
||||
this.omitNorms = omitNorms;
|
||||
this.fieldType.setOmitNorms(omitNorms);
|
||||
this.omitNormsSet = true;
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected T indexOptions(IndexOptions indexOptions) {
|
||||
this.indexOptions = indexOptions;
|
||||
this.fieldType.setIndexOptions(indexOptions);
|
||||
this.indexOptionsSet = true;
|
||||
return builder;
|
||||
}
|
||||
|
@ -191,40 +238,28 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
|
||||
protected final Names names;
|
||||
|
||||
protected final Field.Index index;
|
||||
|
||||
protected final Field.Store store;
|
||||
|
||||
protected final Field.TermVector termVector;
|
||||
|
||||
protected float boost;
|
||||
|
||||
protected final boolean omitNorms;
|
||||
|
||||
protected final FieldInfo.IndexOptions indexOptions;
|
||||
protected final FieldType fieldType;
|
||||
|
||||
protected final NamedAnalyzer indexAnalyzer;
|
||||
|
||||
protected final NamedAnalyzer searchAnalyzer;
|
||||
|
||||
protected AbstractFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||
protected AbstractFieldMapper(Names names, float boost, FieldType fieldType, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||
this.names = names;
|
||||
this.index = index;
|
||||
this.store = store;
|
||||
this.termVector = termVector;
|
||||
this.boost = boost;
|
||||
this.omitNorms = omitNorms;
|
||||
this.indexOptions = indexOptions;
|
||||
this.fieldType = fieldType;
|
||||
this.fieldType.freeze();
|
||||
|
||||
// automatically set to keyword analyzer if its indexed and not analyzed
|
||||
if (indexAnalyzer == null && !index.isAnalyzed() && index.isIndexed()) {
|
||||
if (indexAnalyzer == null && !this.fieldType.tokenized() && this.fieldType.indexed()) {
|
||||
this.indexAnalyzer = Lucene.KEYWORD_ANALYZER;
|
||||
} else {
|
||||
this.indexAnalyzer = indexAnalyzer;
|
||||
}
|
||||
// automatically set to keyword analyzer if its indexed and not analyzed
|
||||
if (searchAnalyzer == null && !index.isAnalyzed() && index.isIndexed()) {
|
||||
if (searchAnalyzer == null && !this.fieldType.tokenized() && this.fieldType.indexed()) {
|
||||
this.searchAnalyzer = Lucene.KEYWORD_ANALYZER;
|
||||
} else {
|
||||
this.searchAnalyzer = searchAnalyzer;
|
||||
|
@ -241,34 +276,39 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
return this.names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field.Index index() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field.Store store() {
|
||||
return this.store;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stored() {
|
||||
return store == Field.Store.YES;
|
||||
return fieldType.stored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean indexed() {
|
||||
return index != Field.Index.NO;
|
||||
return fieldType.indexed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean analyzed() {
|
||||
return index == Field.Index.ANALYZED;
|
||||
return fieldType.tokenized();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field.TermVector termVector() {
|
||||
return this.termVector;
|
||||
public boolean storeTermVectors() {
|
||||
return fieldType.storeTermVectors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storeTermVectorOffsets() {
|
||||
return fieldType.storeTermVectorOffsets();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storeTermVectorPositions() {
|
||||
return fieldType.storeTermVectorPositions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storeTermVectorPayloads() {
|
||||
return fieldType.storeTermVectorPayloads();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -278,12 +318,12 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
|
||||
@Override
|
||||
public boolean omitNorms() {
|
||||
return this.omitNorms;
|
||||
return fieldType.omitNorms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexOptions indexOptions() {
|
||||
return this.indexOptions;
|
||||
return fieldType.indexOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -304,12 +344,10 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
@Override
|
||||
public void parse(ParseContext context) throws IOException {
|
||||
try {
|
||||
Fieldable field = parseCreateField(context);
|
||||
Field field = parseCreateField(context);
|
||||
if (field == null) {
|
||||
return;
|
||||
}
|
||||
field.setOmitNorms(omitNorms);
|
||||
field.setIndexOptions(indexOptions);
|
||||
if (!customBoost()) {
|
||||
field.setBoost(boost);
|
||||
}
|
||||
|
@ -321,7 +359,7 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
}
|
||||
}
|
||||
|
||||
protected abstract Fieldable parseCreateField(ParseContext context) throws IOException;
|
||||
protected abstract Field parseCreateField(ParseContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* Derived classes can override it to specify that boost value is set by derived classes.
|
||||
|
@ -341,7 +379,7 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object valueForSearch(Fieldable field) {
|
||||
public Object valueForSearch(Field field) {
|
||||
return valueAsString(field);
|
||||
}
|
||||
|
||||
|
@ -396,17 +434,18 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
|
||||
@Override
|
||||
public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper, @Nullable QueryParseContext context) {
|
||||
// LUCENE 4 UPGRADE: Perhaps indexedValue() should return a BytesRef?
|
||||
return new TermRangeQuery(names.indexName(),
|
||||
lowerTerm == null ? null : indexedValue(lowerTerm),
|
||||
upperTerm == null ? null : indexedValue(upperTerm),
|
||||
lowerTerm == null ? null : new BytesRef(indexedValue(lowerTerm)),
|
||||
upperTerm == null ? null : new BytesRef(indexedValue(upperTerm)),
|
||||
includeLower, includeUpper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter rangeFilter(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper, @Nullable QueryParseContext context) {
|
||||
return new TermRangeFilter(names.indexName(),
|
||||
lowerTerm == null ? null : indexedValue(lowerTerm),
|
||||
upperTerm == null ? null : indexedValue(upperTerm),
|
||||
lowerTerm == null ? null : new BytesRef(indexedValue(lowerTerm)),
|
||||
upperTerm == null ? null : new BytesRef(indexedValue(upperTerm)),
|
||||
includeLower, includeUpper);
|
||||
}
|
||||
|
||||
|
@ -427,14 +466,26 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
return;
|
||||
}
|
||||
AbstractFieldMapper fieldMergeWith = (AbstractFieldMapper) mergeWith;
|
||||
if (!this.index.equals(fieldMergeWith.index)) {
|
||||
if (this.indexed() != fieldMergeWith.indexed() || this.analyzed() != fieldMergeWith.analyzed()) {
|
||||
mergeContext.addConflict("mapper [" + names.fullName() + "] has different index values");
|
||||
}
|
||||
if (!this.store.equals(fieldMergeWith.store)) {
|
||||
if (this.stored() != fieldMergeWith.stored()) {
|
||||
mergeContext.addConflict("mapper [" + names.fullName() + "] has different store values");
|
||||
}
|
||||
if (!this.termVector.equals(fieldMergeWith.termVector)) {
|
||||
mergeContext.addConflict("mapper [" + names.fullName() + "] has different term_vector values");
|
||||
if (this.analyzed() != fieldMergeWith.analyzed()) {
|
||||
mergeContext.addConflict("mapper [" + names.fullName() + "] has different tokenize values");
|
||||
}
|
||||
if (this.storeTermVectors() != fieldMergeWith.storeTermVectors()) {
|
||||
mergeContext.addConflict("mapper [" + names.fullName() + "] has different store_term_vector values");
|
||||
}
|
||||
if (this.storeTermVectorOffsets() != fieldMergeWith.storeTermVectorOffsets()) {
|
||||
mergeContext.addConflict("mapper [" + names.fullName() + "] has different store_term_vector_offsets values");
|
||||
}
|
||||
if (this.storeTermVectorPositions() != fieldMergeWith.storeTermVectorPositions()) {
|
||||
mergeContext.addConflict("mapper [" + names.fullName() + "] has different store_term_vector_positions values");
|
||||
}
|
||||
if (this.storeTermVectorPayloads() != fieldMergeWith.storeTermVectorPayloads()) {
|
||||
mergeContext.addConflict("mapper [" + names.fullName() + "] has different store_term_vector_payloads values");
|
||||
}
|
||||
if (this.indexAnalyzer == null) {
|
||||
if (fieldMergeWith.indexAnalyzer != null) {
|
||||
|
@ -486,6 +537,16 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
}
|
||||
}
|
||||
|
||||
protected static String indexTokenizeOptionToString(boolean indexed, boolean tokenized) {
|
||||
if (!indexed) {
|
||||
return "no";
|
||||
} else if (tokenized) {
|
||||
return "analyzed";
|
||||
} else {
|
||||
return "not_analyzed";
|
||||
}
|
||||
}
|
||||
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
builder.field("type", contentType());
|
||||
if (!names.name().equals(names.indexNameClean())) {
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
package org.elasticsearch.index.mapper.core;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.ElasticSearchParseException;
|
||||
import org.elasticsearch.common.Base64;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -50,7 +50,12 @@ public class BinaryFieldMapper extends AbstractFieldMapper<byte[]> {
|
|||
|
||||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final long COMPRESS_THRESHOLD = -1;
|
||||
public static final Field.Store STORE = Field.Store.YES;
|
||||
public static final FieldType BINARY_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
BINARY_FIELD_TYPE.setStored(false);
|
||||
BINARY_FIELD_TYPE.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends AbstractFieldMapper.Builder<Builder, BinaryFieldMapper> {
|
||||
|
@ -60,8 +65,7 @@ public class BinaryFieldMapper extends AbstractFieldMapper<byte[]> {
|
|||
private long compressThreshold = Defaults.COMPRESS_THRESHOLD;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
store = Defaults.STORE;
|
||||
super(name, new FieldType(Defaults.BINARY_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -82,7 +86,7 @@ public class BinaryFieldMapper extends AbstractFieldMapper<byte[]> {
|
|||
|
||||
@Override
|
||||
public BinaryFieldMapper build(BuilderContext context) {
|
||||
return new BinaryFieldMapper(buildNames(context), store, compress, compressThreshold);
|
||||
return new BinaryFieldMapper(buildNames(context), fieldType, compress, compressThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,22 +118,22 @@ public class BinaryFieldMapper extends AbstractFieldMapper<byte[]> {
|
|||
|
||||
private long compressThreshold;
|
||||
|
||||
protected BinaryFieldMapper(Names names, Field.Store store, Boolean compress, long compressThreshold) {
|
||||
super(names, Field.Index.NO, store, Field.TermVector.NO, 1.0f, true, IndexOptions.DOCS_ONLY, null, null);
|
||||
protected BinaryFieldMapper(Names names, FieldType fieldType, Boolean compress, long compressThreshold) {
|
||||
super(names, 1.0f, fieldType, null, null);
|
||||
this.compress = compress;
|
||||
this.compressThreshold = compressThreshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object valueForSearch(Fieldable field) {
|
||||
public Object valueForSearch(Field field) {
|
||||
return value(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public byte[] value(Field field) {
|
||||
BytesRef value = field.binaryValue();
|
||||
if (value == null) {
|
||||
return value;
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return CompressorFactory.uncompressIfNeeded(new BytesArray(value)).toBytes();
|
||||
|
@ -149,7 +153,7 @@ public class BinaryFieldMapper extends AbstractFieldMapper<byte[]> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -184,7 +188,7 @@ public class BinaryFieldMapper extends AbstractFieldMapper<byte[]> {
|
|||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return new Field(names.indexName(), value);
|
||||
return new Field(names.indexName(), value, fieldType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
package org.elasticsearch.index.mapper.core;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.elasticsearch.common.Booleans;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -49,7 +48,12 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
|
|||
public static final String CONTENT_TYPE = "boolean";
|
||||
|
||||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final boolean OMIT_NORMS = true;
|
||||
public static final FieldType BOOLEAN_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
BOOLEAN_FIELD_TYPE.setOmitNorms(true);
|
||||
BOOLEAN_FIELD_TYPE.freeze();
|
||||
}
|
||||
public static final Boolean NULL_VALUE = null;
|
||||
}
|
||||
|
||||
|
@ -58,8 +62,7 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
|
|||
private Boolean nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
this.omitNorms = Defaults.OMIT_NORMS;
|
||||
super(name, new FieldType(Defaults.BOOLEAN_FIELD_TYPE));
|
||||
this.builder = this;
|
||||
}
|
||||
|
||||
|
@ -69,18 +72,33 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Builder index(Field.Index index) {
|
||||
public Builder index(boolean index) {
|
||||
return super.index(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder store(Field.Store store) {
|
||||
public Builder store(boolean store) {
|
||||
return super.store(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder termVector(Field.TermVector termVector) {
|
||||
return super.termVector(termVector);
|
||||
protected Builder storeTermVectors(boolean termVectors) {
|
||||
return super.storeTermVectors(termVectors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder storeTermVectorOffsets(boolean termVectorOffsets) {
|
||||
return super.storeTermVectorOffsets(termVectorOffsets);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder storeTermVectorPositions(boolean termVectorPositions) {
|
||||
return super.storeTermVectorPositions(termVectorPositions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder storeTermVectorPayloads(boolean termVectorPayloads) {
|
||||
return super.storeTermVectorPayloads(termVectorPayloads);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,8 +114,7 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
|
|||
|
||||
@Override
|
||||
public BooleanFieldMapper build(BuilderContext context) {
|
||||
return new BooleanFieldMapper(buildNames(context), index, store,
|
||||
termVector, boost, omitNorms, indexOptions, nullValue);
|
||||
return new BooleanFieldMapper(buildNames(context), boost, fieldType, nullValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,9 +136,8 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
|
|||
|
||||
private Boolean nullValue;
|
||||
|
||||
protected BooleanFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions, Boolean nullValue) {
|
||||
super(names, index, store, termVector, boost, omitNorms, indexOptions, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER);
|
||||
protected BooleanFieldMapper(Names names, float boost, FieldType fieldType, Boolean nullValue) {
|
||||
super(names, boost, fieldType, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER);
|
||||
this.nullValue = nullValue;
|
||||
}
|
||||
|
||||
|
@ -131,7 +147,7 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean value(Fieldable field) {
|
||||
public Boolean value(Field field) {
|
||||
return field.stringValue().charAt(0) == 'T' ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
|
@ -141,7 +157,7 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return field.stringValue().charAt(0) == 'T' ? "true" : "false";
|
||||
}
|
||||
|
||||
|
@ -184,7 +200,7 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
|
|||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return new Field(names.indexName(), value, store, index, termVector);
|
||||
return new Field(names.indexName(), value, fieldType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -195,20 +211,30 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.BOOLEAN_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.BOOLEAN_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.BOOLEAN_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.BOOLEAN_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.BOOLEAN_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.BOOLEAN_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.BOOLEAN_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.BOOLEAN_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.BOOLEAN_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (nullValue != null) {
|
||||
builder.field("null_value", nullValue);
|
||||
|
|
|
@ -19,14 +19,15 @@
|
|||
|
||||
package org.elasticsearch.index.mapper.core;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.NumericRangeFilter;
|
||||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -56,6 +57,11 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
public static final String CONTENT_TYPE = "byte";
|
||||
|
||||
public static class Defaults extends NumberFieldMapper.Defaults {
|
||||
public static final FieldType BYTE_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
BYTE_FIELD_TYPE.freeze();
|
||||
}
|
||||
public static final Byte NULL_VALUE = null;
|
||||
}
|
||||
|
||||
|
@ -64,7 +70,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
protected Byte nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.BYTE_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -75,8 +81,9 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
|
||||
@Override
|
||||
public ByteFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
ByteFieldMapper fieldMapper = new ByteFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue, ignoreMalformed(context));
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue, ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
}
|
||||
|
@ -102,10 +109,9 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
|
||||
private String nullValueAsString;
|
||||
|
||||
protected ByteFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
protected ByteFieldMapper(Names names, int precisionStep, String fuzzyFactor, float boost, FieldType fieldType,
|
||||
Byte nullValue, Explicit<Boolean> ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions,
|
||||
super(names, precisionStep, fuzzyFactor, boost, fieldType,
|
||||
ignoreMalformed, new NamedAnalyzer("_byte/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_byte/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
|
@ -118,12 +124,12 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Byte value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public Byte value(Field field) {
|
||||
BytesRef value = field.binaryValue();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value[0];
|
||||
return value.bytes[value.offset];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -133,7 +139,9 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
|
||||
@Override
|
||||
public String indexedValue(String value) {
|
||||
return NumericUtils.intToPrefixCoded(Byte.parseByte(value));
|
||||
BytesRef bytesRef = new BytesRef();
|
||||
NumericUtils.intToPrefixCoded(Byte.parseByte(value), precisionStep(), bytesRef);
|
||||
return bytesRef.utf8ToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -216,7 +224,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
byte value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
@ -282,7 +290,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
}
|
||||
}
|
||||
}
|
||||
CustomByteNumericField field = new CustomByteNumericField(this, value);
|
||||
CustomByteNumericField field = new CustomByteNumericField(this, value, fieldType);
|
||||
field.setBoost(boost);
|
||||
return field;
|
||||
}
|
||||
|
@ -312,20 +320,30 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.BYTE_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.BYTE_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.BYTE_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.BYTE_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.BYTE_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.BYTE_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.BYTE_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.BYTE_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.BYTE_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (precisionStep != Defaults.PRECISION_STEP) {
|
||||
builder.field("precision_step", precisionStep);
|
||||
|
@ -347,15 +365,15 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
|
||||
private final NumberFieldMapper mapper;
|
||||
|
||||
public CustomByteNumericField(NumberFieldMapper mapper, byte number) {
|
||||
super(mapper, mapper.stored() ? new byte[]{number} : null);
|
||||
public CustomByteNumericField(NumberFieldMapper mapper, byte number, FieldType fieldType) {
|
||||
super(mapper, mapper.stored() ? new byte[]{number} : null, fieldType);
|
||||
this.mapper = mapper;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenStream tokenStreamValue() {
|
||||
if (isIndexed) {
|
||||
public TokenStream tokenStream(Analyzer analyzer) {
|
||||
if (fieldType().indexed()) {
|
||||
return mapper.popCachedStream().setIntValue(number);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
package org.elasticsearch.index.mapper.core;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.NumericRangeFilter;
|
||||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -63,6 +63,12 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
public static class Defaults extends NumberFieldMapper.Defaults {
|
||||
public static final FormatDateTimeFormatter DATE_TIME_FORMATTER = Joda.forPattern("dateOptionalTime");
|
||||
|
||||
public static final FieldType DATE_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
DATE_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final String NULL_VALUE = null;
|
||||
|
||||
public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
|
||||
|
@ -78,7 +84,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
protected FormatDateTimeFormatter dateTimeFormatter = Defaults.DATE_TIME_FORMATTER;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.DATE_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -103,8 +109,9 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
if (context.indexSettings() != null) {
|
||||
parseUpperInclusive = context.indexSettings().getAsBoolean("index.mapping.date.parse_upper_inclusive", Defaults.PARSE_UPPER_INCLUSIVE);
|
||||
}
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
DateFieldMapper fieldMapper = new DateFieldMapper(buildNames(context), dateTimeFormatter,
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue,
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
timeUnit, parseUpperInclusive, ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
|
@ -142,10 +149,9 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
protected final TimeUnit timeUnit;
|
||||
|
||||
protected DateFieldMapper(Names names, FormatDateTimeFormatter dateTimeFormatter, int precisionStep, String fuzzyFactor,
|
||||
Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
float boost, FieldType fieldType,
|
||||
String nullValue, TimeUnit timeUnit, boolean parseUpperInclusive, Explicit<Boolean> ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions,
|
||||
super(names, precisionStep, fuzzyFactor, boost, fieldType,
|
||||
ignoreMalformed, new NamedAnalyzer("_date/" + precisionStep,
|
||||
new NumericDateAnalyzer(precisionStep, dateTimeFormatter.parser())),
|
||||
new NamedAnalyzer("_date/max", new NumericDateAnalyzer(Integer.MAX_VALUE, dateTimeFormatter.parser())));
|
||||
|
@ -174,12 +180,12 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Long value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public Long value(Field field) {
|
||||
BytesRef value = field.binaryValue();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Numbers.bytesToLong(value);
|
||||
return Numbers.bytesToLong(value.bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -188,15 +194,15 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Dates should return as a string, delegates to {@link #valueAsString(org.apache.lucene.document.Fieldable)}.
|
||||
* Dates should return as a string.
|
||||
*/
|
||||
@Override
|
||||
public Object valueForSearch(Fieldable field) {
|
||||
public Object valueForSearch(Field field) {
|
||||
return valueAsString(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
Long value = value(field);
|
||||
if (value == null) {
|
||||
return null;
|
||||
|
@ -206,7 +212,9 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
@Override
|
||||
public String indexedValue(String value) {
|
||||
return NumericUtils.longToPrefixCoded(dateTimeFormatter.parser().parseMillis(value));
|
||||
BytesRef bytesRef = new BytesRef();
|
||||
NumericUtils.longToPrefixCoded(dateTimeFormatter.parser().parseMillis(value), precisionStep(), bytesRef);
|
||||
return bytesRef.utf8ToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -297,7 +305,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
String dateAsString = null;
|
||||
Long value = null;
|
||||
float boost = this.boost;
|
||||
|
@ -343,7 +351,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
if (value != null) {
|
||||
LongFieldMapper.CustomLongNumericField field = new LongFieldMapper.CustomLongNumericField(this, timeUnit.toMillis(value));
|
||||
LongFieldMapper.CustomLongNumericField field = new LongFieldMapper.CustomLongNumericField(this, timeUnit.toMillis(value), fieldType);
|
||||
field.setBoost(boost);
|
||||
return field;
|
||||
}
|
||||
|
@ -356,7 +364,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
value = parseStringValue(dateAsString);
|
||||
LongFieldMapper.CustomLongNumericField field = new LongFieldMapper.CustomLongNumericField(this, value);
|
||||
LongFieldMapper.CustomLongNumericField field = new LongFieldMapper.CustomLongNumericField(this, value, fieldType);
|
||||
field.setBoost(boost);
|
||||
return field;
|
||||
}
|
||||
|
@ -385,20 +393,30 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.DATE_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.DATE_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.DATE_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.DATE_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.DATE_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.DATE_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.DATE_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.DATE_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.DATE_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (precisionStep != Defaults.PRECISION_STEP) {
|
||||
builder.field("precision_step", precisionStep);
|
||||
|
|
|
@ -21,12 +21,12 @@ package org.elasticsearch.index.mapper.core;
|
|||
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.NumericRangeFilter;
|
||||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -56,6 +56,11 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
public static final String CONTENT_TYPE = "double";
|
||||
|
||||
public static class Defaults extends NumberFieldMapper.Defaults {
|
||||
public static final FieldType DOUBLE_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
DOUBLE_FIELD_TYPE.freeze();
|
||||
}
|
||||
public static final Double NULL_VALUE = null;
|
||||
}
|
||||
|
||||
|
@ -64,7 +69,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
protected Double nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.DOUBLE_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -75,8 +80,9 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
|
||||
@Override
|
||||
public DoubleFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
DoubleFieldMapper fieldMapper = new DoubleFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue,
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
|
@ -105,10 +111,9 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
private String nullValueAsString;
|
||||
|
||||
protected DoubleFieldMapper(Names names, int precisionStep, String fuzzyFactor,
|
||||
Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
float boost, FieldType fieldType,
|
||||
Double nullValue, Explicit<Boolean> ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions,
|
||||
super(names, precisionStep, fuzzyFactor, boost, fieldType,
|
||||
ignoreMalformed, new NamedAnalyzer("_double/" + precisionStep, new NumericDoubleAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_double/max", new NumericDoubleAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
|
@ -121,12 +126,12 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Double value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public Double value(Field field) {
|
||||
BytesRef value = field.binaryValue();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Numbers.bytesToDouble(value);
|
||||
return Numbers.bytesToDouble(value.bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,7 +141,10 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
|
||||
@Override
|
||||
public String indexedValue(String value) {
|
||||
return NumericUtils.doubleToPrefixCoded(Double.parseDouble(value));
|
||||
long longValue = NumericUtils.doubleToSortableLong(Double.parseDouble(value));
|
||||
BytesRef bytesRef = new BytesRef();
|
||||
NumericUtils.longToPrefixCoded(longValue, precisionStep(), bytesRef);
|
||||
return bytesRef.utf8ToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -218,7 +226,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
double value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
@ -285,7 +293,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
}
|
||||
}
|
||||
|
||||
CustomDoubleNumericField field = new CustomDoubleNumericField(this, value);
|
||||
CustomDoubleNumericField field = new CustomDoubleNumericField(this, value, fieldType);
|
||||
field.setBoost(boost);
|
||||
return field;
|
||||
}
|
||||
|
@ -315,20 +323,30 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.DOUBLE_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.DOUBLE_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.DOUBLE_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.DOUBLE_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.DOUBLE_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.DOUBLE_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.DOUBLE_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.DOUBLE_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.DOUBLE_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (precisionStep != Defaults.PRECISION_STEP) {
|
||||
builder.field("precision_step", precisionStep);
|
||||
|
@ -350,15 +368,15 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
|
||||
private final NumberFieldMapper mapper;
|
||||
|
||||
public CustomDoubleNumericField(NumberFieldMapper mapper, double number) {
|
||||
super(mapper, mapper.stored() ? Numbers.doubleToBytes(number) : null);
|
||||
public CustomDoubleNumericField(NumberFieldMapper mapper, double number, FieldType fieldType) {
|
||||
super(mapper, mapper.stored() ? Numbers.doubleToBytes(number) : null, fieldType);
|
||||
this.mapper = mapper;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenStream tokenStreamValue() {
|
||||
if (isIndexed) {
|
||||
if (fieldType().indexed()) {
|
||||
return mapper.popCachedStream().setDoubleValue(number);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -21,12 +21,13 @@ package org.elasticsearch.index.mapper.core;
|
|||
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.NumericRangeFilter;
|
||||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -57,6 +58,12 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
public static final String CONTENT_TYPE = "float";
|
||||
|
||||
public static class Defaults extends NumberFieldMapper.Defaults {
|
||||
public static final FieldType FLOAT_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
FLOAT_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final Float NULL_VALUE = null;
|
||||
}
|
||||
|
||||
|
@ -65,7 +72,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
protected Float nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.FLOAT_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -76,8 +83,9 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
|
||||
@Override
|
||||
public FloatFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
FloatFieldMapper fieldMapper = new FloatFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue,
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
|
@ -104,10 +112,9 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
|
||||
private String nullValueAsString;
|
||||
|
||||
protected FloatFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
protected FloatFieldMapper(Names names, int precisionStep, String fuzzyFactor, float boost, FieldType fieldType,
|
||||
Float nullValue, Explicit<Boolean> ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions,
|
||||
super(names, precisionStep, fuzzyFactor, boost, fieldType,
|
||||
ignoreMalformed, new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
|
@ -120,12 +127,12 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Float value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public Float value(Field field) {
|
||||
BytesRef value = field.binaryValue();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Numbers.bytesToFloat(value);
|
||||
return Numbers.bytesToFloat(value.bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,7 +142,10 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
|
||||
@Override
|
||||
public String indexedValue(String value) {
|
||||
return NumericUtils.floatToPrefixCoded(Float.parseFloat(value));
|
||||
int intValue = NumericUtils.floatToSortableInt(Float.parseFloat(value));
|
||||
BytesRef bytesRef = new BytesRef();
|
||||
NumericUtils.intToPrefixCoded(intValue, precisionStep(), bytesRef);
|
||||
return bytesRef.utf8ToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -213,7 +223,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
float value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
@ -280,7 +290,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
}
|
||||
}
|
||||
|
||||
CustomFloatNumericField field = new CustomFloatNumericField(this, value);
|
||||
CustomFloatNumericField field = new CustomFloatNumericField(this, value, fieldType);
|
||||
field.setBoost(boost);
|
||||
return field;
|
||||
}
|
||||
|
@ -311,20 +321,30 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.FLOAT_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.FLOAT_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.FLOAT_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.FLOAT_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.FLOAT_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.FLOAT_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.FLOAT_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.FLOAT_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.FLOAT_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (precisionStep != Defaults.PRECISION_STEP) {
|
||||
builder.field("precision_step", precisionStep);
|
||||
|
@ -346,15 +366,15 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
|
||||
private final NumberFieldMapper mapper;
|
||||
|
||||
public CustomFloatNumericField(NumberFieldMapper mapper, float number) {
|
||||
super(mapper, mapper.stored() ? Numbers.floatToBytes(number) : null);
|
||||
public CustomFloatNumericField(NumberFieldMapper mapper, float number, FieldType fieldType) {
|
||||
super(mapper, mapper.stored() ? Numbers.floatToBytes(number) : null, fieldType);
|
||||
this.mapper = mapper;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenStream tokenStreamValue() {
|
||||
if (isIndexed) {
|
||||
if (fieldType().indexed()) {
|
||||
return mapper.popCachedStream().setFloatValue(number);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -21,12 +21,12 @@ package org.elasticsearch.index.mapper.core;
|
|||
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.NumericRangeFilter;
|
||||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -57,6 +57,12 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
public static final String CONTENT_TYPE = "integer";
|
||||
|
||||
public static class Defaults extends NumberFieldMapper.Defaults {
|
||||
public static final FieldType INTEGER_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
INTEGER_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final Integer NULL_VALUE = null;
|
||||
}
|
||||
|
||||
|
@ -65,7 +71,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
protected Integer nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.INTEGER_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -76,8 +82,9 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
|
||||
@Override
|
||||
public IntegerFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
IntegerFieldMapper fieldMapper = new IntegerFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions,
|
||||
precisionStep, fuzzyFactor, boost, fieldType,
|
||||
nullValue, ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
|
@ -104,10 +111,10 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
|
||||
private String nullValueAsString;
|
||||
|
||||
protected IntegerFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
protected IntegerFieldMapper(Names names, int precisionStep, String fuzzyFactor,
|
||||
float boost, FieldType fieldType,
|
||||
Integer nullValue, Explicit<Boolean> ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions,
|
||||
super(names, precisionStep, fuzzyFactor, boost, fieldType,
|
||||
ignoreMalformed, new NamedAnalyzer("_int/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_int/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
|
@ -120,12 +127,12 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Integer value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public Integer value(Field field) {
|
||||
BytesRef value = field.binaryValue();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Numbers.bytesToInt(value);
|
||||
return Numbers.bytesToInt(value.bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,7 +142,9 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
|
||||
@Override
|
||||
public String indexedValue(String value) {
|
||||
return NumericUtils.intToPrefixCoded(Integer.parseInt(value));
|
||||
BytesRef bytesRef = new BytesRef();
|
||||
NumericUtils.intToPrefixCoded(Integer.parseInt(value), precisionStep(), bytesRef);
|
||||
return bytesRef.utf8ToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -218,7 +227,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
int value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
@ -285,7 +294,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
CustomIntegerNumericField field = new CustomIntegerNumericField(this, value);
|
||||
CustomIntegerNumericField field = new CustomIntegerNumericField(this, value, fieldType);
|
||||
field.setBoost(boost);
|
||||
return field;
|
||||
}
|
||||
|
@ -315,20 +324,30 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.INTEGER_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.INTEGER_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.INTEGER_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.INTEGER_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.INTEGER_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.INTEGER_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.INTEGER_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.INTEGER_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.INTEGER_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (precisionStep != Defaults.PRECISION_STEP) {
|
||||
builder.field("precision_step", precisionStep);
|
||||
|
@ -350,15 +369,15 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
|
||||
private final NumberFieldMapper mapper;
|
||||
|
||||
public CustomIntegerNumericField(NumberFieldMapper mapper, int number) {
|
||||
super(mapper, mapper.stored() ? Numbers.intToBytes(number) : null);
|
||||
public CustomIntegerNumericField(NumberFieldMapper mapper, int number, FieldType fieldType) {
|
||||
super(mapper, mapper.stored() ? Numbers.intToBytes(number) : null, fieldType);
|
||||
this.mapper = mapper;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenStream tokenStreamValue() {
|
||||
if (isIndexed) {
|
||||
if (fieldType().indexed()) {
|
||||
return mapper.popCachedStream().setIntValue(number);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -21,12 +21,13 @@ package org.elasticsearch.index.mapper.core;
|
|||
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.NumericRangeFilter;
|
||||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -57,6 +58,12 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
public static final String CONTENT_TYPE = "long";
|
||||
|
||||
public static class Defaults extends NumberFieldMapper.Defaults {
|
||||
public static final FieldType LONG_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
LONG_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final Long NULL_VALUE = null;
|
||||
}
|
||||
|
||||
|
@ -65,7 +72,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
protected Long nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.LONG_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -76,8 +83,9 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
@Override
|
||||
public LongFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
LongFieldMapper fieldMapper = new LongFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue,
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
|
@ -104,10 +112,10 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
private String nullValueAsString;
|
||||
|
||||
protected LongFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
protected LongFieldMapper(Names names, int precisionStep, String fuzzyFactor,
|
||||
float boost, FieldType fieldType,
|
||||
Long nullValue, Explicit<Boolean> ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions,
|
||||
super(names, precisionStep, fuzzyFactor, boost, fieldType,
|
||||
ignoreMalformed, new NamedAnalyzer("_long/" + precisionStep, new NumericLongAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_long/max", new NumericLongAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
|
@ -120,12 +128,12 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Long value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public Long value(Field field) {
|
||||
BytesRef value = field.binaryValue();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Numbers.bytesToLong(value);
|
||||
return Numbers.bytesToLong(value.bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,7 +143,9 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
@Override
|
||||
public String indexedValue(String value) {
|
||||
return NumericUtils.longToPrefixCoded(Long.parseLong(value));
|
||||
BytesRef bytesRef = new BytesRef();
|
||||
NumericUtils.longToPrefixCoded(Long.parseLong(value), precisionStep(), bytesRef);
|
||||
return bytesRef.utf8ToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -218,7 +228,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
long value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
@ -284,7 +294,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
}
|
||||
}
|
||||
CustomLongNumericField field = new CustomLongNumericField(this, value);
|
||||
CustomLongNumericField field = new CustomLongNumericField(this, value, fieldType);
|
||||
field.setBoost(boost);
|
||||
return field;
|
||||
}
|
||||
|
@ -314,20 +324,30 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.LONG_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.LONG_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.LONG_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.LONG_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.LONG_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.LONG_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.LONG_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.LONG_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.LONG_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (precisionStep != Defaults.PRECISION_STEP) {
|
||||
builder.field("precision_step", precisionStep);
|
||||
|
@ -349,15 +369,15 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
private final NumberFieldMapper mapper;
|
||||
|
||||
public CustomLongNumericField(NumberFieldMapper mapper, long number) {
|
||||
super(mapper, mapper.stored() ? Numbers.longToBytes(number) : null);
|
||||
public CustomLongNumericField(NumberFieldMapper mapper, long number, FieldType fieldType) {
|
||||
super(mapper, mapper.stored() ? Numbers.longToBytes(number) : null, fieldType);
|
||||
this.mapper = mapper;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenStream tokenStreamValue() {
|
||||
if (isIndexed) {
|
||||
if (fieldType().indexed()) {
|
||||
return mapper.popCachedStream().setLongValue(number);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -20,10 +20,8 @@
|
|||
package org.elasticsearch.index.mapper.core;
|
||||
|
||||
import org.apache.lucene.analysis.NumericTokenStream;
|
||||
import org.apache.lucene.document.AbstractField;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.Query;
|
||||
|
@ -48,9 +46,17 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
|
||||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final int PRECISION_STEP = NumericUtils.PRECISION_STEP_DEFAULT;
|
||||
public static final Field.Index INDEX = Field.Index.NOT_ANALYZED;
|
||||
public static final boolean OMIT_NORMS = true;
|
||||
public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY;
|
||||
|
||||
public static final FieldType NUMBER_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
NUMBER_FIELD_TYPE.setTokenized(false);
|
||||
NUMBER_FIELD_TYPE.setOmitNorms(true);
|
||||
NUMBER_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
NUMBER_FIELD_TYPE.setStoreTermVectors(false);
|
||||
NUMBER_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final String FUZZY_FACTOR = null;
|
||||
public static final Explicit<Boolean> IGNORE_MALFORMED = new Explicit<Boolean>(false, false);
|
||||
}
|
||||
|
@ -63,15 +69,12 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
|
||||
private Boolean ignoreMalformed;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
this.index = Defaults.INDEX;
|
||||
this.omitNorms = Defaults.OMIT_NORMS;
|
||||
this.indexOptions = Defaults.INDEX_OPTIONS;
|
||||
public Builder(String name, FieldType fieldType) {
|
||||
super(name, fieldType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T store(Field.Store store) {
|
||||
public T store(boolean store) {
|
||||
return super.store(store);
|
||||
}
|
||||
|
||||
|
@ -134,10 +137,10 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
};
|
||||
|
||||
protected NumberFieldMapper(Names names, int precisionStep, @Nullable String fuzzyFactor,
|
||||
Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
float boost, FieldType fieldType,
|
||||
Explicit<Boolean> ignoreMalformed, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||
super(names, index, store, Field.TermVector.NO, boost, boost != 1.0f || omitNorms, indexOptions, indexAnalyzer, searchAnalyzer);
|
||||
// LUCENE 4 UPGRADE: Since we can't do anything before the super call, we have to push the boost check down to subclasses
|
||||
super(names, boost, fieldType, indexAnalyzer, searchAnalyzer);
|
||||
if (precisionStep <= 0 || precisionStep >= maxPrecisionStep()) {
|
||||
this.precisionStep = Integer.MAX_VALUE;
|
||||
} else {
|
||||
|
@ -176,7 +179,7 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Field parseCreateField(ParseContext context) throws IOException {
|
||||
RuntimeException e;
|
||||
try {
|
||||
return innerParseCreateField(context);
|
||||
|
@ -193,7 +196,7 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
}
|
||||
}
|
||||
|
||||
protected abstract Fieldable innerParseCreateField(ParseContext context) throws IOException;
|
||||
protected abstract Field innerParseCreateField(ParseContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* Use the field query created here when matching on numbers.
|
||||
|
@ -242,12 +245,12 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
* Override the default behavior (to return the string, and return the actual Number instance).
|
||||
*/
|
||||
@Override
|
||||
public Object valueForSearch(Fieldable field) {
|
||||
public Object valueForSearch(Field field) {
|
||||
return value(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
Number num = value(field);
|
||||
return num == null ? null : num.toString();
|
||||
}
|
||||
|
@ -283,28 +286,13 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
}
|
||||
|
||||
// used to we can use a numeric field in a document that is then parsed twice!
|
||||
public abstract static class CustomNumericField extends AbstractField {
|
||||
public abstract static class CustomNumericField extends Field {
|
||||
|
||||
protected final NumberFieldMapper mapper;
|
||||
|
||||
public CustomNumericField(NumberFieldMapper mapper, byte[] value) {
|
||||
public CustomNumericField(NumberFieldMapper mapper, byte[] value, FieldType fieldType) {
|
||||
super(mapper.names().indexName(), value, fieldType);
|
||||
this.mapper = mapper;
|
||||
this.name = mapper.names().indexName();
|
||||
fieldsData = value;
|
||||
|
||||
isIndexed = mapper.indexed();
|
||||
isTokenized = mapper.indexed();
|
||||
indexOptions = FieldInfo.IndexOptions.DOCS_ONLY;
|
||||
omitNorms = mapper.omitNorms();
|
||||
|
||||
if (value != null) {
|
||||
isStored = true;
|
||||
isBinary = true;
|
||||
binaryLength = value.length;
|
||||
binaryOffset = 0;
|
||||
}
|
||||
|
||||
setStoreTermVector(Field.TermVector.NO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,12 +21,13 @@ package org.elasticsearch.index.mapper.core;
|
|||
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.NumericRangeFilter;
|
||||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -57,6 +58,11 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
public static final String CONTENT_TYPE = "short";
|
||||
|
||||
public static class Defaults extends NumberFieldMapper.Defaults {
|
||||
public static final FieldType SHORT_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
SHORT_FIELD_TYPE.freeze();
|
||||
}
|
||||
public static final Short NULL_VALUE = null;
|
||||
}
|
||||
|
||||
|
@ -65,7 +71,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
protected Short nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.SHORT_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -76,8 +82,9 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
|
||||
@Override
|
||||
public ShortFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
ShortFieldMapper fieldMapper = new ShortFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions, nullValue,
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
|
@ -104,10 +111,10 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
|
||||
private String nullValueAsString;
|
||||
|
||||
protected ShortFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
protected ShortFieldMapper(Names names, int precisionStep, String fuzzyFactor,
|
||||
float boost, FieldType fieldType,
|
||||
Short nullValue, Explicit<Boolean> ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, indexOptions,
|
||||
super(names, precisionStep, fuzzyFactor, boost, fieldType,
|
||||
ignoreMalformed, new NamedAnalyzer("_short/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_short/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
|
@ -120,12 +127,12 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Short value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public Short value(Field field) {
|
||||
BytesRef value = field.binaryValue();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Numbers.bytesToShort(value);
|
||||
return Numbers.bytesToShort(value.bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,7 +142,9 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
|
||||
@Override
|
||||
public String indexedValue(String value) {
|
||||
return NumericUtils.intToPrefixCoded(Short.parseShort(value));
|
||||
BytesRef bytesRef = new BytesRef();
|
||||
NumericUtils.intToPrefixCoded(Short.parseShort(value), precisionStep(), bytesRef);
|
||||
return bytesRef.utf8ToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -218,7 +227,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
short value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
@ -284,7 +293,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
}
|
||||
}
|
||||
}
|
||||
CustomShortNumericField field = new CustomShortNumericField(this, value);
|
||||
CustomShortNumericField field = new CustomShortNumericField(this, value, fieldType);
|
||||
field.setBoost(boost);
|
||||
return field;
|
||||
}
|
||||
|
@ -314,20 +323,30 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.SHORT_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.SHORT_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.SHORT_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.SHORT_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.SHORT_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.SHORT_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.SHORT_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.SHORT_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.SHORT_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (precisionStep != Defaults.PRECISION_STEP) {
|
||||
builder.field("precision_step", precisionStep);
|
||||
|
@ -349,15 +368,15 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
|
||||
private final NumberFieldMapper mapper;
|
||||
|
||||
public CustomShortNumericField(NumberFieldMapper mapper, short number) {
|
||||
super(mapper, mapper.stored() ? Numbers.shortToBytes(number) : null);
|
||||
public CustomShortNumericField(NumberFieldMapper mapper, short number, FieldType fieldType) {
|
||||
super(mapper, mapper.stored() ? Numbers.shortToBytes(number) : null, fieldType);
|
||||
this.mapper = mapper;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenStream tokenStreamValue() {
|
||||
if (isIndexed) {
|
||||
if (fieldType().indexed()) {
|
||||
return mapper.popCachedStream().setIntValue(number);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.index.mapper.core;
|
|||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -47,6 +47,12 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements Al
|
|||
public static final String CONTENT_TYPE = "string";
|
||||
|
||||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final FieldType STRING_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
STRING_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
// NOTE, when adding defaults here, make sure you add them in the builder
|
||||
public static final String NULL_VALUE = null;
|
||||
public static final int POSITION_OFFSET_GAP = 0;
|
||||
|
@ -64,7 +70,7 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements Al
|
|||
protected int ignoreAbove = Defaults.IGNORE_ABOVE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.STRING_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -113,16 +119,16 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements Al
|
|||
// if the field is not analyzed, then by default, we should omit norms and have docs only
|
||||
// index options, as probably what the user really wants
|
||||
// if they are set explicitly, we will use those values
|
||||
if (index == Field.Index.NOT_ANALYZED) {
|
||||
if (fieldType.indexed() && fieldType.tokenized()) {
|
||||
if (!omitNormsSet) {
|
||||
omitNorms = true;
|
||||
fieldType.setOmitNorms(true);
|
||||
}
|
||||
if (!indexOptionsSet) {
|
||||
indexOptions = IndexOptions.DOCS_ONLY;
|
||||
fieldType.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
}
|
||||
}
|
||||
StringFieldMapper fieldMapper = new StringFieldMapper(buildNames(context),
|
||||
index, store, termVector, boost, omitNorms, indexOptions, nullValue,
|
||||
boost, fieldType, nullValue,
|
||||
indexAnalyzer, searchAnalyzer, searchQuotedAnalyzer, positionOffsetGap, ignoreAbove);
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
|
@ -176,18 +182,16 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements Al
|
|||
|
||||
private int ignoreAbove;
|
||||
|
||||
protected StringFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
protected StringFieldMapper(Names names, float boost, FieldType fieldType,
|
||||
String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||
this(names, index, store, termVector, boost, omitNorms, indexOptions, nullValue, indexAnalyzer,
|
||||
this(names, boost, fieldType, nullValue, indexAnalyzer,
|
||||
searchAnalyzer, searchAnalyzer, Defaults.POSITION_OFFSET_GAP, Defaults.IGNORE_ABOVE);
|
||||
}
|
||||
|
||||
protected StringFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
protected StringFieldMapper(Names names, float boost, FieldType fieldType,
|
||||
String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer,
|
||||
NamedAnalyzer searchQuotedAnalyzer, int positionOffsetGap, int ignoreAbove) {
|
||||
super(names, index, store, termVector, boost, omitNorms, indexOptions, indexAnalyzer, searchAnalyzer);
|
||||
super(names, boost, fieldType, indexAnalyzer, searchAnalyzer);
|
||||
this.nullValue = nullValue;
|
||||
this.positionOffsetGap = positionOffsetGap;
|
||||
this.searchQuotedAnalyzer = searchQuotedAnalyzer != null ? searchQuotedAnalyzer : this.searchAnalyzer;
|
||||
|
@ -209,7 +213,7 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements Al
|
|||
}
|
||||
|
||||
@Override
|
||||
public String value(Fieldable field) {
|
||||
public String value(Field field) {
|
||||
return field.stringValue();
|
||||
}
|
||||
|
||||
|
@ -219,7 +223,7 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements Al
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return value(field);
|
||||
}
|
||||
|
||||
|
@ -291,7 +295,7 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements Al
|
|||
context.ignoredValue(names.indexName(), value);
|
||||
return null;
|
||||
}
|
||||
Field field = new Field(names.indexName(), false, value, store, index, termVector);
|
||||
Field field = new Field(names.indexName(), value, fieldType);
|
||||
field.setBoost(boost);
|
||||
return field;
|
||||
}
|
||||
|
@ -317,20 +321,30 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements Al
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.STRING_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.STRING_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.STRING_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.STRING_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.STRING_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.STRING_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.STRING_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.STRING_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.STRING_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (nullValue != null) {
|
||||
builder.field("null_value", nullValue);
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.mapper.core;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Field.Index;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.elasticsearch.ElasticSearchParseException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -68,11 +66,21 @@ public class TypeParsers {
|
|||
} else if (propName.equals("store")) {
|
||||
builder.store(parseStore(name, propNode.toString()));
|
||||
} else if (propName.equals("index")) {
|
||||
builder.index(parseIndex(name, propNode.toString()));
|
||||
parseIndex(name, propNode.toString(), builder);
|
||||
} else if (propName.equals("tokenized")) {
|
||||
builder.tokenized(nodeBooleanValue(propNode));
|
||||
} else if (propName.equals("term_vector")) {
|
||||
builder.termVector(parseTermVector(name, propNode.toString()));
|
||||
parseTermVector(name, propNode.toString(), builder);
|
||||
} else if (propName.equals("boost")) {
|
||||
builder.boost(nodeFloatValue(propNode));
|
||||
} else if (propName.equals("store_term_vectors")) {
|
||||
builder.storeTermVectors(nodeBooleanValue(propNode));
|
||||
} else if (propName.equals("store_term_vector_offsets")) {
|
||||
builder.storeTermVectorOffsets(nodeBooleanValue(propNode));
|
||||
} else if (propName.equals("store_term_vector_positions")) {
|
||||
builder.storeTermVectorPositions(nodeBooleanValue(propNode));
|
||||
} else if (propName.equals("store_term_vector_payloads")) {
|
||||
builder.storeTermVectorPayloads(nodeBooleanValue(propNode));
|
||||
} else if (propName.equals("omit_norms")) {
|
||||
builder.omitNorms(nodeBooleanValue(propNode));
|
||||
} else if (propName.equals("omit_term_freq_and_positions")) {
|
||||
|
@ -122,48 +130,46 @@ public class TypeParsers {
|
|||
return Joda.forPattern(node.toString());
|
||||
}
|
||||
|
||||
public static Field.TermVector parseTermVector(String fieldName, String termVector) throws MapperParsingException {
|
||||
public static void parseTermVector(String fieldName, String termVector, AbstractFieldMapper.Builder builder) throws MapperParsingException {
|
||||
termVector = Strings.toUnderscoreCase(termVector);
|
||||
if ("no".equals(termVector)) {
|
||||
return Field.TermVector.NO;
|
||||
builder.storeTermVectors(false);
|
||||
} else if ("yes".equals(termVector)) {
|
||||
return Field.TermVector.YES;
|
||||
builder.storeTermVectors(true);
|
||||
} else if ("with_offsets".equals(termVector)) {
|
||||
return Field.TermVector.WITH_OFFSETS;
|
||||
builder.storeTermVectorOffsets(true);
|
||||
} else if ("with_positions".equals(termVector)) {
|
||||
return Field.TermVector.WITH_POSITIONS;
|
||||
builder.storeTermVectorPositions(true);
|
||||
} else if ("with_positions_offsets".equals(termVector)) {
|
||||
return Field.TermVector.WITH_POSITIONS_OFFSETS;
|
||||
builder.storeTermVectorPositions(true);
|
||||
builder.storeTermVectorOffsets(true);
|
||||
} else {
|
||||
throw new MapperParsingException("Wrong value for termVector [" + termVector + "] for field [" + fieldName + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public static Field.Index parseIndex(String fieldName, String index) throws MapperParsingException {
|
||||
public static void parseIndex(String fieldName, String index, AbstractFieldMapper.Builder builder) throws MapperParsingException {
|
||||
index = Strings.toUnderscoreCase(index);
|
||||
if ("no".equals(index)) {
|
||||
return Field.Index.NO;
|
||||
builder.index(false);
|
||||
} else if ("not_analyzed".equals(index)) {
|
||||
return Field.Index.NOT_ANALYZED;
|
||||
builder.index(true);
|
||||
builder.tokenized(false);
|
||||
} else if ("analyzed".equals(index)) {
|
||||
return Field.Index.ANALYZED;
|
||||
builder.index(true);
|
||||
builder.tokenized(true);
|
||||
} else {
|
||||
throw new MapperParsingException("Wrong value for index [" + index + "] for field [" + fieldName + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public static Field.Store parseStore(String fieldName, String store) throws MapperParsingException {
|
||||
public static boolean parseStore(String fieldName, String store) throws MapperParsingException {
|
||||
if ("no".equals(store)) {
|
||||
return Field.Store.NO;
|
||||
return false;
|
||||
} else if ("yes".equals(store)) {
|
||||
return Field.Store.YES;
|
||||
return true;
|
||||
} else {
|
||||
boolean value = nodeBooleanValue(store);
|
||||
if (value) {
|
||||
return Field.Store.YES;
|
||||
} else {
|
||||
return Field.Store.NO;
|
||||
}
|
||||
return nodeBooleanValue(store);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.elasticsearch.index.mapper.geo;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -55,6 +55,18 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper<String> {
|
|||
public static final int GEOHASH_LEVELS = GeohashPrefixTree.getMaxLevelsPossible();
|
||||
public static final int QUADTREE_LEVELS = QuadPrefixTree.DEFAULT_MAX_LEVELS;
|
||||
public static final double DISTANCE_ERROR_PCT = 0.025d;
|
||||
|
||||
public static final FieldType GEO_SHAPE_FIELD_TYPE = new FieldType();
|
||||
|
||||
static {
|
||||
GEO_SHAPE_FIELD_TYPE.setIndexed(true);
|
||||
GEO_SHAPE_FIELD_TYPE.setTokenized(false);
|
||||
GEO_SHAPE_FIELD_TYPE.setStored(false);
|
||||
GEO_SHAPE_FIELD_TYPE.setStoreTermVectors(false);
|
||||
GEO_SHAPE_FIELD_TYPE.setOmitNorms(true);
|
||||
GEO_SHAPE_FIELD_TYPE.setIndexOptions(FieldInfo.IndexOptions.DOCS_ONLY);
|
||||
GEO_SHAPE_FIELD_TYPE.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends AbstractFieldMapper.Builder<Builder, GeoShapeFieldMapper> {
|
||||
|
@ -66,7 +78,7 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper<String> {
|
|||
private SpatialPrefixTree prefixTree;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.GEO_SHAPE_FIELD_TYPE));
|
||||
}
|
||||
|
||||
public Builder tree(String tree) {
|
||||
|
@ -96,7 +108,7 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper<String> {
|
|||
throw new ElasticSearchIllegalArgumentException("Unknown prefix tree type [" + tree + "]");
|
||||
}
|
||||
|
||||
return new GeoShapeFieldMapper(buildNames(context), prefixTree, distanceErrorPct);
|
||||
return new GeoShapeFieldMapper(buildNames(context), prefixTree, distanceErrorPct, fieldType);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,13 +135,13 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper<String> {
|
|||
|
||||
private final SpatialStrategy spatialStrategy;
|
||||
|
||||
public GeoShapeFieldMapper(FieldMapper.Names names, SpatialPrefixTree prefixTree, double distanceErrorPct) {
|
||||
super(names, Field.Index.NOT_ANALYZED, Field.Store.NO, Field.TermVector.NO, 1, true, FieldInfo.IndexOptions.DOCS_ONLY, null, null);
|
||||
public GeoShapeFieldMapper(FieldMapper.Names names, SpatialPrefixTree prefixTree, double distanceErrorPct, FieldType fieldType) {
|
||||
super(names, 1, fieldType, null, null);
|
||||
this.spatialStrategy = new TermQueryPrefixTreeStrategy(names, prefixTree, distanceErrorPct);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Field parseCreateField(ParseContext context) throws IOException {
|
||||
return spatialStrategy.createField(GeoJSONShapeParser.parse(context.parser()));
|
||||
}
|
||||
|
||||
|
@ -162,7 +174,7 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String value(Fieldable field) {
|
||||
public String value(Field field) {
|
||||
throw new UnsupportedOperationException("GeoShape fields cannot be converted to String values");
|
||||
}
|
||||
|
||||
|
@ -172,7 +184,7 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
throw new UnsupportedOperationException("GeoShape fields cannot be converted to String values");
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper.internal;
|
|||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Query;
|
||||
|
@ -195,7 +194,7 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Field parseCreateField(ParseContext context) throws IOException {
|
||||
if (!enabled) {
|
||||
return null;
|
||||
}
|
||||
|
@ -229,7 +228,7 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
|||
}
|
||||
|
||||
@Override
|
||||
public Void value(Fieldable field) {
|
||||
public Void value(Field field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -239,12 +238,12 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object valueForSearch(Fieldable field) {
|
||||
public Object valueForSearch(Field field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
package org.elasticsearch.index.mapper.internal;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.NumericRangeFilter;
|
||||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
|
@ -59,8 +59,13 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
|
|||
public static class Defaults extends NumberFieldMapper.Defaults {
|
||||
public static final String NAME = "_boost";
|
||||
public static final Float NULL_VALUE = null;
|
||||
public static final Field.Index INDEX = Field.Index.NO;
|
||||
public static final Field.Store STORE = Field.Store.NO;
|
||||
|
||||
public static final FieldType BOOST_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
BOOST_FIELD_TYPE.setIndexed(false);
|
||||
BOOST_FIELD_TYPE.setStored(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends NumberFieldMapper.Builder<Builder, BoostFieldMapper> {
|
||||
|
@ -68,10 +73,8 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
|
|||
protected Float nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.BOOST_FIELD_TYPE));
|
||||
builder = this;
|
||||
index = Defaults.INDEX;
|
||||
store = Defaults.STORE;
|
||||
}
|
||||
|
||||
public Builder nullValue(float nullValue) {
|
||||
|
@ -82,7 +85,7 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
|
|||
@Override
|
||||
public BoostFieldMapper build(BuilderContext context) {
|
||||
return new BoostFieldMapper(name, buildIndexName(context),
|
||||
precisionStep, index, store, boost, omitNorms, indexOptions, nullValue);
|
||||
precisionStep, boost, fieldType, nullValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,14 +113,12 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
|
|||
}
|
||||
|
||||
protected BoostFieldMapper(String name, String indexName) {
|
||||
this(name, indexName, Defaults.PRECISION_STEP, Defaults.INDEX, Defaults.STORE,
|
||||
Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Defaults.NULL_VALUE);
|
||||
this(name, indexName, Defaults.PRECISION_STEP, Defaults.BOOST, new FieldType(Defaults.BOOST_FIELD_TYPE), Defaults.NULL_VALUE);
|
||||
}
|
||||
|
||||
protected BoostFieldMapper(String name, String indexName, int precisionStep, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
Float nullValue) {
|
||||
super(new Names(name, indexName, indexName, name), precisionStep, null, index, store, boost, omitNorms, indexOptions,
|
||||
protected BoostFieldMapper(String name, String indexName, int precisionStep,
|
||||
float boost, FieldType fieldType, Float nullValue) {
|
||||
super(new Names(name, indexName, indexName, name), precisionStep, null, boost, fieldType,
|
||||
Defaults.IGNORE_MALFORMED, new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
|
@ -129,12 +130,12 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
|
|||
}
|
||||
|
||||
@Override
|
||||
public Float value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public Float value(Field field) {
|
||||
BytesRef value = field.binaryValue();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Numbers.bytesToFloat(value);
|
||||
return Numbers.bytesToFloat(value.bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -144,7 +145,10 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
|
|||
|
||||
@Override
|
||||
public String indexedValue(String value) {
|
||||
return NumericUtils.floatToPrefixCoded(Float.parseFloat(value));
|
||||
int intValue = NumericUtils.floatToSortableInt(Float.parseFloat(value));
|
||||
BytesRef bytesRef = new BytesRef();
|
||||
NumericUtils.intToPrefixCoded(intValue, precisionStep(), bytesRef);
|
||||
return bytesRef.utf8ToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -230,13 +234,13 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
final float value = parseFloatValue(context);
|
||||
if (Float.isNaN(value)) {
|
||||
return null;
|
||||
}
|
||||
context.doc().setBoost(value);
|
||||
return new FloatFieldMapper.CustomFloatNumericField(this, value);
|
||||
return new FloatFieldMapper.CustomFloatNumericField(this, value, fieldType);
|
||||
}
|
||||
|
||||
private float parseFloatValue(ParseContext context) throws IOException {
|
||||
|
|
|
@ -23,8 +23,9 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.Iterables;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -56,10 +57,17 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final String NAME = IdFieldMapper.NAME;
|
||||
public static final String INDEX_NAME = IdFieldMapper.NAME;
|
||||
public static final Field.Index INDEX = Field.Index.NO;
|
||||
public static final Field.Store STORE = Field.Store.NO;
|
||||
public static final boolean OMIT_NORMS = true;
|
||||
public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY;
|
||||
|
||||
public static final FieldType ID_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
ID_FIELD_TYPE.setIndexed(false);
|
||||
ID_FIELD_TYPE.setStored(false);
|
||||
ID_FIELD_TYPE.setOmitNorms(true);
|
||||
ID_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
ID_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final String PATH = null;
|
||||
}
|
||||
|
||||
|
@ -68,12 +76,8 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
private String path = Defaults.PATH;
|
||||
|
||||
public Builder() {
|
||||
super(Defaults.NAME);
|
||||
super(Defaults.NAME, new FieldType(Defaults.ID_FIELD_TYPE));
|
||||
indexName = Defaults.INDEX_NAME;
|
||||
store = Defaults.STORE;
|
||||
index = Defaults.INDEX;
|
||||
omitNorms = Defaults.OMIT_NORMS;
|
||||
indexOptions = Defaults.INDEX_OPTIONS;
|
||||
}
|
||||
|
||||
public Builder path(String path) {
|
||||
|
@ -83,7 +87,7 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
|
||||
@Override
|
||||
public IdFieldMapper build(BuilderContext context) {
|
||||
return new IdFieldMapper(name, indexName, index, store, termVector, boost, omitNorms, indexOptions, path);
|
||||
return new IdFieldMapper(name, indexName, boost, fieldType, path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,21 +110,19 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
private final String path;
|
||||
|
||||
public IdFieldMapper() {
|
||||
this(Defaults.NAME, Defaults.INDEX_NAME, Defaults.INDEX);
|
||||
this(Defaults.NAME, Defaults.INDEX_NAME, new FieldType(Defaults.ID_FIELD_TYPE));
|
||||
}
|
||||
|
||||
public IdFieldMapper(Field.Index index) {
|
||||
this(Defaults.NAME, Defaults.INDEX_NAME, index);
|
||||
public IdFieldMapper(FieldType fieldType) {
|
||||
this(Defaults.NAME, Defaults.INDEX_NAME, fieldType);
|
||||
}
|
||||
|
||||
protected IdFieldMapper(String name, String indexName, Field.Index index) {
|
||||
this(name, indexName, index, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST,
|
||||
Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Defaults.PATH);
|
||||
protected IdFieldMapper(String name, String indexName, FieldType fieldType) {
|
||||
this(name, indexName, Defaults.BOOST, fieldType, Defaults.PATH);
|
||||
}
|
||||
|
||||
protected IdFieldMapper(String name, String indexName, Field.Index index, Field.Store store, Field.TermVector termVector,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions, String path) {
|
||||
super(new Names(name, indexName, indexName, name), index, store, termVector, boost, omitNorms, indexOptions, Lucene.KEYWORD_ANALYZER,
|
||||
protected IdFieldMapper(String name, String indexName, float boost, FieldType fieldType, String path) {
|
||||
super(new Names(name, indexName, indexName, name), boost, fieldType, Lucene.KEYWORD_ANALYZER,
|
||||
Lucene.KEYWORD_ANALYZER);
|
||||
this.path = path;
|
||||
}
|
||||
|
@ -130,12 +132,12 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
}
|
||||
|
||||
public String value(Document document) {
|
||||
Fieldable field = document.getFieldable(names.indexName());
|
||||
Field field = (Field) document.getField(names.indexName());
|
||||
return field == null ? null : value(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value(Fieldable field) {
|
||||
public String value(Field field) {
|
||||
return field.stringValue();
|
||||
}
|
||||
|
||||
|
@ -145,7 +147,7 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return value(field);
|
||||
}
|
||||
|
||||
|
@ -184,14 +186,14 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
}
|
||||
Collection<String> queryTypes = context.queryTypes();
|
||||
if (queryTypes.size() == 1) {
|
||||
PrefixQuery prefixQuery = new PrefixQuery(UidFieldMapper.TERM_FACTORY.createTerm(Uid.createUid(Iterables.getFirst(queryTypes, null), value)));
|
||||
PrefixQuery prefixQuery = new PrefixQuery(new Term(UidFieldMapper.NAME, Uid.createUid(Iterables.getFirst(queryTypes, null), value)));
|
||||
if (method != null) {
|
||||
prefixQuery.setRewriteMethod(method);
|
||||
}
|
||||
}
|
||||
BooleanQuery query = new BooleanQuery();
|
||||
for (String queryType : queryTypes) {
|
||||
PrefixQuery prefixQuery = new PrefixQuery(UidFieldMapper.TERM_FACTORY.createTerm(Uid.createUid(queryType, value)));
|
||||
PrefixQuery prefixQuery = new PrefixQuery(new Term(UidFieldMapper.NAME, Uid.createUid(queryType, value)));
|
||||
if (method != null) {
|
||||
prefixQuery.setRewriteMethod(method);
|
||||
}
|
||||
|
@ -207,11 +209,11 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
}
|
||||
Collection<String> queryTypes = context.queryTypes();
|
||||
if (queryTypes.size() == 1) {
|
||||
return new PrefixFilter(UidFieldMapper.TERM_FACTORY.createTerm(Uid.createUid(Iterables.getFirst(queryTypes, null), value)));
|
||||
return new PrefixFilter(new Term(UidFieldMapper.NAME, Uid.createUid(Iterables.getFirst(queryTypes, null), value)));
|
||||
}
|
||||
XBooleanFilter filter = new XBooleanFilter();
|
||||
for (String queryType : queryTypes) {
|
||||
filter.addShould(new PrefixFilter(UidFieldMapper.TERM_FACTORY.createTerm(Uid.createUid(queryType, value))));
|
||||
filter.addShould(new PrefixFilter(new Term(UidFieldMapper.NAME, Uid.createUid(queryType, value))));
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
@ -256,16 +258,16 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
throw new MapperParsingException("Provided id [" + context.id() + "] does not match the content one [" + id + "]");
|
||||
}
|
||||
context.id(id);
|
||||
if (index == Field.Index.NO && store == Field.Store.NO) {
|
||||
if (!fieldType.indexed() && !fieldType.stored()) {
|
||||
return null;
|
||||
}
|
||||
return new Field(names.indexName(), false, context.id(), store, index, termVector);
|
||||
return new Field(names.indexName(), context.id(), fieldType);
|
||||
} else {
|
||||
// we are in the pre/post parse phase
|
||||
if (index == Field.Index.NO && store == Field.Store.NO) {
|
||||
if (!fieldType.indexed() && !fieldType.stored()) {
|
||||
return null;
|
||||
}
|
||||
return new Field(names.indexName(), false, context.id(), store, index, termVector);
|
||||
return new Field(names.indexName(), context.id(), fieldType);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,15 +279,16 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
// if all are defaults, no sense to write it at all
|
||||
if (store == Defaults.STORE && index == Defaults.INDEX && path == Defaults.PATH) {
|
||||
if (fieldType.stored() == Defaults.ID_FIELD_TYPE.stored() &&
|
||||
fieldType.indexed() == Defaults.ID_FIELD_TYPE.indexed() && path == Defaults.PATH) {
|
||||
return builder;
|
||||
}
|
||||
builder.startObject(CONTENT_TYPE);
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (fieldType.stored() != Defaults.ID_FIELD_TYPE.stored()) {
|
||||
builder.field("store", fieldType.stored());
|
||||
}
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (fieldType.indexed() != Defaults.ID_FIELD_TYPE.indexed()) {
|
||||
builder.field("index", fieldType.indexed());
|
||||
}
|
||||
if (path != Defaults.PATH) {
|
||||
builder.field("path", path);
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.index.mapper.internal;
|
|||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -48,10 +48,18 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
|
|||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final String NAME = IndexFieldMapper.NAME;
|
||||
public static final String INDEX_NAME = IndexFieldMapper.NAME;
|
||||
public static final Field.Index INDEX = Field.Index.NOT_ANALYZED;
|
||||
public static final Field.Store STORE = Field.Store.NO;
|
||||
public static final boolean OMIT_NORMS = true;
|
||||
public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY;
|
||||
|
||||
public static final FieldType INDEX_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
INDEX_FIELD_TYPE.setIndexed(true);
|
||||
INDEX_FIELD_TYPE.setTokenized(false);
|
||||
INDEX_FIELD_TYPE.setStored(false);
|
||||
INDEX_FIELD_TYPE.setOmitNorms(true);
|
||||
INDEX_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
INDEX_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final boolean ENABLED = false;
|
||||
}
|
||||
|
||||
|
@ -60,12 +68,8 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
|
|||
private boolean enabled = Defaults.ENABLED;
|
||||
|
||||
public Builder() {
|
||||
super(Defaults.NAME);
|
||||
super(Defaults.NAME, new FieldType(Defaults.INDEX_FIELD_TYPE));
|
||||
indexName = Defaults.INDEX_NAME;
|
||||
index = Defaults.INDEX;
|
||||
store = Defaults.STORE;
|
||||
omitNorms = Defaults.OMIT_NORMS;
|
||||
indexOptions = Defaults.INDEX_OPTIONS;
|
||||
}
|
||||
|
||||
public Builder enabled(boolean enabled) {
|
||||
|
@ -75,7 +79,7 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
|
|||
|
||||
@Override
|
||||
public IndexFieldMapper build(BuilderContext context) {
|
||||
return new IndexFieldMapper(name, indexName, store, termVector, boost, omitNorms, indexOptions, enabled);
|
||||
return new IndexFieldMapper(name, indexName, boost, fieldType, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,13 +107,11 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
|
|||
}
|
||||
|
||||
protected IndexFieldMapper(String name, String indexName) {
|
||||
this(name, indexName, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST,
|
||||
Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Defaults.ENABLED);
|
||||
this(name, indexName, Defaults.BOOST, new FieldType(Defaults.INDEX_FIELD_TYPE), Defaults.ENABLED);
|
||||
}
|
||||
|
||||
public IndexFieldMapper(String name, String indexName, Field.Store store, Field.TermVector termVector,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions, boolean enabled) {
|
||||
super(new Names(name, indexName, indexName, name), Defaults.INDEX, store, termVector, boost, omitNorms, indexOptions, Lucene.KEYWORD_ANALYZER,
|
||||
public IndexFieldMapper(String name, String indexName, float boost, FieldType fieldType, boolean enabled) {
|
||||
super(new Names(name, indexName, indexName, name), boost, fieldType, Lucene.KEYWORD_ANALYZER,
|
||||
Lucene.KEYWORD_ANALYZER);
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
@ -119,12 +121,12 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
|
|||
}
|
||||
|
||||
public String value(Document document) {
|
||||
Fieldable field = document.getFieldable(names.indexName());
|
||||
Field field = (Field) document.getField(names.indexName());
|
||||
return field == null ? null : value(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value(Fieldable field) {
|
||||
public String value(Field field) {
|
||||
return field.stringValue();
|
||||
}
|
||||
|
||||
|
@ -134,7 +136,7 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return value(field);
|
||||
}
|
||||
|
||||
|
@ -176,7 +178,7 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
|
|||
if (!enabled) {
|
||||
return null;
|
||||
}
|
||||
return new Field(names.indexName(), context.index(), store, index);
|
||||
return new Field(names.indexName(), context.index(), fieldType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -187,12 +189,12 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
// if all defaults, no need to write it at all
|
||||
if (store == Defaults.STORE && enabled == Defaults.ENABLED) {
|
||||
if (stored() == Defaults.INDEX_FIELD_TYPE.stored() && enabled == Defaults.ENABLED) {
|
||||
return builder;
|
||||
}
|
||||
builder.startObject(CONTENT_TYPE);
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.INDEX_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (enabled != Defaults.ENABLED) {
|
||||
builder.field("enabled", enabled);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.elasticsearch.index.mapper.internal;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.ConstantScoreQuery;
|
||||
|
@ -49,9 +49,17 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements Inter
|
|||
|
||||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final String NAME = ParentFieldMapper.NAME;
|
||||
public static final Field.Index INDEX = Field.Index.NOT_ANALYZED;
|
||||
public static final boolean OMIT_NORMS = true;
|
||||
public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY;
|
||||
|
||||
public static final FieldType PARENT_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
PARENT_FIELD_TYPE.setIndexed(true);
|
||||
PARENT_FIELD_TYPE.setTokenized(false);
|
||||
PARENT_FIELD_TYPE.setStored(true);
|
||||
PARENT_FIELD_TYPE.setOmitNorms(true);
|
||||
PARENT_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
PARENT_FIELD_TYPE.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends Mapper.Builder<Builder, ParentFieldMapper> {
|
||||
|
@ -97,8 +105,8 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements Inter
|
|||
private final String type;
|
||||
|
||||
protected ParentFieldMapper(String name, String indexName, String type) {
|
||||
super(new Names(name, indexName, indexName, name), Defaults.INDEX, Field.Store.YES, Defaults.TERM_VECTOR, Defaults.BOOST,
|
||||
Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER);
|
||||
super(new Names(name, indexName, indexName, name), Defaults.BOOST, new FieldType(Defaults.PARENT_FIELD_TYPE),
|
||||
Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
@ -130,7 +138,7 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements Inter
|
|||
// we are in the parsing of _parent phase
|
||||
String parentId = context.parser().text();
|
||||
context.sourceToParse().parent(parentId);
|
||||
return new Field(names.indexName(), Uid.createUid(context.stringBuilder(), type, parentId), store, index);
|
||||
return new Field(names.indexName(), Uid.createUid(context.stringBuilder(), type, parentId), fieldType);
|
||||
}
|
||||
// otherwise, we are running it post processing of the xcontent
|
||||
String parsedParentId = context.doc().get(Defaults.NAME);
|
||||
|
@ -141,7 +149,7 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements Inter
|
|||
throw new MapperParsingException("No parent id provided, not within the document, and not externally");
|
||||
}
|
||||
// we did not add it in the parsing phase, add it now
|
||||
return new Field(names.indexName(), Uid.createUid(context.stringBuilder(), type, parentId), store, index);
|
||||
return new Field(names.indexName(), Uid.createUid(context.stringBuilder(), type, parentId), fieldType);
|
||||
} else if (parentId != null && !parsedParentId.equals(Uid.createUid(context.stringBuilder(), type, parentId))) {
|
||||
throw new MapperParsingException("Parent id mismatch, document value is [" + Uid.createUid(parsedParentId).id() + "], while external value is [" + parentId + "]");
|
||||
}
|
||||
|
@ -151,7 +159,7 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements Inter
|
|||
}
|
||||
|
||||
@Override
|
||||
public Uid value(Fieldable field) {
|
||||
public Uid value(Field field) {
|
||||
return Uid.createUid(field.stringValue());
|
||||
}
|
||||
|
||||
|
@ -161,12 +169,12 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements Inter
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return field.stringValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object valueForSearch(Fieldable field) {
|
||||
public Object valueForSearch(Field field) {
|
||||
String fieldValue = field.stringValue();
|
||||
if (fieldValue == null) {
|
||||
return null;
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.index.mapper.internal;
|
|||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
|
@ -47,10 +47,18 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
|
||||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final String NAME = "_routing";
|
||||
public static final Field.Index INDEX = Field.Index.NOT_ANALYZED;
|
||||
public static final Field.Store STORE = Field.Store.YES;
|
||||
public static final boolean OMIT_NORMS = true;
|
||||
public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY;
|
||||
|
||||
public static final FieldType ROUTING_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
ROUTING_FIELD_TYPE.setIndexed(true);
|
||||
ROUTING_FIELD_TYPE.setTokenized(false);
|
||||
ROUTING_FIELD_TYPE.setStored(true);
|
||||
ROUTING_FIELD_TYPE.setOmitNorms(true);
|
||||
ROUTING_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
ROUTING_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final boolean REQUIRED = false;
|
||||
public static final String PATH = null;
|
||||
}
|
||||
|
@ -62,9 +70,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
private String path = Defaults.PATH;
|
||||
|
||||
public Builder() {
|
||||
super(Defaults.NAME);
|
||||
store = Defaults.STORE;
|
||||
index = Defaults.INDEX;
|
||||
super(Defaults.NAME, new FieldType(Defaults.ROUTING_FIELD_TYPE));
|
||||
}
|
||||
|
||||
public Builder required(boolean required) {
|
||||
|
@ -79,7 +85,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
|
||||
@Override
|
||||
public RoutingFieldMapper build(BuilderContext context) {
|
||||
return new RoutingFieldMapper(store, index, required, path);
|
||||
return new RoutingFieldMapper(fieldType, required, path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,11 +113,11 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
private final String path;
|
||||
|
||||
public RoutingFieldMapper() {
|
||||
this(Defaults.STORE, Defaults.INDEX, Defaults.REQUIRED, Defaults.PATH);
|
||||
this(new FieldType(Defaults.ROUTING_FIELD_TYPE), Defaults.REQUIRED, Defaults.PATH);
|
||||
}
|
||||
|
||||
protected RoutingFieldMapper(Field.Store store, Field.Index index, boolean required, String path) {
|
||||
super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), index, store, Defaults.TERM_VECTOR, 1.0f, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Lucene.KEYWORD_ANALYZER,
|
||||
protected RoutingFieldMapper(FieldType fieldType, boolean required, String path) {
|
||||
super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), 1.0f, fieldType, Lucene.KEYWORD_ANALYZER,
|
||||
Lucene.KEYWORD_ANALYZER);
|
||||
this.required = required;
|
||||
this.path = path;
|
||||
|
@ -130,12 +136,12 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
}
|
||||
|
||||
public String value(Document document) {
|
||||
Fieldable field = document.getFieldable(names.indexName());
|
||||
Field field = (Field) document.getField(names.indexName());
|
||||
return field == null ? null : value(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value(Fieldable field) {
|
||||
public String value(Field field) {
|
||||
return field.stringValue();
|
||||
}
|
||||
|
||||
|
@ -145,7 +151,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return value(field);
|
||||
}
|
||||
|
||||
|
@ -160,7 +166,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
if (path != null && routing != null) {
|
||||
// we have a path, check if we can validate we have the same routing value as the one in the doc...
|
||||
String value = null;
|
||||
Fieldable field = context.doc().getFieldable(path);
|
||||
Field field = (Field) context.doc().getField(path);
|
||||
if (field != null) {
|
||||
value = field.stringValue();
|
||||
if (value == null) {
|
||||
|
@ -209,7 +215,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
context.ignoredValue(names.indexName(), routing);
|
||||
return null;
|
||||
}
|
||||
return new Field(names.indexName(), routing, store, index);
|
||||
return new Field(names.indexName(), routing, fieldType);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -224,15 +230,16 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
// if all are defaults, no sense to write it at all
|
||||
if (index == Defaults.INDEX && store == Defaults.STORE && required == Defaults.REQUIRED && path == Defaults.PATH) {
|
||||
if (indexed() == Defaults.ROUTING_FIELD_TYPE.indexed() &&
|
||||
stored() == Defaults.ROUTING_FIELD_TYPE.stored() && required == Defaults.REQUIRED && path == Defaults.PATH) {
|
||||
return builder;
|
||||
}
|
||||
builder.startObject(CONTENT_TYPE);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.ROUTING_FIELD_TYPE.indexed()) {
|
||||
builder.field("index", indexed());
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.ROUTING_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (required != Defaults.REQUIRED) {
|
||||
builder.field("required", required);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.elasticsearch.index.mapper.internal;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
|
@ -40,16 +40,23 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
|
|||
public static class Defaults extends IntegerFieldMapper.Defaults {
|
||||
public static final String NAME = CONTENT_TYPE;
|
||||
public static final boolean ENABLED = false;
|
||||
|
||||
public static final FieldType SIZE_FIELD_TYPE = new FieldType(IntegerFieldMapper.Defaults.INTEGER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
SIZE_FIELD_TYPE.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends Mapper.Builder<Builder, IntegerFieldMapper> {
|
||||
|
||||
protected boolean enabled = Defaults.ENABLED;
|
||||
|
||||
protected Field.Store store = Defaults.STORE;
|
||||
protected final FieldType fieldType;
|
||||
|
||||
public Builder() {
|
||||
super(Defaults.NAME);
|
||||
fieldType = new FieldType(Defaults.SIZE_FIELD_TYPE);
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -58,14 +65,14 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
|
|||
return builder;
|
||||
}
|
||||
|
||||
public Builder store(Field.Store store) {
|
||||
this.store = store;
|
||||
public Builder store(boolean store) {
|
||||
this.fieldType.setStored(store);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SizeFieldMapper build(BuilderContext context) {
|
||||
return new SizeFieldMapper(enabled, store);
|
||||
return new SizeFieldMapper(enabled, fieldType);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,12 +96,12 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
|
|||
private final boolean enabled;
|
||||
|
||||
public SizeFieldMapper() {
|
||||
this(Defaults.ENABLED, Defaults.STORE);
|
||||
this(Defaults.ENABLED, new FieldType(Defaults.SIZE_FIELD_TYPE));
|
||||
}
|
||||
|
||||
public SizeFieldMapper(boolean enabled, Field.Store store) {
|
||||
super(new Names(Defaults.NAME), Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, Defaults.INDEX, store,
|
||||
Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Defaults.NULL_VALUE,
|
||||
public SizeFieldMapper(boolean enabled, FieldType fieldType) {
|
||||
super(new Names(Defaults.NAME), Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR,
|
||||
Defaults.BOOST, fieldType, Defaults.NULL_VALUE,
|
||||
Defaults.IGNORE_MALFORMED);
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
@ -133,28 +140,28 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
if (!enabled) {
|
||||
return null;
|
||||
}
|
||||
if (context.flyweight()) {
|
||||
return null;
|
||||
}
|
||||
return new CustomIntegerNumericField(this, context.source().length());
|
||||
return new CustomIntegerNumericField(this, context.source().length(), fieldType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
// all are defaults, no need to write it at all
|
||||
if (enabled == Defaults.ENABLED && store == Defaults.STORE) {
|
||||
if (enabled == Defaults.ENABLED && stored() == Defaults.SIZE_FIELD_TYPE.stored()) {
|
||||
return builder;
|
||||
}
|
||||
builder.startObject(contentType());
|
||||
if (enabled != Defaults.ENABLED) {
|
||||
builder.field("enabled", enabled);
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.SIZE_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
|
|
|
@ -22,7 +22,8 @@ package org.elasticsearch.index.mapper.internal;
|
|||
import com.google.common.base.Objects;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.document.StoredField;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.elasticsearch.ElasticSearchParseException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -67,10 +68,17 @@ public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements In
|
|||
public static final boolean ENABLED = true;
|
||||
public static final long COMPRESS_THRESHOLD = -1;
|
||||
public static final String FORMAT = null; // default format is to use the one provided
|
||||
public static final Field.Index INDEX = Field.Index.NO;
|
||||
public static final Field.Store STORE = Field.Store.YES;
|
||||
public static final boolean OMIT_NORMS = true;
|
||||
public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY;
|
||||
|
||||
public static final FieldType SOURCE_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
SOURCE_FIELD_TYPE.setIndexed(false);
|
||||
SOURCE_FIELD_TYPE.setStored(true);
|
||||
SOURCE_FIELD_TYPE.setOmitNorms(true);
|
||||
SOURCE_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
SOURCE_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final String[] INCLUDES = Strings.EMPTY_ARRAY;
|
||||
public static final String[] EXCLUDES = Strings.EMPTY_ARRAY;
|
||||
}
|
||||
|
@ -190,8 +198,7 @@ public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements In
|
|||
}
|
||||
|
||||
protected SourceFieldMapper(String name, boolean enabled, String format, Boolean compress, long compressThreshold, String[] includes, String[] excludes) {
|
||||
super(new Names(name, name, name, name), Defaults.INDEX, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST,
|
||||
Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER);
|
||||
super(new Names(name, name, name, name), Defaults.BOOST, new FieldType(Defaults.SOURCE_FIELD_TYPE), Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER);
|
||||
this.enabled = enabled;
|
||||
this.compress = compress;
|
||||
this.compressThreshold = compressThreshold;
|
||||
|
@ -237,7 +244,7 @@ public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements In
|
|||
if (!enabled) {
|
||||
return null;
|
||||
}
|
||||
if (store == Field.Store.NO) {
|
||||
if (!stored()) {
|
||||
return null;
|
||||
}
|
||||
if (context.flyweight()) {
|
||||
|
@ -335,21 +342,21 @@ public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements In
|
|||
}
|
||||
}
|
||||
assert source.hasArray();
|
||||
return new Field(names().indexName(), source.array(), source.arrayOffset(), source.length());
|
||||
return new StoredField(names().indexName(), source.array(), source.arrayOffset(), source.length());
|
||||
}
|
||||
|
||||
public byte[] value(Document document) {
|
||||
Fieldable field = document.getFieldable(names.indexName());
|
||||
Field field = (Field) document.getField(names.indexName());
|
||||
return field == null ? null : value(field);
|
||||
}
|
||||
|
||||
public byte[] nativeValue(Fieldable field) {
|
||||
return field.getBinaryValue();
|
||||
public byte[] nativeValue(Field field) {
|
||||
return field.binaryValue().bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public byte[] value(Field field) {
|
||||
byte[] value = field.binaryValue().bytes;
|
||||
if (value == null) {
|
||||
return value;
|
||||
}
|
||||
|
@ -366,7 +373,7 @@ public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements In
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.elasticsearch.index.mapper.internal;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
@ -47,8 +47,16 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
|||
|
||||
public static class Defaults extends LongFieldMapper.Defaults {
|
||||
public static final String NAME = TTLFieldMapper.CONTENT_TYPE;
|
||||
public static final Field.Store STORE = Field.Store.YES;
|
||||
public static final Field.Index INDEX = Field.Index.NOT_ANALYZED;
|
||||
|
||||
public static final FieldType TTL_FIELD_TYPE = new FieldType(LongFieldMapper.Defaults.LONG_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
TTL_FIELD_TYPE.setStored(true);
|
||||
TTL_FIELD_TYPE.setIndexed(true);
|
||||
TTL_FIELD_TYPE.setTokenized(false);
|
||||
TTL_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final boolean ENABLED = false;
|
||||
public static final long DEFAULT = -1;
|
||||
}
|
||||
|
@ -59,9 +67,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
|||
private long defaultTTL = Defaults.DEFAULT;
|
||||
|
||||
public Builder() {
|
||||
super(Defaults.NAME);
|
||||
store = Defaults.STORE;
|
||||
index = Defaults.INDEX;
|
||||
super(Defaults.NAME, new FieldType(Defaults.TTL_FIELD_TYPE));
|
||||
}
|
||||
|
||||
public Builder enabled(boolean enabled) {
|
||||
|
@ -76,7 +82,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
|||
|
||||
@Override
|
||||
public TTLFieldMapper build(BuilderContext context) {
|
||||
return new TTLFieldMapper(store, index, enabled, defaultTTL, ignoreMalformed(context));
|
||||
return new TTLFieldMapper(fieldType, enabled, defaultTTL, ignoreMalformed(context));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,12 +111,12 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
|||
private long defaultTTL;
|
||||
|
||||
public TTLFieldMapper() {
|
||||
this(Defaults.STORE, Defaults.INDEX, Defaults.ENABLED, Defaults.DEFAULT, Defaults.IGNORE_MALFORMED);
|
||||
this(new FieldType(Defaults.TTL_FIELD_TYPE), Defaults.ENABLED, Defaults.DEFAULT, Defaults.IGNORE_MALFORMED);
|
||||
}
|
||||
|
||||
protected TTLFieldMapper(Field.Store store, Field.Index index, boolean enabled, long defaultTTL, Explicit<Boolean> ignoreMalformed) {
|
||||
protected TTLFieldMapper(FieldType fieldType, boolean enabled, long defaultTTL, Explicit<Boolean> ignoreMalformed) {
|
||||
super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), Defaults.PRECISION_STEP,
|
||||
Defaults.FUZZY_FACTOR, index, store, Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS,
|
||||
Defaults.FUZZY_FACTOR, Defaults.BOOST, fieldType,
|
||||
Defaults.NULL_VALUE, ignoreMalformed);
|
||||
this.enabled = enabled;
|
||||
this.defaultTTL = defaultTTL;
|
||||
|
@ -126,7 +132,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
|||
|
||||
// Overrides valueForSearch to display live value of remaining ttl
|
||||
@Override
|
||||
public Object valueForSearch(Fieldable field) {
|
||||
public Object valueForSearch(Field field) {
|
||||
long now;
|
||||
SearchContext searchContext = SearchContext.current();
|
||||
if (searchContext != null) {
|
||||
|
@ -178,7 +184,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException, AlreadyExpiredException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException, AlreadyExpiredException {
|
||||
if (enabled) {
|
||||
long ttl = context.sourceToParse().ttl();
|
||||
if (ttl <= 0 && defaultTTL > 0) { // no ttl provided so we use the default value
|
||||
|
@ -194,7 +200,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
|||
throw new AlreadyExpiredException(context.index(), context.type(), context.id(), timestamp, ttl, now);
|
||||
}
|
||||
// the expiration timestamp (timestamp + ttl) is set as field
|
||||
return new CustomLongNumericField(this, expire);
|
||||
return new CustomLongNumericField(this, expire, fieldType);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.elasticsearch.index.mapper.internal;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
||||
|
@ -50,8 +50,16 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
|||
|
||||
public static class Defaults extends DateFieldMapper.Defaults {
|
||||
public static final String NAME = "_timestamp";
|
||||
public static final Field.Store STORE = Field.Store.NO;
|
||||
public static final Field.Index INDEX = Field.Index.NOT_ANALYZED;
|
||||
|
||||
public static final FieldType TIMESTAMP_FIELD_TYPE = new FieldType(DateFieldMapper.Defaults.DATE_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
TIMESTAMP_FIELD_TYPE.setStored(false);
|
||||
TIMESTAMP_FIELD_TYPE.setIndexed(true);
|
||||
TIMESTAMP_FIELD_TYPE.setTokenized(false);
|
||||
TIMESTAMP_FIELD_TYPE.freeze();
|
||||
}
|
||||
|
||||
public static final boolean ENABLED = false;
|
||||
public static final String PATH = null;
|
||||
public static final FormatDateTimeFormatter DATE_TIME_FORMATTER = Joda.forPattern(DEFAULT_DATE_TIME_FORMAT);
|
||||
|
@ -64,9 +72,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
|||
private FormatDateTimeFormatter dateTimeFormatter = Defaults.DATE_TIME_FORMATTER;
|
||||
|
||||
public Builder() {
|
||||
super(Defaults.NAME);
|
||||
store = Defaults.STORE;
|
||||
index = Defaults.INDEX;
|
||||
super(Defaults.NAME, new FieldType(Defaults.TIMESTAMP_FIELD_TYPE));
|
||||
}
|
||||
|
||||
public Builder enabled(boolean enabled) {
|
||||
|
@ -90,7 +96,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
|||
if (context.indexSettings() != null) {
|
||||
parseUpperInclusive = context.indexSettings().getAsBoolean("index.mapping.date.parse_upper_inclusive", Defaults.PARSE_UPPER_INCLUSIVE);
|
||||
}
|
||||
return new TimestampFieldMapper(store, index, enabled, path, dateTimeFormatter, parseUpperInclusive, ignoreMalformed(context));
|
||||
return new TimestampFieldMapper(fieldType, enabled, path, dateTimeFormatter, parseUpperInclusive, ignoreMalformed(context));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,13 +126,13 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
|||
private final String path;
|
||||
|
||||
public TimestampFieldMapper() {
|
||||
this(Defaults.STORE, Defaults.INDEX, Defaults.ENABLED, Defaults.PATH, Defaults.DATE_TIME_FORMATTER, Defaults.PARSE_UPPER_INCLUSIVE, Defaults.IGNORE_MALFORMED);
|
||||
this(new FieldType(Defaults.TIMESTAMP_FIELD_TYPE), Defaults.ENABLED, Defaults.PATH, Defaults.DATE_TIME_FORMATTER, Defaults.PARSE_UPPER_INCLUSIVE, Defaults.IGNORE_MALFORMED);
|
||||
}
|
||||
|
||||
protected TimestampFieldMapper(Field.Store store, Field.Index index, boolean enabled, String path,
|
||||
protected TimestampFieldMapper(FieldType fieldType, boolean enabled, String path,
|
||||
FormatDateTimeFormatter dateTimeFormatter, boolean parseUpperInclusive, Explicit<Boolean> ignoreMalformed) {
|
||||
super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), dateTimeFormatter,
|
||||
Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, index, store, Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS,
|
||||
Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, Defaults.BOOST, fieldType,
|
||||
Defaults.NULL_VALUE, TimeUnit.MILLISECONDS /*always milliseconds*/,
|
||||
parseUpperInclusive, ignoreMalformed);
|
||||
this.enabled = enabled;
|
||||
|
@ -149,12 +155,12 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
|||
* Override the default behavior to return a timestamp
|
||||
*/
|
||||
@Override
|
||||
public Object valueForSearch(Fieldable field) {
|
||||
public Object valueForSearch(Field field) {
|
||||
return value(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
Long value = value(field);
|
||||
if (value == null) {
|
||||
return null;
|
||||
|
@ -186,14 +192,14 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
if (enabled) {
|
||||
long timestamp = context.sourceToParse().timestamp();
|
||||
if (!indexed() && !stored()) {
|
||||
context.ignoredValue(names.indexName(), String.valueOf(timestamp));
|
||||
return null;
|
||||
}
|
||||
return new LongFieldMapper.CustomLongNumericField(this, timestamp);
|
||||
return new LongFieldMapper.CustomLongNumericField(this, timestamp, fieldType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -206,16 +212,17 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
// if all are defaults, no sense to write it at all
|
||||
if (index == Defaults.INDEX && store == Defaults.STORE && enabled == Defaults.ENABLED && path == Defaults.PATH
|
||||
if (indexed() == Defaults.TIMESTAMP_FIELD_TYPE.indexed() &&
|
||||
stored() == Defaults.TIMESTAMP_FIELD_TYPE.stored() && enabled == Defaults.ENABLED && path == Defaults.PATH
|
||||
&& dateTimeFormatter.format().equals(Defaults.DATE_TIME_FORMATTER.format())) {
|
||||
return builder;
|
||||
}
|
||||
builder.startObject(CONTENT_TYPE);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.TIMESTAMP_FIELD_TYPE.indexed()) {
|
||||
builder.field("index", indexed());
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.TIMESTAMP_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (enabled != Defaults.ENABLED) {
|
||||
builder.field("enabled", enabled);
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.index.mapper.internal;
|
|||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.DeletionAwareConstantScoreQuery;
|
||||
|
@ -56,26 +56,29 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
|
|||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final String NAME = TypeFieldMapper.NAME;
|
||||
public static final String INDEX_NAME = TypeFieldMapper.NAME;
|
||||
public static final Field.Index INDEX = Field.Index.NOT_ANALYZED;
|
||||
public static final Field.Store STORE = Field.Store.NO;
|
||||
public static final boolean OMIT_NORMS = true;
|
||||
public static final IndexOptions INDEX_OPTIONS = IndexOptions.DOCS_ONLY;
|
||||
|
||||
public static final FieldType TYPE_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
TYPE_FIELD_TYPE.setIndexed(true);
|
||||
TYPE_FIELD_TYPE.setTokenized(false);
|
||||
TYPE_FIELD_TYPE.setStored(false);
|
||||
TYPE_FIELD_TYPE.setOmitNorms(true);
|
||||
TYPE_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
TYPE_FIELD_TYPE.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends AbstractFieldMapper.Builder<Builder, TypeFieldMapper> {
|
||||
|
||||
public Builder() {
|
||||
super(Defaults.NAME);
|
||||
super(Defaults.NAME, new FieldType(Defaults.TYPE_FIELD_TYPE));
|
||||
indexName = Defaults.INDEX_NAME;
|
||||
index = Defaults.INDEX;
|
||||
store = Defaults.STORE;
|
||||
omitNorms = Defaults.OMIT_NORMS;
|
||||
indexOptions = Defaults.INDEX_OPTIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeFieldMapper build(BuilderContext context) {
|
||||
return new TypeFieldMapper(name, indexName, index, store, termVector, boost, omitNorms, indexOptions);
|
||||
return new TypeFieldMapper(name, indexName, boost, fieldType);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,23 +97,21 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
|
|||
}
|
||||
|
||||
protected TypeFieldMapper(String name, String indexName) {
|
||||
this(name, indexName, Defaults.INDEX, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST,
|
||||
Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS);
|
||||
this(name, indexName, Defaults.BOOST, new FieldType(Defaults.TYPE_FIELD_TYPE));
|
||||
}
|
||||
|
||||
public TypeFieldMapper(String name, String indexName, Field.Index index, Field.Store store, Field.TermVector termVector,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions) {
|
||||
super(new Names(name, indexName, indexName, name), index, store, termVector, boost, omitNorms, indexOptions, Lucene.KEYWORD_ANALYZER,
|
||||
public TypeFieldMapper(String name, String indexName, float boost, FieldType fieldType) {
|
||||
super(new Names(name, indexName, indexName, name), boost, fieldType, Lucene.KEYWORD_ANALYZER,
|
||||
Lucene.KEYWORD_ANALYZER);
|
||||
}
|
||||
|
||||
public String value(Document document) {
|
||||
Fieldable field = document.getFieldable(names.indexName());
|
||||
Field field = (Field) document.getField(names.indexName());
|
||||
return field == null ? null : value(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value(Fieldable field) {
|
||||
public String value(Field field) {
|
||||
return field.stringValue();
|
||||
}
|
||||
|
||||
|
@ -120,7 +121,7 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return value(field);
|
||||
}
|
||||
|
||||
|
@ -135,8 +136,8 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
|
|||
|
||||
@Override
|
||||
public Filter fieldFilter(String value, @Nullable QueryParseContext context) {
|
||||
if (index == Field.Index.NO) {
|
||||
return new PrefixFilter(UidFieldMapper.TERM_FACTORY.createTerm(Uid.typePrefix(value)));
|
||||
if (!indexed()) {
|
||||
return new PrefixFilter(new Term(UidFieldMapper.NAME, Uid.typePrefix(value)));
|
||||
}
|
||||
return new TermFilter(names().createIndexNameTerm(value));
|
||||
}
|
||||
|
@ -176,10 +177,10 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
|
|||
|
||||
@Override
|
||||
protected Field parseCreateField(ParseContext context) throws IOException {
|
||||
if (index == Field.Index.NO && store == Field.Store.NO) {
|
||||
if (!indexed() && !stored()) {
|
||||
return null;
|
||||
}
|
||||
return new Field(names.indexName(), false, context.type(), store, index, termVector);
|
||||
return new Field(names.indexName(), context.type(), fieldType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -190,15 +191,15 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
// if all are defaults, no sense to write it at all
|
||||
if (store == Defaults.STORE && index == Defaults.INDEX) {
|
||||
if (stored() == Defaults.TYPE_FIELD_TYPE.stored() && indexed() == Defaults.TYPE_FIELD_TYPE.indexed()) {
|
||||
return builder;
|
||||
}
|
||||
builder.startObject(CONTENT_TYPE);
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.TYPE_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.TYPE_FIELD_TYPE.indexed()) {
|
||||
builder.field("index", indexed());
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.elasticsearch.index.mapper.internal;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
|
@ -47,9 +47,17 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
|
|||
|
||||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final String NAME = UidFieldMapper.NAME;
|
||||
public static final Field.Index INDEX = Field.Index.NOT_ANALYZED;
|
||||
public static final boolean OMIT_NORMS = true;
|
||||
public static final FieldInfo.IndexOptions INDEX_OPTIONS = FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; // we store payload (otherwise, we really need just docs)
|
||||
|
||||
public static final FieldType UID_FIELD_TYPE = new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
||||
|
||||
static {
|
||||
UID_FIELD_TYPE.setIndexed(true);
|
||||
UID_FIELD_TYPE.setTokenized(false);
|
||||
UID_FIELD_TYPE.setStored(true);
|
||||
UID_FIELD_TYPE.setOmitNorms(true);
|
||||
UID_FIELD_TYPE.setIndexOptions(FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); // we store payload (otherwise, we really need just docs)
|
||||
UID_FIELD_TYPE.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends Mapper.Builder<Builder, UidFieldMapper> {
|
||||
|
@ -90,8 +98,8 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
|
|||
}
|
||||
|
||||
protected UidFieldMapper(String name, String indexName) {
|
||||
super(new Names(name, indexName, indexName, name), Defaults.INDEX, Field.Store.YES, Defaults.TERM_VECTOR, Defaults.BOOST,
|
||||
Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER);
|
||||
super(new Names(name, indexName, indexName, name), Defaults.BOOST, new FieldType(Defaults.UID_FIELD_TYPE),
|
||||
Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -115,7 +123,7 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
|
|||
// since we did not have the uid in the pre phase, we did not add it automatically to the nested docs
|
||||
// as they were created we need to make sure we add it to all the nested docs...
|
||||
if (context.docs().size() > 1) {
|
||||
UidField uidField = (UidField) context.rootDoc().getFieldable(UidFieldMapper.NAME);
|
||||
UidField uidField = (UidField) context.rootDoc().getField(UidFieldMapper.NAME);
|
||||
assert uidField != null;
|
||||
// we need to go over the docs and add it...
|
||||
for (int i = 1; i < context.docs().size(); i++) {
|
||||
|
@ -141,7 +149,7 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Field parseCreateField(ParseContext context) throws IOException {
|
||||
context.uid(Uid.createUid(context.stringBuilder(), context.type(), context.id()));
|
||||
// so, caching uid stream and field is fine
|
||||
// since we don't do any mapping parsing without immediate indexing
|
||||
|
@ -152,7 +160,7 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
|
|||
}
|
||||
|
||||
@Override
|
||||
public Uid value(Fieldable field) {
|
||||
public Uid value(Field field) {
|
||||
return Uid.createUid(field.stringValue());
|
||||
}
|
||||
|
||||
|
@ -162,7 +170,7 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
|
|||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
return field.stringValue();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,11 @@ package org.elasticsearch.index.mapper.ip;
|
|||
|
||||
import org.apache.lucene.analysis.NumericTokenStream;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
|
@ -86,6 +88,12 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
public static class Defaults extends NumberFieldMapper.Defaults {
|
||||
public static final String NULL_VALUE = null;
|
||||
|
||||
public static final FieldType IP_FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.NUMBER_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
IP_FIELD_TYPE.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends NumberFieldMapper.Builder<Builder, IpFieldMapper> {
|
||||
|
@ -93,7 +101,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
protected String nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(Defaults.IP_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
|
@ -104,8 +112,9 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
@Override
|
||||
public IpFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
IpFieldMapper fieldMapper = new IpFieldMapper(buildNames(context),
|
||||
precisionStep, index, store, boost, omitNorms, indexOptions, nullValue, ignoreMalformed(context));
|
||||
precisionStep, boost, fieldType, nullValue, ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
}
|
||||
|
@ -130,10 +139,9 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
private String nullValue;
|
||||
|
||||
protected IpFieldMapper(Names names, int precisionStep,
|
||||
Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, IndexOptions indexOptions,
|
||||
float boost, FieldType fieldType,
|
||||
String nullValue, Explicit<Boolean> ignoreMalformed) {
|
||||
super(names, precisionStep, null, index, store, boost, omitNorms, indexOptions,
|
||||
super(names, precisionStep, null, boost, fieldType,
|
||||
ignoreMalformed, new NamedAnalyzer("_ip/" + precisionStep, new NumericIpAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_ip/max", new NumericIpAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
|
@ -145,8 +153,8 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Long value(Fieldable field) {
|
||||
byte[] value = field.getBinaryValue();
|
||||
public Long value(Field field) {
|
||||
byte[] value = field.binaryValue().bytes;
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -159,15 +167,15 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
/**
|
||||
* IPs should return as a string, delegates to {@link #valueAsString(org.apache.lucene.document.Fieldable)}.
|
||||
* IPs should return as a string.
|
||||
*/
|
||||
@Override
|
||||
public Object valueForSearch(Fieldable field) {
|
||||
public Object valueForSearch(Field field) {
|
||||
return valueAsString(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueAsString(Fieldable field) {
|
||||
public String valueAsString(Field field) {
|
||||
Long value = value(field);
|
||||
if (value == null) {
|
||||
return null;
|
||||
|
@ -177,7 +185,9 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
@Override
|
||||
public String indexedValue(String value) {
|
||||
return NumericUtils.longToPrefixCoded(ipToLong(value));
|
||||
BytesRef bytesRef = new BytesRef();
|
||||
NumericUtils.longToPrefixCoded(ipToLong(value), precisionStep(), bytesRef);
|
||||
return bytesRef.utf8ToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -241,7 +251,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
protected Field innerParseCreateField(ParseContext context) throws IOException {
|
||||
String ipAsString;
|
||||
if (context.externalValueSet()) {
|
||||
ipAsString = (String) context.externalValue();
|
||||
|
@ -264,7 +274,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
final long value = ipToLong(ipAsString);
|
||||
return new LongFieldMapper.CustomLongNumericField(this, value);
|
||||
return new LongFieldMapper.CustomLongNumericField(this, value, fieldType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -291,20 +301,30 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
if (index != Defaults.INDEX) {
|
||||
builder.field("index", index.name().toLowerCase());
|
||||
if (indexed() != Defaults.IP_FIELD_TYPE.indexed() ||
|
||||
analyzed() != Defaults.IP_FIELD_TYPE.tokenized()) {
|
||||
builder.field("index", indexTokenizeOptionToString(indexed(), analyzed()));
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.IP_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.IP_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (omitNorms != Defaults.OMIT_NORMS) {
|
||||
builder.field("omit_norms", omitNorms);
|
||||
if (storeTermVectorOffsets() != Defaults.IP_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (indexOptions != Defaults.INDEX_OPTIONS) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions));
|
||||
if (storeTermVectorPositions() != Defaults.IP_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.IP_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (omitNorms() != Defaults.IP_FIELD_TYPE.omitNorms()) {
|
||||
builder.field("omit_norms", omitNorms());
|
||||
}
|
||||
if (indexOptions() != Defaults.IP_FIELD_TYPE.indexOptions()) {
|
||||
builder.field("index_options", indexOptionToString(indexOptions()));
|
||||
}
|
||||
if (precisionStep != Defaults.PRECISION_STEP) {
|
||||
builder.field("precision_step", precisionStep);
|
||||
|
|
|
@ -22,7 +22,8 @@ package org.elasticsearch.index.mapper.object;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -304,7 +305,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
|
|||
this.mappers = copyOf(mappers);
|
||||
}
|
||||
this.nestedTypePath = "__" + fullPath;
|
||||
this.nestedTypeFilter = new TermFilter(TypeFieldMapper.TERM_FACTORY.createTerm(nestedTypePath));
|
||||
this.nestedTypeFilter = new TermFilter(new Term(TypeFieldMapper.NAME, nestedTypePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -412,7 +413,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
|
|||
if (nested.isNested()) {
|
||||
Document nestedDoc = new Document();
|
||||
// pre add the uid field if possible (id was already provided)
|
||||
Fieldable uidField = context.doc().getFieldable(UidFieldMapper.NAME);
|
||||
Field uidField = (Field) context.doc().getField(UidFieldMapper.NAME);
|
||||
if (uidField != null) {
|
||||
// we don't need to add it as a full uid field in nested docs, since we don't need versioning
|
||||
// we also rely on this for UidField#loadVersion
|
||||
|
@ -465,7 +466,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
|
|||
if (nested.isNested()) {
|
||||
Document nestedDoc = context.switchDoc(restoreDoc);
|
||||
if (nested.isIncludeInParent()) {
|
||||
for (Fieldable field : nestedDoc.getFields()) {
|
||||
for (IndexableField field : nestedDoc.getFields()) {
|
||||
if (field.name().equals(UidFieldMapper.NAME) || field.name().equals(TypeFieldMapper.NAME)) {
|
||||
continue;
|
||||
} else {
|
||||
|
@ -476,7 +477,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
|
|||
if (nested.isIncludeInRoot()) {
|
||||
// don't add it twice, if its included in parent, and we are handling the master doc...
|
||||
if (!(nested.isIncludeInParent() && context.doc() == context.rootDoc())) {
|
||||
for (Fieldable field : nestedDoc.getFields()) {
|
||||
for (IndexableField field : nestedDoc.getFields()) {
|
||||
if (field.name().equals(UidFieldMapper.NAME) || field.name().equals(TypeFieldMapper.NAME)) {
|
||||
continue;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue