diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java index 3eafa63f880..79a3b4a43b6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java @@ -25,4 +25,9 @@ package org.elasticsearch.index.mapper; public interface AllFieldMapper extends FieldMapper, InternalMapper { public static final String NAME = "_all"; + + /** + * Is the all field enabled or not. + */ + public boolean enabled(); } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ByteFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ByteFieldMapper.java index 1bde6b18de8..e890ff6c131 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ByteFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ByteFieldMapper.java @@ -160,7 +160,7 @@ public class ByteFieldMapper extends NumberFieldMapper { } else { value = ((Number) externalValue).byteValue(); } - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), Byte.toString(value), boost); } } else { @@ -169,12 +169,12 @@ public class ByteFieldMapper extends NumberFieldMapper { return null; } value = nullValue; - if (nullValueAsString != null && (includeInAll == null || includeInAll)) { + if (nullValueAsString != null && (context.includeInAll(includeInAll))) { context.allEntries().addText(names.fullName(), nullValueAsString, boost); } } else { value = (byte) context.parser().shortValue(); - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), context.parser().text(), boost); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DateFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DateFieldMapper.java index 3ab03f09b0d..92b30ac51bf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DateFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DateFieldMapper.java @@ -194,7 +194,7 @@ public class DateFieldMapper extends NumberFieldMapper { if (dateAsString == null) { return null; } - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), dateAsString, boost); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DoubleFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DoubleFieldMapper.java index 406a49ebb34..8fa0484fe45 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DoubleFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DoubleFieldMapper.java @@ -162,7 +162,7 @@ public class DoubleFieldMapper extends NumberFieldMapper { } else { value = ((Number) externalValue).doubleValue(); } - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), Double.toString(value), boost); } } else { @@ -171,12 +171,12 @@ public class DoubleFieldMapper extends NumberFieldMapper { return null; } value = nullValue; - if (nullValueAsString != null && (includeInAll == null || includeInAll)) { + if (nullValueAsString != null && (context.includeInAll(includeInAll))) { context.allEntries().addText(names.fullName(), nullValueAsString, boost); } } else { value = context.parser().doubleValue(); - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), context.parser().text(), boost); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/FloatFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/FloatFieldMapper.java index 2553e11110f..c4e859d146a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/FloatFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/FloatFieldMapper.java @@ -161,7 +161,7 @@ public class FloatFieldMapper extends NumberFieldMapper { } else { value = ((Number) externalValue).floatValue(); } - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), Float.toString(value), boost); } } else { @@ -170,12 +170,12 @@ public class FloatFieldMapper extends NumberFieldMapper { return null; } value = nullValue; - if (nullValueAsString != null && (includeInAll == null || includeInAll)) { + if (nullValueAsString != null && (context.includeInAll(includeInAll))) { context.allEntries().addText(names.fullName(), nullValueAsString, boost); } } else { value = context.parser().floatValue(); - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), context.parser().text(), boost); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IntegerFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IntegerFieldMapper.java index 292adcd4250..40d77a15430 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IntegerFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IntegerFieldMapper.java @@ -161,7 +161,7 @@ public class IntegerFieldMapper extends NumberFieldMapper { } else { value = ((Number) externalValue).intValue(); } - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), Integer.toString(value), boost); } } else { @@ -170,12 +170,12 @@ public class IntegerFieldMapper extends NumberFieldMapper { return null; } value = nullValue; - if (nullValueAsString != null && (includeInAll == null || includeInAll)) { + if (nullValueAsString != null && (context.includeInAll(includeInAll))) { context.allEntries().addText(names.fullName(), nullValueAsString, boost); } } else { value = context.parser().intValue(); - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), context.parser().text(), boost); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/LongFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/LongFieldMapper.java index 08f6512ff37..9498cd5ca23 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/LongFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/LongFieldMapper.java @@ -161,7 +161,7 @@ public class LongFieldMapper extends NumberFieldMapper { } else { value = ((Number) externalValue).longValue(); } - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), Long.toString(value), boost); } } else { @@ -170,12 +170,12 @@ public class LongFieldMapper extends NumberFieldMapper { return null; } value = nullValue; - if (nullValueAsString != null && (includeInAll == null || includeInAll)) { + if (nullValueAsString != null && (context.includeInAll(includeInAll))) { context.allEntries().addText(names.fullName(), nullValueAsString, boost); } } else { value = context.parser().longValue(); - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), context.parser().text(), boost); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ParseContext.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ParseContext.java index 31c998915f0..668e56394bb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ParseContext.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ParseContext.java @@ -199,6 +199,18 @@ public class ParseContext { this.uid = uid; } + /** + * Is all included or not. Will always disable it if {@link org.elasticsearch.index.mapper.AllFieldMapper#enabled()} + * is false. If its enabled, then will return true only if the specific flag is null or + * its actual value (so, if not set, defaults to "true"). + */ + public boolean includeInAll(Boolean specificIncludeInAll) { + if (!docMapper.allFieldMapper().enabled()) { + return false; + } + return specificIncludeInAll == null || specificIncludeInAll; + } + public AllEntries allEntries() { return this.allEntries; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ShortFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ShortFieldMapper.java index e82db319d96..a685a18f671 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ShortFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ShortFieldMapper.java @@ -161,7 +161,7 @@ public class ShortFieldMapper extends NumberFieldMapper { } else { value = ((Number) externalValue).shortValue(); } - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), Short.toString(value), boost); } } else { @@ -170,12 +170,12 @@ public class ShortFieldMapper extends NumberFieldMapper { return null; } value = nullValue; - if (nullValueAsString != null && (includeInAll == null || includeInAll)) { + if (nullValueAsString != null && (context.includeInAll(includeInAll))) { context.allEntries().addText(names.fullName(), nullValueAsString, boost); } } else { value = context.parser().shortValue(); - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), context.parser().text(), boost); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/StringFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/StringFieldMapper.java index fa9831ecf6d..36b31b05102 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/StringFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/StringFieldMapper.java @@ -140,7 +140,7 @@ public class StringFieldMapper extends AbstractFieldMapper implements In if (value == null) { return null; } - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), value, boost); } if (!indexed() && !stored()) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ip/IpFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ip/IpFieldMapper.java index 112f0e405f2..0b9cb391b31 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ip/IpFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ip/IpFieldMapper.java @@ -210,7 +210,7 @@ public class IpFieldMapper extends NumberFieldMapper { if (ipAsString == null) { return null; } - if (includeInAll == null || includeInAll) { + if (context.includeInAll(includeInAll)) { context.allEntries().addText(names.fullName(), ipAsString, boost); }