Simplify inclusion in `_all`. #20028

Currently, when you set `include_in_all` on an object, it will propagate the
information to its sub mappers immediately. This is annoying because this is
done using a different mechanism than regular mapping updates.

This PR changes object fields to propagate the information at document parsing
time rather than when `include_an_all` is updated. While moving this cost to
document parsing time rather than mapping update time is probably a bad
trade-off, I am confident that this cost is very low and think this new way
makes things simpler.
This commit is contained in:
Adrien Grand 2016-08-17 16:47:03 +02:00
parent f6b166f19e
commit a7a7123d74
24 changed files with 173 additions and 446 deletions

View File

@ -47,28 +47,6 @@ import static org.elasticsearch.index.mapper.TypeParsers.parseTextField;
*/ */
public class AllFieldMapper extends MetadataFieldMapper { public class AllFieldMapper extends MetadataFieldMapper {
public interface IncludeInAll {
/**
* If {@code includeInAll} is not null then return a copy of this mapper
* that will include values in the _all field according to {@code includeInAll}.
*/
Mapper includeInAll(Boolean includeInAll);
/**
* If {@code includeInAll} is not null and not set on this mapper yet, then
* return a copy of this mapper that will include values in the _all field
* according to {@code includeInAll}.
*/
Mapper includeInAllIfNotSet(Boolean includeInAll);
/**
* If {@code includeInAll} was already set on this mapper then return a copy
* of this mapper that has {@code includeInAll} not set.
*/
Mapper unsetIncludeInAll();
}
public static final String NAME = "_all"; public static final String NAME = "_all";
public static final String CONTENT_TYPE = "_all"; public static final String CONTENT_TYPE = "_all";

View File

@ -37,7 +37,6 @@ import org.elasticsearch.common.joda.DateMathParser;
import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.joda.Joda; import org.elasticsearch.common.joda.Joda;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.util.LocaleUtils; import org.elasticsearch.common.util.LocaleUtils;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData;
@ -60,7 +59,7 @@ import java.util.concurrent.Callable;
import static org.elasticsearch.index.mapper.TypeParsers.parseDateTimeFormatter; import static org.elasticsearch.index.mapper.TypeParsers.parseDateTimeFormatter;
/** A {@link FieldMapper} for ip addresses. */ /** A {@link FieldMapper} for ip addresses. */
public class DateFieldMapper extends FieldMapper implements AllFieldMapper.IncludeInAll { public class DateFieldMapper extends FieldMapper {
public static final String CONTENT_TYPE = "date"; public static final String CONTENT_TYPE = "date";
public static final FormatDateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = Joda.forPattern( public static final FormatDateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = Joda.forPattern(
@ -119,9 +118,8 @@ public class DateFieldMapper extends FieldMapper implements AllFieldMapper.Inclu
@Override @Override
public DateFieldMapper build(BuilderContext context) { public DateFieldMapper build(BuilderContext context) {
setupFieldType(context); setupFieldType(context);
DateFieldMapper fieldMapper = new DateFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), return new DateFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context),
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (DateFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
} }
@ -473,11 +471,13 @@ public class DateFieldMapper extends FieldMapper implements AllFieldMapper.Inclu
MappedFieldType fieldType, MappedFieldType fieldType,
MappedFieldType defaultFieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> ignoreMalformed,
Boolean includeInAll,
Settings indexSettings, Settings indexSettings,
MultiFields multiFields, MultiFields multiFields,
CopyTo copyTo) { CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
this.ignoreMalformed = ignoreMalformed; this.ignoreMalformed = ignoreMalformed;
this.includeInAll = includeInAll;
} }
@Override @Override
@ -495,39 +495,6 @@ public class DateFieldMapper extends FieldMapper implements AllFieldMapper.Inclu
return (DateFieldMapper) super.clone(); return (DateFieldMapper) super.clone();
} }
@Override
public Mapper includeInAll(Boolean includeInAll) {
if (includeInAll != null) {
DateFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper includeInAllIfNotSet(Boolean includeInAll) {
if (includeInAll != null && this.includeInAll == null) {
DateFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper unsetIncludeInAll() {
if (includeInAll != null) {
DateFieldMapper clone = clone();
clone.includeInAll = null;
return clone;
} else {
return this;
}
}
@Override @Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException { protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
String dateAsString; String dateAsString;

View File

@ -343,6 +343,12 @@ final class DocumentParser {
context = nestedContext(context, mapper); context = nestedContext(context, mapper);
} }
// update the default value of include_in_all if necessary
Boolean includeInAll = mapper.includeInAll();
if (includeInAll != null) {
context = context.setIncludeInAllDefault(includeInAll);
}
// if we are at the end of the previous object, advance // if we are at the end of the previous object, advance
if (token == XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.END_OBJECT) {
token = parser.nextToken(); token = parser.nextToken();

View File

@ -537,11 +537,7 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
ImmutableOpenMap.Builder<String, FieldMapper> builder = new ImmutableOpenMap.Builder<>(); ImmutableOpenMap.Builder<String, FieldMapper> builder = new ImmutableOpenMap.Builder<>();
// we disable the all in multi-field mappers // we disable the all in multi-field mappers
for (ObjectObjectCursor<String, FieldMapper> cursor : mappers) { for (ObjectObjectCursor<String, FieldMapper> cursor : mappers) {
FieldMapper mapper = cursor.value; builder.put(cursor.key, cursor.value);
if (mapper instanceof AllFieldMapper.IncludeInAll) {
mapper = (FieldMapper) ((AllFieldMapper.IncludeInAll) mapper).unsetIncludeInAll();
}
builder.put(cursor.key, mapper);
} }
this.mappers = builder.build(); this.mappers = builder.build();
} }
@ -568,10 +564,6 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
FieldMapper mergeWithMapper = cursor.value; FieldMapper mergeWithMapper = cursor.value;
FieldMapper mergeIntoMapper = mappers.get(mergeWithMapper.simpleName()); FieldMapper mergeIntoMapper = mappers.get(mergeWithMapper.simpleName());
if (mergeIntoMapper == null) { if (mergeIntoMapper == null) {
// we disable the all in multi-field mappers
if (mergeWithMapper instanceof AllFieldMapper.IncludeInAll) {
mergeWithMapper = (FieldMapper) ((AllFieldMapper.IncludeInAll) mergeWithMapper).unsetIncludeInAll();
}
newMappersBuilder.put(mergeWithMapper.simpleName(), mergeWithMapper); newMappersBuilder.put(mergeWithMapper.simpleName(), mergeWithMapper);
} else { } else {
FieldMapper merged = mergeIntoMapper.merge(mergeWithMapper, false); FieldMapper merged = mergeIntoMapper.merge(mergeWithMapper, false);

View File

@ -50,7 +50,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** A {@link FieldMapper} for ip addresses. */ /** A {@link FieldMapper} for ip addresses. */
public class IpFieldMapper extends FieldMapper implements AllFieldMapper.IncludeInAll { public class IpFieldMapper extends FieldMapper {
public static final String CONTENT_TYPE = "ip"; public static final String CONTENT_TYPE = "ip";
@ -81,9 +81,8 @@ public class IpFieldMapper extends FieldMapper implements AllFieldMapper.Include
@Override @Override
public IpFieldMapper build(BuilderContext context) { public IpFieldMapper build(BuilderContext context) {
setupFieldType(context); setupFieldType(context);
IpFieldMapper fieldMapper = new IpFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), return new IpFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context),
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (IpFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
} }
@ -261,11 +260,13 @@ public class IpFieldMapper extends FieldMapper implements AllFieldMapper.Include
MappedFieldType fieldType, MappedFieldType fieldType,
MappedFieldType defaultFieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> ignoreMalformed,
Boolean includeInAll,
Settings indexSettings, Settings indexSettings,
MultiFields multiFields, MultiFields multiFields,
CopyTo copyTo) { CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
this.ignoreMalformed = ignoreMalformed; this.ignoreMalformed = ignoreMalformed;
this.includeInAll = includeInAll;
} }
@Override @Override
@ -283,39 +284,6 @@ public class IpFieldMapper extends FieldMapper implements AllFieldMapper.Include
return (IpFieldMapper) super.clone(); return (IpFieldMapper) super.clone();
} }
@Override
public Mapper includeInAll(Boolean includeInAll) {
if (includeInAll != null) {
IpFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper includeInAllIfNotSet(Boolean includeInAll) {
if (includeInAll != null && this.includeInAll == null) {
IpFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper unsetIncludeInAll() {
if (includeInAll != null) {
IpFieldMapper clone = clone();
clone.includeInAll = null;
return clone;
} else {
return this;
}
}
@Override @Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException { protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
Object addressAsObject; Object addressAsObject;

View File

@ -41,7 +41,7 @@ import static org.elasticsearch.index.mapper.TypeParsers.parseField;
/** /**
* A field mapper for keywords. This mapper accepts strings and indexes them as-is. * A field mapper for keywords. This mapper accepts strings and indexes them as-is.
*/ */
public final class KeywordFieldMapper extends FieldMapper implements AllFieldMapper.IncludeInAll { public final class KeywordFieldMapper extends FieldMapper {
public static final String CONTENT_TYPE = "keyword"; public static final String CONTENT_TYPE = "keyword";
@ -94,10 +94,9 @@ public final class KeywordFieldMapper extends FieldMapper implements AllFieldMap
@Override @Override
public KeywordFieldMapper build(BuilderContext context) { public KeywordFieldMapper build(BuilderContext context) {
setupFieldType(context); setupFieldType(context);
KeywordFieldMapper fieldMapper = new KeywordFieldMapper( return new KeywordFieldMapper(
name, fieldType, defaultFieldType, ignoreAbove, name, fieldType, defaultFieldType, ignoreAbove, includeInAll,
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return fieldMapper.includeInAll(includeInAll);
} }
} }
@ -177,10 +176,11 @@ public final class KeywordFieldMapper extends FieldMapper implements AllFieldMap
private int ignoreAbove; private int ignoreAbove;
protected KeywordFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, protected KeywordFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
int ignoreAbove, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { int ignoreAbove, Boolean includeInAll, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
assert fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) <= 0; assert fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) <= 0;
this.ignoreAbove = ignoreAbove; this.ignoreAbove = ignoreAbove;
this.includeInAll = includeInAll;
} }
/** Values that have more chars than the return value of this method will /** Values that have more chars than the return value of this method will
@ -200,39 +200,6 @@ public final class KeywordFieldMapper extends FieldMapper implements AllFieldMap
return includeInAll; return includeInAll;
} }
@Override
public KeywordFieldMapper includeInAll(Boolean includeInAll) {
if (includeInAll != null) {
KeywordFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public KeywordFieldMapper includeInAllIfNotSet(Boolean includeInAll) {
if (includeInAll != null && this.includeInAll == null) {
KeywordFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public KeywordFieldMapper unsetIncludeInAll() {
if (includeInAll != null) {
KeywordFieldMapper clone = clone();
clone.includeInAll = null;
return clone;
} else {
return this;
}
}
@Override @Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException { protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
final String value; final String value;

View File

@ -75,9 +75,8 @@ public class LegacyByteFieldMapper extends LegacyNumberFieldMapper {
throw new IllegalStateException("Cannot use legacy numeric types after 5.0"); throw new IllegalStateException("Cannot use legacy numeric types after 5.0");
} }
setupFieldType(context); setupFieldType(context);
LegacyByteFieldMapper fieldMapper = new LegacyByteFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), return new LegacyByteFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context),
coerce(context), context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); coerce(context), includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (LegacyByteFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
@Override @Override
@ -176,9 +175,9 @@ public class LegacyByteFieldMapper extends LegacyNumberFieldMapper {
} }
protected LegacyByteFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, protected LegacyByteFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Boolean includeInAll,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, includeInAll, indexSettings, multiFields, copyTo);
} }
@Override @Override

View File

@ -36,7 +36,6 @@ import org.elasticsearch.common.joda.DateMathParser;
import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.joda.Joda; import org.elasticsearch.common.joda.Joda;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.util.LocaleUtils; import org.elasticsearch.common.util.LocaleUtils;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -116,9 +115,8 @@ public class LegacyDateFieldMapper extends LegacyNumberFieldMapper {
} }
setupFieldType(context); setupFieldType(context);
fieldType.setNullValue(nullValue); fieldType.setNullValue(nullValue);
LegacyDateFieldMapper fieldMapper = new LegacyDateFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), return new LegacyDateFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context),
coerce(context), context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); coerce(context), includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (LegacyDateFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
@Override @Override
@ -467,8 +465,8 @@ public class LegacyDateFieldMapper extends LegacyNumberFieldMapper {
} }
protected LegacyDateFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Explicit<Boolean> ignoreMalformed,Explicit<Boolean> coerce, protected LegacyDateFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Explicit<Boolean> ignoreMalformed,Explicit<Boolean> coerce,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Boolean includeInAll, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, includeInAll, indexSettings, multiFields, copyTo);
} }
@Override @Override

View File

@ -78,9 +78,8 @@ public class LegacyDoubleFieldMapper extends LegacyNumberFieldMapper {
throw new IllegalStateException("Cannot use legacy numeric types after 5.0"); throw new IllegalStateException("Cannot use legacy numeric types after 5.0");
} }
setupFieldType(context); setupFieldType(context);
LegacyDoubleFieldMapper fieldMapper = new LegacyDoubleFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), coerce(context), return new LegacyDoubleFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), coerce(context),
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (LegacyDoubleFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
@Override @Override
@ -187,8 +186,8 @@ public class LegacyDoubleFieldMapper extends LegacyNumberFieldMapper {
} }
protected LegacyDoubleFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Explicit<Boolean> ignoreMalformed, protected LegacyDoubleFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Explicit<Boolean> ignoreMalformed,
Explicit<Boolean> coerce, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Explicit<Boolean> coerce, Boolean includeInAll, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, includeInAll, indexSettings, multiFields, copyTo);
} }
@Override @Override

View File

@ -77,9 +77,8 @@ public class LegacyFloatFieldMapper extends LegacyNumberFieldMapper {
throw new IllegalStateException("Cannot use legacy numeric types after 5.0"); throw new IllegalStateException("Cannot use legacy numeric types after 5.0");
} }
setupFieldType(context); setupFieldType(context);
LegacyFloatFieldMapper fieldMapper = new LegacyFloatFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), coerce(context), return new LegacyFloatFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), coerce(context),
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (LegacyFloatFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
@Override @Override
@ -171,9 +170,9 @@ public class LegacyFloatFieldMapper extends LegacyNumberFieldMapper {
} }
protected LegacyFloatFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, protected LegacyFloatFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Boolean includeInAll,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, includeInAll, indexSettings, multiFields, copyTo);
} }
@Override @Override

View File

@ -81,10 +81,9 @@ public class LegacyIntegerFieldMapper extends LegacyNumberFieldMapper {
throw new IllegalStateException("Cannot use legacy numeric types after 5.0"); throw new IllegalStateException("Cannot use legacy numeric types after 5.0");
} }
setupFieldType(context); setupFieldType(context);
LegacyIntegerFieldMapper fieldMapper = new LegacyIntegerFieldMapper(name, fieldType, defaultFieldType, return new LegacyIntegerFieldMapper(name, fieldType, defaultFieldType,
ignoreMalformed(context), coerce(context), ignoreMalformed(context), coerce(context), includeInAll,
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (LegacyIntegerFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
@Override @Override
protected int maxPrecisionStep() { protected int maxPrecisionStep() {
@ -175,9 +174,9 @@ public class LegacyIntegerFieldMapper extends LegacyNumberFieldMapper {
} }
protected LegacyIntegerFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, protected LegacyIntegerFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Boolean includeInAll,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, includeInAll, indexSettings, multiFields, copyTo);
} }
@Override @Override

View File

@ -117,9 +117,8 @@ public class LegacyIpFieldMapper extends LegacyNumberFieldMapper {
throw new IllegalStateException("Cannot use legacy numeric types after 5.0"); throw new IllegalStateException("Cannot use legacy numeric types after 5.0");
} }
setupFieldType(context); setupFieldType(context);
LegacyIpFieldMapper fieldMapper = new LegacyIpFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), return new LegacyIpFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context),
coerce(context), context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); coerce(context), includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (LegacyIpFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
@Override @Override
@ -267,9 +266,9 @@ public class LegacyIpFieldMapper extends LegacyNumberFieldMapper {
} }
protected LegacyIpFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, protected LegacyIpFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Boolean includeInAll,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, includeInAll, indexSettings, multiFields, copyTo);
} }
private static long parseValue(Object value) { private static long parseValue(Object value) {

View File

@ -81,9 +81,9 @@ public class LegacyLongFieldMapper extends LegacyNumberFieldMapper {
throw new IllegalStateException("Cannot use legacy numeric types after 5.0"); throw new IllegalStateException("Cannot use legacy numeric types after 5.0");
} }
setupFieldType(context); setupFieldType(context);
LegacyLongFieldMapper fieldMapper = new LegacyLongFieldMapper(name, fieldType, defaultFieldType, return new LegacyLongFieldMapper(name, fieldType, defaultFieldType,
ignoreMalformed(context), coerce(context), context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); ignoreMalformed(context), coerce(context), includeInAll, context.indexSettings(),
return (LegacyLongFieldMapper) fieldMapper.includeInAll(includeInAll); multiFieldsBuilder.build(this, context), copyTo);
} }
@Override @Override
@ -175,9 +175,9 @@ public class LegacyLongFieldMapper extends LegacyNumberFieldMapper {
} }
protected LegacyLongFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, protected LegacyLongFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Boolean includeInAll,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, includeInAll, indexSettings, multiFields, copyTo);
} }
@Override @Override

View File

@ -40,7 +40,7 @@ import org.joda.time.DateTimeZone;
/** /**
* *
*/ */
public abstract class LegacyNumberFieldMapper extends FieldMapper implements AllFieldMapper.IncludeInAll { public abstract class LegacyNumberFieldMapper extends FieldMapper {
// this is private since it has a different default // this is private since it has a different default
private static final Setting<Boolean> COERCE_SETTING = private static final Setting<Boolean> COERCE_SETTING =
Setting.boolSetting("index.mapping.coerce", true, Property.IndexScope); Setting.boolSetting("index.mapping.coerce", true, Property.IndexScope);
@ -158,12 +158,13 @@ public abstract class LegacyNumberFieldMapper extends FieldMapper implements All
protected Explicit<Boolean> coerce; protected Explicit<Boolean> coerce;
protected LegacyNumberFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, protected LegacyNumberFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Settings indexSettings, Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Boolean includeInAll,
MultiFields multiFields, CopyTo copyTo) { Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
assert fieldType.tokenized() == false; assert fieldType.tokenized() == false;
this.ignoreMalformed = ignoreMalformed; this.ignoreMalformed = ignoreMalformed;
this.coerce = coerce; this.coerce = coerce;
this.includeInAll = includeInAll;
} }
@Override @Override
@ -171,39 +172,6 @@ public abstract class LegacyNumberFieldMapper extends FieldMapper implements All
return (LegacyNumberFieldMapper) super.clone(); return (LegacyNumberFieldMapper) super.clone();
} }
@Override
public Mapper includeInAll(Boolean includeInAll) {
if (includeInAll != null) {
LegacyNumberFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper includeInAllIfNotSet(Boolean includeInAll) {
if (includeInAll != null && this.includeInAll == null) {
LegacyNumberFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper unsetIncludeInAll() {
if (includeInAll != null) {
LegacyNumberFieldMapper clone = clone();
clone.includeInAll = null;
return clone;
} else {
return this;
}
}
@Override @Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException { protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
RuntimeException e = null; RuntimeException e = null;

View File

@ -34,7 +34,6 @@ import org.elasticsearch.Version;
import org.elasticsearch.action.fieldstats.FieldStats; import org.elasticsearch.action.fieldstats.FieldStats;
import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Explicit;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData;
@ -78,10 +77,9 @@ public class LegacyShortFieldMapper extends LegacyNumberFieldMapper {
throw new IllegalStateException("Cannot use legacy numeric types after 5.0"); throw new IllegalStateException("Cannot use legacy numeric types after 5.0");
} }
setupFieldType(context); setupFieldType(context);
LegacyShortFieldMapper fieldMapper = new LegacyShortFieldMapper(name, fieldType, defaultFieldType, return new LegacyShortFieldMapper(name, fieldType, defaultFieldType,
ignoreMalformed(context), coerce(context), ignoreMalformed(context), coerce(context), includeInAll,
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (LegacyShortFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
@Override @Override
@ -181,9 +179,9 @@ public class LegacyShortFieldMapper extends LegacyNumberFieldMapper {
} }
protected LegacyShortFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, protected LegacyShortFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Explicit<Boolean> ignoreMalformed, Explicit<Boolean> coerce, Boolean includeInAll,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, includeInAll, indexSettings, multiFields, copyTo);
} }
@Override @Override

View File

@ -73,10 +73,9 @@ public class LegacyTokenCountFieldMapper extends LegacyIntegerFieldMapper {
throw new IllegalStateException("Cannot use legacy numeric types after 5.0"); throw new IllegalStateException("Cannot use legacy numeric types after 5.0");
} }
setupFieldType(context); setupFieldType(context);
LegacyTokenCountFieldMapper fieldMapper = new LegacyTokenCountFieldMapper(name, fieldType, defaultFieldType, return new LegacyTokenCountFieldMapper(name, fieldType, defaultFieldType,
ignoreMalformed(context), coerce(context), context.indexSettings(), ignoreMalformed(context), coerce(context), includeInAll, context.indexSettings(),
analyzer, multiFieldsBuilder.build(this, context), copyTo); analyzer, multiFieldsBuilder.build(this, context), copyTo);
return (LegacyTokenCountFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
@Override @Override
@ -117,8 +116,8 @@ public class LegacyTokenCountFieldMapper extends LegacyIntegerFieldMapper {
private NamedAnalyzer analyzer; private NamedAnalyzer analyzer;
protected LegacyTokenCountFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Explicit<Boolean> ignoreMalformed, protected LegacyTokenCountFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Explicit<Boolean> ignoreMalformed,
Explicit<Boolean> coerce, Settings indexSettings, NamedAnalyzer analyzer, MultiFields multiFields, CopyTo copyTo) { Explicit<Boolean> coerce, Boolean includeInAll, Settings indexSettings, NamedAnalyzer analyzer, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, ignoreMalformed, coerce, includeInAll, indexSettings, multiFields, copyTo);
this.analyzer = analyzer; this.analyzer = analyzer;
} }

View File

@ -60,7 +60,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** A {@link FieldMapper} for numeric types: byte, short, int, long, float and double. */ /** A {@link FieldMapper} for numeric types: byte, short, int, long, float and double. */
public class NumberFieldMapper extends FieldMapper implements AllFieldMapper.IncludeInAll { public class NumberFieldMapper extends FieldMapper {
// this is private since it has a different default // this is private since it has a different default
static final Setting<Boolean> COERCE_SETTING = static final Setting<Boolean> COERCE_SETTING =
@ -114,10 +114,8 @@ public class NumberFieldMapper extends FieldMapper implements AllFieldMapper.Inc
@Override @Override
public NumberFieldMapper build(BuilderContext context) { public NumberFieldMapper build(BuilderContext context) {
setupFieldType(context); setupFieldType(context);
NumberFieldMapper fieldMapper = return new NumberFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context),
new NumberFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), coerce(context), includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
coerce(context), context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (NumberFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
} }
@ -871,12 +869,14 @@ public class NumberFieldMapper extends FieldMapper implements AllFieldMapper.Inc
MappedFieldType defaultFieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> ignoreMalformed,
Explicit<Boolean> coerce, Explicit<Boolean> coerce,
Boolean includeInAll,
Settings indexSettings, Settings indexSettings,
MultiFields multiFields, MultiFields multiFields,
CopyTo copyTo) { CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
this.ignoreMalformed = ignoreMalformed; this.ignoreMalformed = ignoreMalformed;
this.coerce = coerce; this.coerce = coerce;
this.includeInAll = includeInAll;
} }
@Override @Override
@ -894,39 +894,6 @@ public class NumberFieldMapper extends FieldMapper implements AllFieldMapper.Inc
return (NumberFieldMapper) super.clone(); return (NumberFieldMapper) super.clone();
} }
@Override
public Mapper includeInAll(Boolean includeInAll) {
if (includeInAll != null) {
NumberFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper includeInAllIfNotSet(Boolean includeInAll) {
if (includeInAll != null && this.includeInAll == null) {
NumberFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper unsetIncludeInAll() {
if (includeInAll != null) {
NumberFieldMapper clone = clone();
clone.includeInAll = null;
return clone;
} else {
return this;
}
}
@Override @Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException { protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
XContentParser parser = context.parser(); XContentParser parser = context.parser();

View File

@ -25,7 +25,6 @@ import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.CopyOnWriteHashMap; import org.elasticsearch.common.collect.CopyOnWriteHashMap;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
@ -47,7 +46,7 @@ import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenien
/** /**
* *
*/ */
public class ObjectMapper extends Mapper implements AllFieldMapper.IncludeInAll, Cloneable { public class ObjectMapper extends Mapper implements Cloneable {
public static final String CONTENT_TYPE = "object"; public static final String CONTENT_TYPE = "object";
public static final String NESTED_CONTENT_TYPE = "nested"; public static final String NESTED_CONTENT_TYPE = "nested";
@ -154,14 +153,15 @@ public class ObjectMapper extends Mapper implements AllFieldMapper.IncludeInAll,
} }
context.path().remove(); context.path().remove();
ObjectMapper objectMapper = createMapper(name, context.path().pathAsText(name), enabled, nested, dynamic, mappers, context.indexSettings()); ObjectMapper objectMapper = createMapper(name, context.path().pathAsText(name), enabled, nested, dynamic,
objectMapper = objectMapper.includeInAllIfNotSet(includeInAll); includeInAll, mappers, context.indexSettings());
return (Y) objectMapper; return (Y) objectMapper;
} }
protected ObjectMapper createMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic, Map<String, Mapper> mappers, @Nullable Settings settings) { protected ObjectMapper createMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic,
return new ObjectMapper(name, fullPath, enabled, nested, dynamic, mappers); Boolean includeInAll, Map<String, Mapper> mappers, @Nullable Settings settings) {
return new ObjectMapper(name, fullPath, enabled, nested, dynamic, includeInAll, mappers);
} }
} }
@ -322,12 +322,14 @@ public class ObjectMapper extends Mapper implements AllFieldMapper.IncludeInAll,
private volatile CopyOnWriteHashMap<String, Mapper> mappers; private volatile CopyOnWriteHashMap<String, Mapper> mappers;
ObjectMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic, Map<String, Mapper> mappers) { ObjectMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic,
Boolean includeInAll, Map<String, Mapper> mappers) {
super(name); super(name);
this.fullPath = fullPath; this.fullPath = fullPath;
this.enabled = enabled; this.enabled = enabled;
this.nested = nested; this.nested = nested;
this.dynamic = dynamic; this.dynamic = dynamic;
this.includeInAll = includeInAll;
if (mappers == null) { if (mappers == null) {
this.mappers = new CopyOnWriteHashMap<>(); this.mappers = new CopyOnWriteHashMap<>();
} else { } else {
@ -373,68 +375,19 @@ public class ObjectMapper extends Mapper implements AllFieldMapper.IncludeInAll,
return mappers.get(field); return mappers.get(field);
} }
@Override
public ObjectMapper includeInAll(Boolean includeInAll) {
if (includeInAll == null) {
return this;
}
ObjectMapper clone = clone();
clone.includeInAll = includeInAll;
// when called from outside, apply this on all the inner mappers
for (Mapper mapper : clone.mappers.values()) {
if (mapper instanceof AllFieldMapper.IncludeInAll) {
clone.putMapper(((AllFieldMapper.IncludeInAll) mapper).includeInAll(includeInAll));
}
}
return clone;
}
@Override
public ObjectMapper includeInAllIfNotSet(Boolean includeInAll) {
if (includeInAll == null || this.includeInAll != null) {
return this;
}
ObjectMapper clone = clone();
clone.includeInAll = includeInAll;
// when called from outside, apply this on all the inner mappers
for (Mapper mapper : clone.mappers.values()) {
if (mapper instanceof AllFieldMapper.IncludeInAll) {
clone.putMapper(((AllFieldMapper.IncludeInAll) mapper).includeInAllIfNotSet(includeInAll));
}
}
return clone;
}
@Override
public ObjectMapper unsetIncludeInAll() {
if (includeInAll == null) {
return this;
}
ObjectMapper clone = clone();
clone.includeInAll = null;
// when called from outside, apply this on all the inner mappers
for (Mapper mapper : mappers.values()) {
if (mapper instanceof AllFieldMapper.IncludeInAll) {
clone.putMapper(((AllFieldMapper.IncludeInAll) mapper).unsetIncludeInAll());
}
}
return clone;
}
public Nested nested() { public Nested nested() {
return this.nested; return this.nested;
} }
public Boolean includeInAll() {
return includeInAll;
}
public Query nestedTypeFilter() { public Query nestedTypeFilter() {
return this.nestedTypeFilter; return this.nestedTypeFilter;
} }
protected void putMapper(Mapper mapper) { protected void putMapper(Mapper mapper) {
if (mapper instanceof AllFieldMapper.IncludeInAll) {
mapper = ((AllFieldMapper.IncludeInAll) mapper).includeInAllIfNotSet(includeInAll);
}
mappers = mappers.copyAndPut(mapper.simpleName(), mapper); mappers = mappers.copyAndPut(mapper.simpleName(), mapper);
} }

View File

@ -423,6 +423,22 @@ public abstract class ParseContext {
public abstract DocumentMapperParser docMapperParser(); public abstract DocumentMapperParser docMapperParser();
/** Return a view of this {@link ParseContext} that changes the return
* value of {@link #getIncludeInAllDefault()}. */
public final ParseContext setIncludeInAllDefault(boolean includeInAll) {
return new FilterParseContext(this) {
@Override
public Boolean getIncludeInAllDefault() {
return includeInAll;
}
};
}
/** Whether field values should be added to the _all field by default. */
public Boolean getIncludeInAllDefault() {
return null;
}
/** /**
* Return a new context that will be within a copy-to operation. * Return a new context that will be within a copy-to operation.
*/ */
@ -526,7 +542,7 @@ public abstract class ParseContext {
* is <tt>false</tt>. If its enabled, then will return <tt>true</tt> only if the specific flag is <tt>null</tt> or * is <tt>false</tt>. If its enabled, then will return <tt>true</tt> only if the specific flag is <tt>null</tt> or
* its actual value (so, if not set, defaults to "true") and the field is indexed. * its actual value (so, if not set, defaults to "true") and the field is indexed.
*/ */
private boolean includeInAll(Boolean specificIncludeInAll, boolean indexed) { private boolean includeInAll(Boolean includeInAll, boolean indexed) {
if (isWithinCopyTo()) { if (isWithinCopyTo()) {
return false; return false;
} }
@ -536,11 +552,14 @@ public abstract class ParseContext {
if (!docMapper().allFieldMapper().enabled()) { if (!docMapper().allFieldMapper().enabled()) {
return false; return false;
} }
if (includeInAll == null) {
includeInAll = getIncludeInAllDefault();
}
// not explicitly set // not explicitly set
if (specificIncludeInAll == null) { if (includeInAll == null) {
return indexed; return indexed;
} }
return specificIncludeInAll; return includeInAll;
} }
public abstract AllEntries allEntries(); public abstract AllEntries allEntries();

View File

@ -100,7 +100,8 @@ public class RootObjectMapper extends ObjectMapper {
@Override @Override
protected ObjectMapper createMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic, Map<String, Mapper> mappers, @Nullable Settings settings) { protected ObjectMapper createMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic,
Boolean includeInAll, Map<String, Mapper> mappers, @Nullable Settings settings) {
assert !nested.isNested(); assert !nested.isNested();
FormatDateTimeFormatter[] dates = null; FormatDateTimeFormatter[] dates = null;
if (dynamicDateTimeFormatters == null) { if (dynamicDateTimeFormatters == null) {
@ -111,7 +112,7 @@ public class RootObjectMapper extends ObjectMapper {
} else { } else {
dates = dynamicDateTimeFormatters.toArray(new FormatDateTimeFormatter[dynamicDateTimeFormatters.size()]); dates = dynamicDateTimeFormatters.toArray(new FormatDateTimeFormatter[dynamicDateTimeFormatters.size()]);
} }
return new RootObjectMapper(name, enabled, dynamic, mappers, return new RootObjectMapper(name, enabled, dynamic, includeInAll, mappers,
dates, dates,
dynamicTemplates.toArray(new DynamicTemplate[dynamicTemplates.size()]), dynamicTemplates.toArray(new DynamicTemplate[dynamicTemplates.size()]),
dateDetection, numericDetection); dateDetection, numericDetection);
@ -207,9 +208,9 @@ public class RootObjectMapper extends ObjectMapper {
private volatile DynamicTemplate dynamicTemplates[]; private volatile DynamicTemplate dynamicTemplates[];
RootObjectMapper(String name, boolean enabled, Dynamic dynamic, Map<String, Mapper> mappers, RootObjectMapper(String name, boolean enabled, Dynamic dynamic, Boolean includeInAll, Map<String, Mapper> mappers,
FormatDateTimeFormatter[] dynamicDateTimeFormatters, DynamicTemplate dynamicTemplates[], boolean dateDetection, boolean numericDetection) { FormatDateTimeFormatter[] dynamicDateTimeFormatters, DynamicTemplate dynamicTemplates[], boolean dateDetection, boolean numericDetection) {
super(name, name, enabled, Nested.NO, dynamic, mappers); super(name, name, enabled, Nested.NO, dynamic, includeInAll, mappers);
this.dynamicTemplates = dynamicTemplates; this.dynamicTemplates = dynamicTemplates;
this.dynamicDateTimeFormatters = dynamicDateTimeFormatters; this.dynamicDateTimeFormatters = dynamicDateTimeFormatters;
this.dateDetection = dateDetection; this.dateDetection = dateDetection;

View File

@ -65,7 +65,7 @@ import java.util.Map;
/** A {@link FieldMapper} for scaled floats. Values are internally multiplied /** A {@link FieldMapper} for scaled floats. Values are internally multiplied
* by a scaling factor and rounded to the closest long. */ * by a scaling factor and rounded to the closest long. */
public class ScaledFloatFieldMapper extends FieldMapper implements AllFieldMapper.IncludeInAll { public class ScaledFloatFieldMapper extends FieldMapper {
public static final String CONTENT_TYPE = "scaled_float"; public static final String CONTENT_TYPE = "scaled_float";
// use the same default as numbers // use the same default as numbers
@ -124,10 +124,8 @@ public class ScaledFloatFieldMapper extends FieldMapper implements AllFieldMappe
throw new IllegalArgumentException("Field [" + name + "] misses required parameter [scaling_factor]"); throw new IllegalArgumentException("Field [" + name + "] misses required parameter [scaling_factor]");
} }
setupFieldType(context); setupFieldType(context);
ScaledFloatFieldMapper fieldMapper = return new ScaledFloatFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context),
new ScaledFloatFieldMapper(name, fieldType, defaultFieldType, ignoreMalformed(context), coerce(context), includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
coerce(context), context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return (ScaledFloatFieldMapper) fieldMapper.includeInAll(includeInAll);
} }
} }
@ -336,6 +334,7 @@ public class ScaledFloatFieldMapper extends FieldMapper implements AllFieldMappe
MappedFieldType defaultFieldType, MappedFieldType defaultFieldType,
Explicit<Boolean> ignoreMalformed, Explicit<Boolean> ignoreMalformed,
Explicit<Boolean> coerce, Explicit<Boolean> coerce,
Boolean includeInAll,
Settings indexSettings, Settings indexSettings,
MultiFields multiFields, MultiFields multiFields,
CopyTo copyTo) { CopyTo copyTo) {
@ -346,6 +345,7 @@ public class ScaledFloatFieldMapper extends FieldMapper implements AllFieldMappe
} }
this.ignoreMalformed = ignoreMalformed; this.ignoreMalformed = ignoreMalformed;
this.coerce = coerce; this.coerce = coerce;
this.includeInAll = includeInAll;
} }
@Override @Override
@ -363,39 +363,6 @@ public class ScaledFloatFieldMapper extends FieldMapper implements AllFieldMappe
return (ScaledFloatFieldMapper) super.clone(); return (ScaledFloatFieldMapper) super.clone();
} }
@Override
public Mapper includeInAll(Boolean includeInAll) {
if (includeInAll != null) {
ScaledFloatFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper includeInAllIfNotSet(Boolean includeInAll) {
if (includeInAll != null && this.includeInAll == null) {
ScaledFloatFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public Mapper unsetIncludeInAll() {
if (includeInAll != null) {
ScaledFloatFieldMapper clone = clone();
clone.includeInAll = null;
return clone;
} else {
return this;
}
}
@Override @Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException { protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
XContentParser parser = context.parser(); XContentParser parser = context.parser();

View File

@ -49,7 +49,7 @@ import java.util.Set;
import static org.apache.lucene.index.IndexOptions.NONE; import static org.apache.lucene.index.IndexOptions.NONE;
import static org.elasticsearch.index.mapper.TypeParsers.parseTextField; import static org.elasticsearch.index.mapper.TypeParsers.parseTextField;
public class StringFieldMapper extends FieldMapper implements AllFieldMapper.IncludeInAll { public class StringFieldMapper extends FieldMapper {
public static final String CONTENT_TYPE = "string"; public static final String CONTENT_TYPE = "string";
private static final int POSITION_INCREMENT_GAP_USE_ANALYZER = -1; private static final int POSITION_INCREMENT_GAP_USE_ANALYZER = -1;
@ -177,10 +177,9 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionIncrementGap)); fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionIncrementGap));
} }
setupFieldType(context); setupFieldType(context);
StringFieldMapper fieldMapper = new StringFieldMapper( return new StringFieldMapper(
name, fieldType(), defaultFieldType, positionIncrementGap, ignoreAbove, name, fieldType(), defaultFieldType, positionIncrementGap, ignoreAbove, includeInAll,
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return fieldMapper.includeInAll(includeInAll);
} }
} }
@ -488,7 +487,7 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
private int ignoreAbove; private int ignoreAbove;
protected StringFieldMapper(String simpleName, StringFieldType fieldType, MappedFieldType defaultFieldType, protected StringFieldMapper(String simpleName, StringFieldType fieldType, MappedFieldType defaultFieldType,
int positionIncrementGap, int ignoreAbove, int positionIncrementGap, int ignoreAbove, Boolean includeInAll,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
if (Version.indexCreated(indexSettings).onOrAfter(Version.V_5_0_0_alpha1)) { if (Version.indexCreated(indexSettings).onOrAfter(Version.V_5_0_0_alpha1)) {
@ -506,6 +505,7 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
} }
this.positionIncrementGap = positionIncrementGap; this.positionIncrementGap = positionIncrementGap;
this.ignoreAbove = ignoreAbove; this.ignoreAbove = ignoreAbove;
this.includeInAll = includeInAll;
} }
@Override @Override
@ -513,39 +513,6 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
return (StringFieldMapper) super.clone(); return (StringFieldMapper) super.clone();
} }
@Override
public StringFieldMapper includeInAll(Boolean includeInAll) {
if (includeInAll != null) {
StringFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public StringFieldMapper includeInAllIfNotSet(Boolean includeInAll) {
if (includeInAll != null && this.includeInAll == null) {
StringFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public StringFieldMapper unsetIncludeInAll() {
if (includeInAll != null) {
StringFieldMapper clone = clone();
clone.includeInAll = null;
return clone;
} else {
return this;
}
}
@Override @Override
protected boolean customBoost() { protected boolean customBoost() {
return true; return true;

View File

@ -38,7 +38,7 @@ import java.util.Objects;
import static org.elasticsearch.index.mapper.TypeParsers.parseTextField; import static org.elasticsearch.index.mapper.TypeParsers.parseTextField;
/** A {@link FieldMapper} for full-text fields. */ /** A {@link FieldMapper} for full-text fields. */
public class TextFieldMapper extends FieldMapper implements AllFieldMapper.IncludeInAll { public class TextFieldMapper extends FieldMapper {
public static final String CONTENT_TYPE = "text"; public static final String CONTENT_TYPE = "text";
private static final int POSITION_INCREMENT_GAP_USE_ANALYZER = -1; private static final int POSITION_INCREMENT_GAP_USE_ANALYZER = -1;
@ -120,10 +120,9 @@ public class TextFieldMapper extends FieldMapper implements AllFieldMapper.Inclu
fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionIncrementGap)); fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionIncrementGap));
} }
setupFieldType(context); setupFieldType(context);
TextFieldMapper fieldMapper = new TextFieldMapper( return new TextFieldMapper(
name, fieldType, defaultFieldType, positionIncrementGap, name, fieldType, defaultFieldType, positionIncrementGap, includeInAll,
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
return fieldMapper.includeInAll(includeInAll);
} }
} }
@ -297,7 +296,7 @@ public class TextFieldMapper extends FieldMapper implements AllFieldMapper.Inclu
private int positionIncrementGap; private int positionIncrementGap;
protected TextFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, protected TextFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
int positionIncrementGap, int positionIncrementGap, Boolean includeInAll,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
assert fieldType.tokenized(); assert fieldType.tokenized();
@ -306,6 +305,7 @@ public class TextFieldMapper extends FieldMapper implements AllFieldMapper.Inclu
throw new IllegalArgumentException("Cannot enable fielddata on a [text] field that is not indexed: [" + name() + "]"); throw new IllegalArgumentException("Cannot enable fielddata on a [text] field that is not indexed: [" + name() + "]");
} }
this.positionIncrementGap = positionIncrementGap; this.positionIncrementGap = positionIncrementGap;
this.includeInAll = includeInAll;
} }
@Override @Override
@ -318,39 +318,6 @@ public class TextFieldMapper extends FieldMapper implements AllFieldMapper.Inclu
return includeInAll; return includeInAll;
} }
@Override
public TextFieldMapper includeInAll(Boolean includeInAll) {
if (includeInAll != null) {
TextFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public TextFieldMapper includeInAllIfNotSet(Boolean includeInAll) {
if (includeInAll != null && this.includeInAll == null) {
TextFieldMapper clone = clone();
clone.includeInAll = includeInAll;
return clone;
} else {
return this;
}
}
@Override
public TextFieldMapper unsetIncludeInAll() {
if (includeInAll != null) {
TextFieldMapper clone = clone();
clone.includeInAll = null;
return clone;
} else {
return this;
}
}
public int getPositionIncrementGap() { public int getPositionIncrementGap() {
return this.positionIncrementGap; return this.positionIncrementGap;
} }

View File

@ -19,14 +19,20 @@
package org.elasticsearch.index.mapper; package org.elasticsearch.index.mapper;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.lucene.index.IndexableField;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.lucene.all.AllField;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexService;
@ -1154,4 +1160,48 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
assertThat(doc.rootDoc().get("type.test2"), equalTo("value2")); assertThat(doc.rootDoc().get("type.test2"), equalTo("value2"));
assertThat(doc.rootDoc().get("type.inner.inner_field"), equalTo("inner_value")); assertThat(doc.rootDoc().get("type.inner.inner_field"), equalTo("inner_value"));
} }
public void testIncludeInAllPropagation() throws IOException {
String defaultMapping = XContentFactory.jsonBuilder().startObject()
.startObject("type")
.field("dynamic", "strict")
.startObject("properties")
.startObject("a")
.field("type", "keyword")
.endObject()
.startObject("o")
.field("include_in_all", false)
.startObject("properties")
.startObject("a")
.field("type", "keyword")
.endObject()
.startObject("o")
.field("include_in_all", true)
.startObject("properties")
.startObject("a")
.field("type", "keyword")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
.startObject()
.field("a", "b")
.startObject("o")
.field("a", "c")
.startObject("o")
.field("a", "d")
.endObject()
.endObject()
.endObject().bytes());
Set<String> values = new HashSet<>();
for (IndexableField f : doc.rootDoc().getFields("_all")) {
values.add(f.stringValue());
}
assertEquals(new HashSet<>(Arrays.asList("b", "d")), values);
}
} }