Skip to content

Commit f5e89f7

Browse files
committed
mappings: remove fly weight
1 parent 9ec1b11 commit f5e89f7

File tree

11 files changed

+22
-49
lines changed

11 files changed

+22
-49
lines changed

core/src/main/java/org/elasticsearch/index/mapper/ParseContext.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,6 @@ private FilterParseContext(ParseContext in) {
181181
this.in = in;
182182
}
183183

184-
@Override
185-
public boolean flyweight() {
186-
return in.flyweight();
187-
}
188-
189184
@Override
190185
public DocumentMapperParser docMapperParser() {
191186
return in.docMapperParser();
@@ -411,11 +406,6 @@ public void reset(XContentParser parser, Document document, SourceToParse source
411406
this.dynamicMappingsUpdate = null;
412407
}
413408

414-
@Override
415-
public boolean flyweight() {
416-
return sourceToParse.flyweight();
417-
}
418-
419409
@Override
420410
public DocumentMapperParser docMapperParser() {
421411
return this.docMapperParser;
@@ -580,8 +570,6 @@ public Mapper dynamicMappingsUpdate() {
580570
}
581571
}
582572

583-
public abstract boolean flyweight();
584-
585573
public abstract DocumentMapperParser docMapperParser();
586574

587575
/**
@@ -658,6 +646,7 @@ public boolean isWithinMultiFields() {
658646

659647
public abstract SourceToParse sourceToParse();
660648

649+
@Nullable
661650
public abstract BytesReference source();
662651

663652
// only should be used by SourceFieldMapper to update with a compressed source

core/src/main/java/org/elasticsearch/index/mapper/SourceToParse.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public static SourceToParse source(Origin origin, BytesReference source) {
4646

4747
private final XContentParser parser;
4848

49-
private boolean flyweight = false;
50-
5149
private String index;
5250

5351
private String type;
@@ -106,15 +104,6 @@ public SourceToParse type(String type) {
106104
return this;
107105
}
108106

109-
public SourceToParse flyweight(boolean flyweight) {
110-
this.flyweight = flyweight;
111-
return this;
112-
}
113-
114-
public boolean flyweight() {
115-
return this.flyweight;
116-
}
117-
118107
public String id() {
119108
return this.id;
120109
}

core/src/main/java/org/elasticsearch/index/mapper/internal/IdFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public void preParse(ParseContext context) throws IOException {
220220

221221
@Override
222222
public void postParse(ParseContext context) throws IOException {
223-
if (context.id() == null && !context.sourceToParse().flyweight()) {
223+
if (context.id() == null) {
224224
throw new MapperParsingException("No id found while parsing the content source");
225225
}
226226
// it either get built in the preParse phase, or get parsed...

core/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ public void preParse(ParseContext context) throws IOException {
228228

229229
@Override
230230
public void postParse(ParseContext context) throws IOException {
231-
if (context.sourceToParse().flyweight() == false) {
232-
parse(context);
233-
}
231+
parse(context);
234232
}
235233

236234
@Override

core/src/main/java/org/elasticsearch/index/mapper/internal/SourceFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,11 @@ protected void parseCreateField(ParseContext context, List<Field> fields) throws
251251
if (!fieldType().stored()) {
252252
return;
253253
}
254-
if (context.flyweight()) {
254+
BytesReference source = context.source();
255+
// Percolate and tv APIs may not set the source and that is ok, because these APIs will not index any data
256+
if (source == null) {
255257
return;
256258
}
257-
BytesReference source = context.source();
258259

259260
boolean filtered = (includes != null && includes.length > 0) || (excludes != null && excludes.length > 0);
260261
if (filtered) {

core/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public Mapper parse(ParseContext context) throws IOException, MapperParsingExcep
212212

213213
@Override
214214
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException, AlreadyExpiredException {
215-
if (enabledState.enabled && !context.sourceToParse().flyweight()) {
215+
if (enabledState.enabled) {
216216
long ttl = context.sourceToParse().ttl();
217217
if (ttl <= 0 && defaultTTL > 0) { // no ttl provided so we use the default value
218218
ttl = defaultTTL;

core/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void preParse(ParseContext context) throws IOException {
149149

150150
@Override
151151
public void postParse(ParseContext context) throws IOException {
152-
if (context.id() == null && !context.sourceToParse().flyweight()) {
152+
if (context.id() == null) {
153153
throw new MapperParsingException("No id found while parsing the content source");
154154
}
155155
// if we did not have the id as part of the sourceToParse, then we need to parse it here

core/src/main/java/org/elasticsearch/index/percolator/PercolatorFieldMapper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ public PercolatorFieldMapper(String simpleName, MappedFieldType fieldType, Mappe
126126
public Mapper parse(ParseContext context) throws IOException {
127127
QueryShardContext queryShardContext = new QueryShardContext(this.queryShardContext);
128128
Query query = PercolatorQueriesRegistry.parseQuery(queryShardContext, mapUnmappedFieldAsString, context.parser());
129-
if (context.flyweight() == false) {
130-
ExtractQueryTermsService.extractQueryTerms(query, context.doc(), queryTermsField.name(), unknownQueryField.name(), queryTermsField.fieldType());
131-
}
129+
ExtractQueryTermsService.extractQueryTerms(query, context.doc(), queryTermsField.name(), unknownQueryField.name(), queryTermsField.fieldType());
132130
return null;
133131
}
134132

core/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVectorsRequ
292292
private ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc) throws Throwable {
293293
MapperService mapperService = indexShard.mapperService();
294294
DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type);
295-
ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse(source(doc).index(index).type(type).flyweight(true));
295+
ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse(source(doc).index(index).type(type).id("_id_for_tv_api"));
296296
if (docMapper.getMapping() != null) {
297297
parsedDocument.addDynamicMappingsUpdate(docMapper.getMapping());
298298
}

core/src/main/java/org/elasticsearch/percolator/PercolateDocumentParser.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.ElasticsearchParseException;
2525
import org.elasticsearch.action.percolate.PercolateShardRequest;
2626
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
27+
import org.elasticsearch.common.bytes.BytesArray;
2728
import org.elasticsearch.common.bytes.BytesReference;
2829
import org.elasticsearch.common.inject.Inject;
2930
import org.elasticsearch.common.io.stream.BytesStreamOutput;
@@ -34,6 +35,7 @@
3435
import org.elasticsearch.index.mapper.DocumentMapperForType;
3536
import org.elasticsearch.index.mapper.MapperService;
3637
import org.elasticsearch.index.mapper.ParsedDocument;
38+
import org.elasticsearch.index.mapper.SourceToParse;
3739
import org.elasticsearch.index.query.QueryShardContext;
3840
import org.elasticsearch.search.SearchParseElement;
3941
import org.elasticsearch.search.aggregations.AggregationPhase;
@@ -93,7 +95,7 @@ public ParsedDocument parse(PercolateShardRequest request, PercolateContext cont
9395

9496
DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(request.documentType());
9597
String index = context.shardTarget().index();
96-
doc = docMapper.getDocumentMapper().parse(source(parser).index(index).type(request.documentType()).flyweight(true));
98+
doc = docMapper.getDocumentMapper().parse(source(parser).index(index).type(request.documentType()).id("_id_for_percolate_api"));
9799
if (docMapper.getMapping() != null) {
98100
doc.addDynamicMappingsUpdate(docMapper.getMapping());
99101
}
@@ -202,19 +204,15 @@ private void parseSort(XContentParser parser, PercolateContext context) throws E
202204
}
203205

204206
private ParsedDocument parseFetchedDoc(PercolateContext context, BytesReference fetchedDoc, MapperService mapperService, String index, String type) {
205-
try (XContentParser parser = XContentFactory.xContent(fetchedDoc).createParser(fetchedDoc)) {
206-
DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type);
207-
ParsedDocument doc = docMapper.getDocumentMapper().parse(source(parser).index(index).type(type).flyweight(true));
208-
if (doc == null) {
209-
throw new ElasticsearchParseException("No doc to percolate in the request");
210-
}
211-
if (context.highlight() != null) {
212-
doc.setSource(fetchedDoc);
213-
}
214-
return doc;
215-
} catch (Throwable e) {
216-
throw new ElasticsearchParseException("failed to parse request", e);
207+
DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type);
208+
ParsedDocument doc = docMapper.getDocumentMapper().parse(source(fetchedDoc).index(index).type(type).id("_id_for_percolate_api"));
209+
if (doc == null) {
210+
throw new ElasticsearchParseException("No doc to percolate in the request");
217211
}
212+
if (context.highlight() != null) {
213+
doc.setSource(fetchedDoc);
214+
}
215+
return doc;
218216
}
219217

220218
}

plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected void parseCreateField(ParseContext context, List<Field> fields) throws
150150
if (!enabledState.enabled) {
151151
return;
152152
}
153-
if (context.flyweight()) {
153+
if (context.source() == null) {
154154
return;
155155
}
156156
fields.add(new IntegerFieldMapper.CustomIntegerNumericField(context.source().length(), fieldType()));

0 commit comments

Comments
 (0)