@Override public boolean version() { return in.version(); }
@Override public void version(boolean version) { in.version(version); }
@Override public boolean hitExecutionNeeded(SearchContext context) { return context.version(); }
@Override public boolean version() { return in.version(); }
@Override public void version(boolean version) { in.version(version); }
@Override public void version(boolean version) { in.version(version); }
@Override public void version(boolean version) { in.version(version); }
@Override public boolean version() { return in.version(); }
@Override public boolean version() { return in.version(); }
@Override public void version(boolean version) { in.version(version); }
@Override public boolean version() { return in.version(); }
@Override public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOException { if (context.version() == false || (context.storedFieldsContext() != null && context.storedFieldsContext().fetchFields() == false)) { return; } hits = hits.clone(); // don't modify the incoming hits Arrays.sort(hits, Comparator.comparingInt(SearchHit::docId)); int lastReaderId = -1; NumericDocValues versions = null; for (SearchHit hit : hits) { int readerId = ReaderUtil.subIndex(hit.docId(), context.searcher().getIndexReader().leaves()); LeafReaderContext subReaderContext = context.searcher().getIndexReader().leaves().get(readerId); if (lastReaderId != readerId) { versions = subReaderContext.reader().getNumericDocValues(VersionFieldMapper.NAME); lastReaderId = readerId; } int docId = hit.docId() - subReaderContext.docBase; long version = Versions.NOT_FOUND; if (versions != null && versions.advanceExact(docId)) { version = versions.longValue(); } hit.version(version < 0 ? -1 : version); } } }
@Override public void parse(XContentParser parser, SearchContext context) throws Exception { XContentParser.Token token = parser.currentToken(); if (token.isValue()) { context.version(parser.booleanValue()); } } }
@Override public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOException { if (context.version() == false || (context.storedFieldsContext() != null && context.storedFieldsContext().fetchFields() == false)) { return; } hits = hits.clone(); // don't modify the incoming hits Arrays.sort(hits, Comparator.comparingInt(SearchHit::docId)); int lastReaderId = -1; NumericDocValues versions = null; for (SearchHit hit : hits) { int readerId = ReaderUtil.subIndex(hit.docId(), context.searcher().getIndexReader().leaves()); LeafReaderContext subReaderContext = context.searcher().getIndexReader().leaves().get(readerId); if (lastReaderId != readerId) { versions = subReaderContext.reader().getNumericDocValues(VersionFieldMapper.NAME); lastReaderId = readerId; } int docId = hit.docId() - subReaderContext.docBase; long version = Versions.NOT_FOUND; if (versions != null && versions.advanceExact(docId)) { version = versions.longValue(); } hit.version(version < 0 ? -1 : version); } } }
@Override public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOException { if (context.version() == false || (context.storedFieldsContext() != null && context.storedFieldsContext().fetchFields() == false)) { return; } hits = hits.clone(); // don't modify the incoming hits Arrays.sort(hits, Comparator.comparingInt(SearchHit::docId)); int lastReaderId = -1; NumericDocValues versions = null; for (SearchHit hit : hits) { int readerId = ReaderUtil.subIndex(hit.docId(), context.searcher().getIndexReader().leaves()); LeafReaderContext subReaderContext = context.searcher().getIndexReader().leaves().get(readerId); if (lastReaderId != readerId) { versions = subReaderContext.reader().getNumericDocValues(VersionFieldMapper.NAME); lastReaderId = readerId; } int docId = hit.docId() - subReaderContext.docBase; long version = Versions.NOT_FOUND; if (versions != null && versions.advanceExact(docId)) { version = versions.longValue(); } hit.version(version < 0 ? -1 : version); } } }
@Override public void hitExecute(SearchContext context, HitContext hitContext) { if (context.version() == false || (context.storedFieldsContext() != null && context.storedFieldsContext().fetchFields() == false)) { return; } long version = Versions.NOT_FOUND; if (context.indexShard().getEngine() instanceof VersionLessInternalEngine) { version = 1; } else { try { NumericDocValues versions = hitContext.reader().getNumericDocValues(VersionFieldMapper.NAME); if (versions != null) { version = versions.get(hitContext.docId()); } } catch (IOException e) { throw new ElasticsearchException("Could not retrieve version", e); } } hitContext.hit().version(version < 0 ? -1 : version); } }