Skip to content

Commit 9c24141

Browse files
committed
Mapping: When _all is disabled, optimize to not gather all entries, closes elastic#722.
1 parent be3e88d commit 9c24141

File tree

11 files changed

+38
-21
lines changed

11 files changed

+38
-21
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@
2525
public interface AllFieldMapper extends FieldMapper<Void>, InternalMapper {
2626

2727
public static final String NAME = "_all";
28+
29+
/**
30+
* Is the all field enabled or not.
31+
*/
32+
public boolean enabled();
2833
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ByteFieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected ByteFieldMapper(Names names, int precisionStep, Field.Index index, Fie
160160
} else {
161161
value = ((Number) externalValue).byteValue();
162162
}
163-
if (includeInAll == null || includeInAll) {
163+
if (context.includeInAll(includeInAll)) {
164164
context.allEntries().addText(names.fullName(), Byte.toString(value), boost);
165165
}
166166
} else {
@@ -169,12 +169,12 @@ protected ByteFieldMapper(Names names, int precisionStep, Field.Index index, Fie
169169
return null;
170170
}
171171
value = nullValue;
172-
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
172+
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
173173
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
174174
}
175175
} else {
176176
value = (byte) context.parser().shortValue();
177-
if (includeInAll == null || includeInAll) {
177+
if (context.includeInAll(includeInAll)) {
178178
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
179179
}
180180
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DateFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ protected DateFieldMapper(Names names, FormatDateTimeFormatter dateTimeFormatter
194194
if (dateAsString == null) {
195195
return null;
196196
}
197-
if (includeInAll == null || includeInAll) {
197+
if (context.includeInAll(includeInAll)) {
198198
context.allEntries().addText(names.fullName(), dateAsString, boost);
199199
}
200200

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/DoubleFieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected DoubleFieldMapper(Names names, int precisionStep,
162162
} else {
163163
value = ((Number) externalValue).doubleValue();
164164
}
165-
if (includeInAll == null || includeInAll) {
165+
if (context.includeInAll(includeInAll)) {
166166
context.allEntries().addText(names.fullName(), Double.toString(value), boost);
167167
}
168168
} else {
@@ -171,12 +171,12 @@ protected DoubleFieldMapper(Names names, int precisionStep,
171171
return null;
172172
}
173173
value = nullValue;
174-
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
174+
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
175175
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
176176
}
177177
} else {
178178
value = context.parser().doubleValue();
179-
if (includeInAll == null || includeInAll) {
179+
if (context.includeInAll(includeInAll)) {
180180
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
181181
}
182182
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/FloatFieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected FloatFieldMapper(Names names, int precisionStep, Field.Index index, Fi
161161
} else {
162162
value = ((Number) externalValue).floatValue();
163163
}
164-
if (includeInAll == null || includeInAll) {
164+
if (context.includeInAll(includeInAll)) {
165165
context.allEntries().addText(names.fullName(), Float.toString(value), boost);
166166
}
167167
} else {
@@ -170,12 +170,12 @@ protected FloatFieldMapper(Names names, int precisionStep, Field.Index index, Fi
170170
return null;
171171
}
172172
value = nullValue;
173-
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
173+
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
174174
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
175175
}
176176
} else {
177177
value = context.parser().floatValue();
178-
if (includeInAll == null || includeInAll) {
178+
if (context.includeInAll(includeInAll)) {
179179
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
180180
}
181181
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IntegerFieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected IntegerFieldMapper(Names names, int precisionStep, Field.Index index,
161161
} else {
162162
value = ((Number) externalValue).intValue();
163163
}
164-
if (includeInAll == null || includeInAll) {
164+
if (context.includeInAll(includeInAll)) {
165165
context.allEntries().addText(names.fullName(), Integer.toString(value), boost);
166166
}
167167
} else {
@@ -170,12 +170,12 @@ protected IntegerFieldMapper(Names names, int precisionStep, Field.Index index,
170170
return null;
171171
}
172172
value = nullValue;
173-
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
173+
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
174174
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
175175
}
176176
} else {
177177
value = context.parser().intValue();
178-
if (includeInAll == null || includeInAll) {
178+
if (context.includeInAll(includeInAll)) {
179179
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
180180
}
181181
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/LongFieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected LongFieldMapper(Names names, int precisionStep, Field.Index index, Fie
161161
} else {
162162
value = ((Number) externalValue).longValue();
163163
}
164-
if (includeInAll == null || includeInAll) {
164+
if (context.includeInAll(includeInAll)) {
165165
context.allEntries().addText(names.fullName(), Long.toString(value), boost);
166166
}
167167
} else {
@@ -170,12 +170,12 @@ protected LongFieldMapper(Names names, int precisionStep, Field.Index index, Fie
170170
return null;
171171
}
172172
value = nullValue;
173-
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
173+
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
174174
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
175175
}
176176
} else {
177177
value = context.parser().longValue();
178-
if (includeInAll == null || includeInAll) {
178+
if (context.includeInAll(includeInAll)) {
179179
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
180180
}
181181
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ParseContext.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@ public void uid(String uid) {
199199
this.uid = uid;
200200
}
201201

202+
/**
203+
* Is all included or not. Will always disable it if {@link org.elasticsearch.index.mapper.AllFieldMapper#enabled()}
204+
* is <tt>false</tt>. If its enabled, then will return <tt>true</tt> only if the specific flag is <tt>null</tt> or
205+
* its actual value (so, if not set, defaults to "true").
206+
*/
207+
public boolean includeInAll(Boolean specificIncludeInAll) {
208+
if (!docMapper.allFieldMapper().enabled()) {
209+
return false;
210+
}
211+
return specificIncludeInAll == null || specificIncludeInAll;
212+
}
213+
202214
public AllEntries allEntries() {
203215
return this.allEntries;
204216
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ShortFieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected ShortFieldMapper(Names names, int precisionStep, Field.Index index, Fi
161161
} else {
162162
value = ((Number) externalValue).shortValue();
163163
}
164-
if (includeInAll == null || includeInAll) {
164+
if (context.includeInAll(includeInAll)) {
165165
context.allEntries().addText(names.fullName(), Short.toString(value), boost);
166166
}
167167
} else {
@@ -170,12 +170,12 @@ protected ShortFieldMapper(Names names, int precisionStep, Field.Index index, Fi
170170
return null;
171171
}
172172
value = nullValue;
173-
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
173+
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
174174
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
175175
}
176176
} else {
177177
value = context.parser().shortValue();
178-
if (includeInAll == null || includeInAll) {
178+
if (context.includeInAll(includeInAll)) {
179179
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
180180
}
181181
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/StringFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected StringFieldMapper(Names names, Field.Index index, Field.Store store, F
140140
if (value == null) {
141141
return null;
142142
}
143-
if (includeInAll == null || includeInAll) {
143+
if (context.includeInAll(includeInAll)) {
144144
context.allEntries().addText(names.fullName(), value, boost);
145145
}
146146
if (!indexed() && !stored()) {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ip/IpFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ protected IpFieldMapper(Names names, int precisionStep,
210210
if (ipAsString == null) {
211211
return null;
212212
}
213-
if (includeInAll == null || includeInAll) {
213+
if (context.includeInAll(includeInAll)) {
214214
context.allEntries().addText(names.fullName(), ipAsString, boost);
215215
}
216216

0 commit comments

Comments
 (0)