@Override public long version() { return this.searchHit.version(); }
@Override public long version() { return sh.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); } } }
searchHit.version(get(Fields._VERSION, values, -1L)); searchHit.sortValues(get(Fields.SORT, values, SearchSortValues.EMPTY)); searchHit.highlightFields(get(Fields.HIGHLIGHT, values, null));
@Override public GetResponse getDelegatedFromInstigator(final SearchResponse searchResponse) { if (searchResponse.getHits().getTotalHits() <= 0) { return new GetResponse(new GetResult(request.index(), request.type(), request.id(), request.version(), false, null, null)); } else if (searchResponse.getHits().getTotalHits() > 1) { throw new RuntimeException("cannot happen"); } else { final SearchHit sh = searchResponse.getHits().getHits()[0]; return new GetResponse(new GetResult(sh.index(), sh.type(), sh.id(), sh.version(), true, sh.getSourceRef(), null)); } } });
hitProperties.put("_type", hit.type()); hitProperties.put("_id", hit.id()); hitProperties.put("_version", hit.version());
hitProperties.put("_type", hit.type()); hitProperties.put("_id", hit.id()); hitProperties.put("_version", hit.version());
@Override public GetResponse getDelegatedFromInstigator(final MultiSearchResponse searchResponse) { if (searchResponse.getResponses() == null || searchResponse.getResponses().length <= 0) { final Item item = request.getItems().get(0); return new GetResponse(new GetResult(item.index(), item.type(), item.id(), item.version(), false, null, null)); } else if (searchResponse.getResponses().length > 1) { throw new RuntimeException("cannot happen"); } else { final org.elasticsearch.action.search.MultiSearchResponse.Item item = searchResponse.getResponses()[0]; final SearchHit sh = item.getResponse().getHits().getHits()[0]; return new GetResponse(new GetResult(sh.index(), sh.type(), sh.id(), sh.version(), true, sh.getSourceRef(), null)); } } });
@Override protected IndexRequest buildIndexRequest(SearchHit doc) { IndexRequest index = new IndexRequest(mainRequest); index.index(doc.index()); index.type(doc.type()); index.id(doc.id()); index.source(doc.sourceRef()); index.versionType(VersionType.INTERNAL); index.version(doc.version()); return index; }
@Override protected IndexRequest buildIndexRequest(SearchHit doc) { IndexRequest index = new IndexRequest(mainRequest); index.index(doc.index()); index.type(doc.type()); index.id(doc.id()); index.source(doc.sourceRef()); index.versionType(VersionType.INTERNAL); index.version(doc.version()); return index; }
@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); } } }
searchHit.version(get(Fields._VERSION, values, -1L)); searchHit.sortValues(get(Fields.SORT, values, SearchSortValues.EMPTY)); searchHit.highlightFields(get(Fields.HIGHLIGHT, values, null));
searchHit.version(get(Fields._VERSION, values, -1L)); searchHit.sortValues(get(Fields.SORT, values, SearchSortValues.EMPTY)); searchHit.highlightFields(get(Fields.HIGHLIGHT, values, null));
@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); } }
public static SearchHit createFromMap(Map<String, Object> values) { String id = get(Fields._ID, values, null); Text type = get(Fields._TYPE, values, null); NestedIdentity nestedIdentity = get(NestedIdentity._NESTED, values, null); Map<String, SearchHitField> fields = get(Fields.FIELDS, values, null); SearchHit searchHit = new SearchHit(-1, id, type, nestedIdentity, fields); searchHit.index = get(Fields._INDEX, values, null); searchHit.score(get(Fields._SCORE, values, DEFAULT_SCORE)); searchHit.version(get(Fields._VERSION, values, -1L)); searchHit.sortValues(get(Fields.SORT, values, SearchSortValues.EMPTY)); searchHit.highlightFields(get(Fields.HIGHLIGHT, values, null)); searchHit.sourceRef(get(SourceFieldMapper.NAME, values, null)); searchHit.explanation(get(Fields._EXPLANATION, values, null)); searchHit.setInnerHits(get(Fields.INNER_HITS, values, null)); List<String> matchedQueries = get(Fields.MATCHED_QUERIES, values, null); if (matchedQueries != null) { searchHit.matchedQueries(matchedQueries.toArray(new String[matchedQueries.size()])); } ShardId shardId = get(Fields._SHARD, values, null); String nodeId = get(Fields._NODE, values, null); if (shardId != null && nodeId != null) { searchHit.shard(new SearchShardTarget(nodeId, shardId, null, OriginalIndices.NONE)); } searchHit.fields(fields); return searchHit; }
DeleteRequest delete = new DeleteRequest(request).index(doc.index()).type(doc.type()).id(doc.id()).version(doc.version()); SearchHitField routing = doc.field("_routing"); if (routing != null) {
index.version(mainRequest.getDestination().version()); } else { index.version(doc.version());
index.version(mainRequest.getDestination().version()); } else { index.version(doc.version());