if we loaded source, use it when needing it in other fetch phases like extracting specific fields instead of loading it again
This commit is contained in:
parent
9ae402dde9
commit
f05fa91cb2
|
@ -293,7 +293,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
|
||||||
} else {
|
} else {
|
||||||
if (searchLookup == null) {
|
if (searchLookup == null) {
|
||||||
searchLookup = new SearchLookup(mapperService, indexCache.fieldData());
|
searchLookup = new SearchLookup(mapperService, indexCache.fieldData());
|
||||||
searchLookup.source().setNextSource(SourceLookup.sourceAsMap(source.source.bytes(), source.source.offset(), source.source.length()));
|
searchLookup.source().setNextSource(source.source.bytes(), source.source.offset(), source.source.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldMapper<?> x = docMapper.mappers().smartNameFieldMapper(field);
|
FieldMapper<?> x = docMapper.mappers().smartNameFieldMapper(field);
|
||||||
|
|
|
@ -184,6 +184,9 @@ public class FetchPhase implements SearchPhase {
|
||||||
// go over and extract fields that are not mapped / stored
|
// go over and extract fields that are not mapped / stored
|
||||||
context.lookup().setNextReader(subReader);
|
context.lookup().setNextReader(subReader);
|
||||||
context.lookup().setNextDocId(subDoc);
|
context.lookup().setNextDocId(subDoc);
|
||||||
|
if (source != null) {
|
||||||
|
context.lookup().source().setNextSource(source, 0, source.length);
|
||||||
|
}
|
||||||
if (extractFieldNames != null) {
|
if (extractFieldNames != null) {
|
||||||
for (String extractFieldName : extractFieldNames) {
|
for (String extractFieldName : extractFieldNames) {
|
||||||
Object value = context.lookup().source().extractValue(extractFieldName);
|
Object value = context.lookup().source().extractValue(extractFieldName);
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.lucene.document.Fieldable;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.elasticsearch.ElasticSearchParseException;
|
import org.elasticsearch.ElasticSearchParseException;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
|
||||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||||
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
|
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
|
||||||
import org.elasticsearch.index.mapper.internal.SourceFieldSelector;
|
import org.elasticsearch.index.mapper.internal.SourceFieldSelector;
|
||||||
|
@ -45,6 +44,9 @@ public class SourceLookup implements Map {
|
||||||
|
|
||||||
private int docId = -1;
|
private int docId = -1;
|
||||||
|
|
||||||
|
private byte[] sourceAsBytes;
|
||||||
|
private int sourceAsBytesOffset;
|
||||||
|
private int sourceAsBytesLength;
|
||||||
private Map<String, Object> source;
|
private Map<String, Object> source;
|
||||||
|
|
||||||
public Map<String, Object> source() {
|
public Map<String, Object> source() {
|
||||||
|
@ -55,7 +57,10 @@ public class SourceLookup implements Map {
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
XContentParser parser = null;
|
if (sourceAsBytes != null) {
|
||||||
|
source = sourceAsMap(sourceAsBytes, sourceAsBytesOffset, sourceAsBytesLength);
|
||||||
|
return source;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Document doc = reader.document(docId, SourceFieldSelector.INSTANCE);
|
Document doc = reader.document(docId, SourceFieldSelector.INSTANCE);
|
||||||
Fieldable sourceField = doc.getFieldable(SourceFieldMapper.NAME);
|
Fieldable sourceField = doc.getFieldable(SourceFieldMapper.NAME);
|
||||||
|
@ -66,10 +71,6 @@ public class SourceLookup implements Map {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ElasticSearchParseException("failed to parse / load source", e);
|
throw new ElasticSearchParseException("failed to parse / load source", e);
|
||||||
} finally {
|
|
||||||
if (parser != null) {
|
|
||||||
parser.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this.source;
|
return this.source;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +85,7 @@ public class SourceLookup implements Map {
|
||||||
}
|
}
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
this.source = null;
|
this.source = null;
|
||||||
|
this.sourceAsBytes = null;
|
||||||
this.docId = -1;
|
this.docId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,9 +94,16 @@ public class SourceLookup implements Map {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.docId = docId;
|
this.docId = docId;
|
||||||
|
this.sourceAsBytes = null;
|
||||||
this.source = null;
|
this.source = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNextSource(byte[] source, int offset, int length) {
|
||||||
|
this.sourceAsBytes = source;
|
||||||
|
this.sourceAsBytesOffset = offset;
|
||||||
|
this.sourceAsBytesLength = length;
|
||||||
|
}
|
||||||
|
|
||||||
public void setNextSource(Map<String, Object> source) {
|
public void setNextSource(Map<String, Object> source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue