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:
Jim Ferenczi 2016-08-11 11:39:01 +02:00
parent a1538de1a1
commit 1f75d05a2a
1 changed files with 8 additions and 14 deletions

View File

@ -18,12 +18,10 @@
*/ */
package org.elasticsearch.search.fetch.version; package org.elasticsearch.search.fetch.version;
import org.apache.lucene.index.Term; import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.index.mapper.Uid; import org.elasticsearch.index.mapper.VersionFieldMapper;
import org.elasticsearch.index.mapper.UidFieldMapper;
import org.elasticsearch.search.fetch.FetchSubPhase; import org.elasticsearch.search.fetch.FetchSubPhase;
import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SearchContext;
@ -36,18 +34,14 @@ public final class VersionFetchSubPhase implements FetchSubPhase {
if (context.version() == false) { if (context.version() == false) {
return; return;
} }
// it might make sense to cache the TermDocs on a shared fetch context and just skip here) long version = Versions.NOT_FOUND;
// 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;
try { try {
BytesRef uid = Uid.createUidAsBytes(hitContext.hit().type(), hitContext.hit().id()); NumericDocValues versions = hitContext.reader().getNumericDocValues(VersionFieldMapper.NAME);
version = Versions.loadVersion( if (versions != null) {
hitContext.readerContext().reader(), version = versions.get(hitContext.docId());
new Term(UidFieldMapper.NAME, uid) }
);
} catch (IOException e) { } 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); hitContext.hit().version(version < 0 ? -1 : version);
} }