-
Notifications
You must be signed in to change notification settings - Fork 25.2k
MappedFieldType should not extend FieldType #57666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
23a35eb
ac2cc4a
b18c1b9
344520b
b26fd80
f331482
a146b6f
fc79105
3772c31
bb8a244
5e6ce42
50d43a6
9b6ebdf
f71d49e
a5bbeee
39468c0
6816f5f
a9e36a7
f97840e
fd0e5e1
0ac318d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
*/ | ||
package org.elasticsearch.index.mapper; | ||
|
||
import org.apache.lucene.index.IndexOptions; | ||
import org.apache.lucene.document.FieldType; | ||
import org.apache.lucene.index.IndexableField; | ||
import org.apache.lucene.index.Term; | ||
import org.apache.lucene.search.DocValuesFieldExistsQuery; | ||
|
@@ -58,6 +58,11 @@ public static class Names { | |
public static class Defaults { | ||
public static final Explicit<Boolean> IGNORE_MALFORMED = new Explicit<>(false, false); | ||
public static final Explicit<Boolean> IGNORE_Z_VALUE = new Explicit<>(true, false); | ||
public static final FieldType FIELD_TYPE = new FieldType(); | ||
static { | ||
FIELD_TYPE.setStored(false); | ||
FIELD_TYPE.freeze(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -76,18 +81,19 @@ public interface Parser<Parsed> { | |
Parsed parse(XContentParser parser, AbstractGeometryFieldMapper mapper) throws IOException, ParseException; | ||
} | ||
|
||
public abstract static class Builder<T extends Builder, FT extends AbstractGeometryFieldType> | ||
public abstract static class Builder<T extends Builder<T, FT>, FT extends AbstractGeometryFieldType> | ||
extends FieldMapper.Builder<T> { | ||
protected Boolean ignoreMalformed; | ||
protected Boolean ignoreZValue; | ||
protected boolean indexed = true; | ||
|
||
public Builder(String name, MappedFieldType fieldType, MappedFieldType defaultFieldType) { | ||
super(name, fieldType, defaultFieldType); | ||
public Builder(String name, FieldType fieldType) { | ||
super(name, fieldType); | ||
} | ||
|
||
public Builder(String name, MappedFieldType fieldType, MappedFieldType defaultFieldType, boolean ignoreMalformed, | ||
public Builder(String name, FieldType fieldType, boolean ignoreMalformed, | ||
boolean ignoreZValue) { | ||
super(name, fieldType, defaultFieldType); | ||
super(name, fieldType); | ||
this.ignoreMalformed = ignoreMalformed; | ||
this.ignoreZValue = ignoreZValue; | ||
} | ||
|
@@ -132,30 +138,6 @@ public Builder ignoreZValue(final boolean ignoreZValue) { | |
this.ignoreZValue = ignoreZValue; | ||
return this; | ||
} | ||
|
||
@Override | ||
protected void setupFieldType(BuilderContext context) { | ||
super.setupFieldType(context); | ||
|
||
// field mapper handles this at build time | ||
// but prefix tree strategies require a name, so throw a similar exception | ||
if (name().isEmpty()) { | ||
throw new IllegalArgumentException("name cannot be empty string"); | ||
} | ||
|
||
setGeometryParser(); | ||
setGeometryIndexer(fieldType()); | ||
setGeometryQueryBuilder(fieldType()); | ||
} | ||
|
||
@Override | ||
public FT fieldType() { | ||
return (FT)fieldType; | ||
} | ||
|
||
protected abstract void setGeometryParser(); | ||
protected abstract void setGeometryIndexer(FT fieldType); | ||
protected abstract void setGeometryQueryBuilder(FT fieldType); | ||
} | ||
|
||
public abstract static class TypeParser<T extends Builder> implements Mapper.TypeParser { | ||
|
@@ -202,12 +184,8 @@ public abstract static class AbstractGeometryFieldType<Parsed, Processed> extend | |
protected Parser<Parsed> geometryParser; | ||
protected QueryProcessor geometryQueryBuilder; | ||
|
||
protected AbstractGeometryFieldType() { | ||
setIndexOptions(IndexOptions.DOCS); | ||
setTokenized(false); | ||
setStored(false); | ||
setStoreTermVectors(false); | ||
setOmitNorms(true); | ||
protected AbstractGeometryFieldType(String name, boolean indexed, boolean hasDocValues, Map<String, String> meta) { | ||
super(name, indexed, hasDocValues, meta); | ||
} | ||
|
||
protected AbstractGeometryFieldType(AbstractGeometryFieldType ref) { | ||
|
@@ -226,7 +204,7 @@ protected Indexer<Parsed, Processed> geometryIndexer() { | |
return geometryIndexer; | ||
} | ||
|
||
public void setGeometryParser(Parser geometryParser) { | ||
public void setGeometryParser(Parser<Parsed> geometryParser) { | ||
this.geometryParser = geometryParser; | ||
} | ||
|
||
|
@@ -271,10 +249,10 @@ public Query termQuery(Object value, QueryShardContext context) { | |
protected Explicit<Boolean> ignoreMalformed; | ||
protected Explicit<Boolean> ignoreZValue; | ||
|
||
protected AbstractGeometryFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, | ||
protected AbstractGeometryFieldMapper(String simpleName, FieldType fieldType, MappedFieldType mappedFieldType, | ||
Settings indexSettings, Explicit<Boolean> ignoreMalformed, | ||
Explicit<Boolean> ignoreZValue, MultiFields multiFields, CopyTo copyTo) { | ||
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); | ||
super(simpleName, fieldType, mappedFieldType, indexSettings, multiFields, copyTo); | ||
this.ignoreMalformed = ignoreMalformed; | ||
this.ignoreZValue = ignoreZValue; | ||
} | ||
|
@@ -293,7 +271,7 @@ protected void mergeOptions(FieldMapper other, List<String> conflicts) { | |
|
||
@Override | ||
public AbstractGeometryFieldType fieldType() { | ||
return (AbstractGeometryFieldType)fieldType; | ||
return (AbstractGeometryFieldType)mappedFieldType; | ||
} | ||
|
||
@Override | ||
|
@@ -308,10 +286,10 @@ protected void parseCreateField(ParseContext context) throws IOException { | |
/** parsing logic for geometry indexing */ | ||
@Override | ||
public void parse(ParseContext context) throws IOException { | ||
AbstractGeometryFieldMapper.AbstractGeometryFieldType fieldType = fieldType(); | ||
AbstractGeometryFieldMapper.AbstractGeometryFieldType mappedFieldType = fieldType(); | ||
|
||
@SuppressWarnings("unchecked") Indexer<Parsed, Processed> geometryIndexer = fieldType.geometryIndexer(); | ||
@SuppressWarnings("unchecked") Parser<Parsed> geometryParser = fieldType.geometryParser(); | ||
@SuppressWarnings("unchecked") Indexer<Parsed, Processed> geometryIndexer = mappedFieldType.geometryIndexer(); | ||
@SuppressWarnings("unchecked") Parser<Parsed> geometryParser = mappedFieldType.geometryParser(); | ||
try { | ||
Processed shape = context.parseExternalValue(geometryIndexer.processedClass()); | ||
if (shape == null) { | ||
|
@@ -323,13 +301,13 @@ public void parse(ParseContext context) throws IOException { | |
} | ||
|
||
List<IndexableField> fields = new ArrayList<>(); | ||
if (fieldType.indexOptions() != IndexOptions.NONE || fieldType.hasDocValues()) { | ||
if (mappedFieldType.isSearchable() || mappedFieldType.hasDocValues()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens with these checks once isSearchable returns true yet there is no index? Do we need to distinguish between the two? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will need to distinguish between them in the future, yes. This is something of a shim though - the plan is to eventually move everything to parametrized mappers (see #58663) which will change how this works again. |
||
fields.addAll(geometryIndexer.indexShape(context, shape)); | ||
} | ||
|
||
// indexed: | ||
List<IndexableField> indexedFields = new ArrayList<>(); | ||
if (fieldType.indexOptions() != IndexOptions.NONE) { | ||
if (mappedFieldType.isSearchable()) { | ||
indexedFields.addAll(fields); | ||
} | ||
// stored: | ||
|
@@ -338,8 +316,8 @@ public void parse(ParseContext context) throws IOException { | |
} | ||
// docValues: | ||
if (fieldType().hasDocValues()) { | ||
addDocValuesFields(fieldType.name(), shape, fields, context); | ||
} else if (fieldType.stored() || fieldType.indexOptions() != IndexOptions.NONE) { | ||
addDocValuesFields(mappedFieldType.name(), shape, fields, context); | ||
} else if (fieldType.stored() || fieldType().isSearchable()) { | ||
createFieldNamesField(context); | ||
} | ||
|
||
|
@@ -355,7 +333,7 @@ public void parse(ParseContext context) throws IOException { | |
throw new MapperParsingException("failed to parse field [{}] of type [{}]", e, fieldType().name(), | ||
fieldType().typeName()); | ||
} | ||
context.addIgnoredField(fieldType.name()); | ||
context.addIgnoredField(mappedFieldType.name()); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I super hate all of these
instanceof
s!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you are making it better.