VersionFetchSubPhase should not use Versions#loadDocIdAndVersion
Since we already know the docId, the PK lookup is useless and we can directly get the value from the numeric doc values.
This commit is contained in:
parent
a1538de1a1
commit
1f75d05a2a
|
@ -18,12 +18,10 @@
|
|||
*/
|
||||
package org.elasticsearch.search.fetch.version;
|
||||
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.index.NumericDocValues;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
import org.elasticsearch.index.mapper.Uid;
|
||||
import org.elasticsearch.index.mapper.UidFieldMapper;
|
||||
import org.elasticsearch.index.mapper.VersionFieldMapper;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhase;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
|
@ -36,18 +34,14 @@ public final class VersionFetchSubPhase implements FetchSubPhase {
|
|||
if (context.version() == false) {
|
||||
return;
|
||||
}
|
||||
// it might make sense to cache the TermDocs on a shared fetch context and just skip here)
|
||||
// it is going to mean we work on the high level multi reader and not the lower level reader as is
|
||||
// the case below...
|
||||
final long version;
|
||||
long version = Versions.NOT_FOUND;
|
||||
try {
|
||||
BytesRef uid = Uid.createUidAsBytes(hitContext.hit().type(), hitContext.hit().id());
|
||||
version = Versions.loadVersion(
|
||||
hitContext.readerContext().reader(),
|
||||
new Term(UidFieldMapper.NAME, uid)
|
||||
);
|
||||
NumericDocValues versions = hitContext.reader().getNumericDocValues(VersionFieldMapper.NAME);
|
||||
if (versions != null) {
|
||||
version = versions.get(hitContext.docId());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("Could not query index for _version", e);
|
||||
throw new ElasticsearchException("Could not retrieve version", e);
|
||||
}
|
||||
hitContext.hit().version(version < 0 ? -1 : version);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue