From 1f75d05a2a70ae5be42632d83caa2a2373178c8c Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Thu, 11 Aug 2016 11:39:01 +0200 Subject: [PATCH] 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. --- .../fetch/version/VersionFetchSubPhase.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/fetch/version/VersionFetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/version/VersionFetchSubPhase.java index 6ecc1a2988a..0ee1112d9b9 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/version/VersionFetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/version/VersionFetchSubPhase.java @@ -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); }