@Override public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { long totalHits = response.getHits().getTotalHits(); float maxScore = response.getHits().getMaxScore(); List<T> results = new ArrayList<>(); for (SearchHit hit : response.getHits()) { if (hit != null) { T result = null; if (!StringUtils.isEmpty(hit.getSourceAsString())) { result = mapEntity(hit.getSourceAsString(), clazz); } else { result = mapEntity(hit.getFields().values(), clazz); } setPersistentEntityId(result, hit.getId(), clazz); setPersistentEntityVersion(result, hit.getVersion(), clazz); setPersistentEntityScore(result, hit.getScore(), clazz); populateScriptFields(result, hit); results.add(result); } } return new AggregatedPageImpl<T>(results, pageable, totalHits, response.getAggregations(), response.getScrollId(), maxScore); }
@Override public long getVersion() { return delegate.getVersion(); }
@Override public long getVersion() { return delegate.getVersion(); }
@Override public long getVersion() { return delegate.getVersion(); }
@Override public long getVersion() { return delegate.getVersion(); }
@Override public long getVersion() { return this.searchHit.getVersion(); }
protected <E extends EsInstance> E getInstanceByIdForClass(String instanceId, Class objectClass) throws Exception { SearchResponse response = this.retrieveByField("id", instanceId, objectClass); if (response.getHits().totalHits() > 0) { String str = response.getHits().getAt(0).getSourceAsString(); E inst = (E) insertMapper.readValue(str, objectClass); inst.setVersion(response.getHits().getAt(0).getVersion()); return inst; } return null; }
private void enumerateHits(ObjectOutputStream objectOutputStream, SearchHit[] hits) throws IOException { for (SearchHit hit : hits) { idAndVersionFactory.create(hit.getId(), hit.getVersion()).writeToStream(objectOutputStream); numItems++; } }
@Override public EsDailySnapshotInstance getInstanceById(String instanceId) throws Exception { SearchResponse response = this.retrieveByField("_id", instanceId, EsDailySnapshotInstance.class); if (response.getHits().totalHits() > 0) { String str = response.getHits().getAt(0).getSourceAsString(); EsDailySnapshotInstance inst = essnapshotinstanceMapper.readValue(str, EsDailySnapshotInstance.class); inst.setId(response.getHits().getAt(0).getId()); inst.setVersion(response.getHits().getAt(0).getVersion()); return inst; } return null; }
public ElasticsearchDocument(SearchHit hit, Function<? super String, ? extends SpatialContext> geoContextMapper) { this(hit.getId(), hit.getType(), hit.getIndex(), hit.getVersion(), hit.getSource(), geoContextMapper); }
ctx.put(TypeFieldMapper.NAME, doc.type()); ctx.put(IdFieldMapper.NAME, doc.id()); Long oldVersion = doc.getVersion(); ctx.put(VersionFieldMapper.NAME, oldVersion); String oldParent = fieldValue(doc, ParentFieldMapper.NAME);
ctx.put(TypeFieldMapper.NAME, doc.type()); ctx.put(IdFieldMapper.NAME, doc.id()); Long oldVersion = doc.getVersion(); ctx.put(VersionFieldMapper.NAME, oldVersion); String oldParent = fieldValue(doc, ParentFieldMapper.NAME);
private <E extends EsDocument> ScrollableResponse<List<E>> convertToScrollableResponse( SearchResponse response, ThrowingFunction<String, E> createFunc) throws Exception { ArrayList<E> list = new ArrayList<>(); ScrollableResponse<List<E>> ret = new ScrollableResponse<>(); ret.setValue(list); ret.setContinousToken(response.getScrollId()); for (int i = 0; i < response.getHits().getHits().length; i++) { String str = response.getHits().getAt(i).getSourceAsString(); E element = createFunc.apply(str); element.setId(response.getHits().getAt(i).getId()); element.setVersion(response.getHits().getAt(i).getVersion()); list.add(element); } return ret; } }
result.initSourceTracing(); result.setId(hit.getId()); result.setVersion(hit.getVersion()); result.setMatchedNamedQueries(hit.getMatchedQueries()); indexAccess.getDescriptor(clazz).readSource(result, hit.getSourceAsMap());
entity.initSourceTracing(); entity.setId(hit.getId()); entity.setVersion(hit.getVersion()); entity.setMatchedNamedQueries(hit.getMatchedQueries()); descriptor.readSource(entity, hit.getSourceAsMap());
/** * Helper method which can be used to parse a {@link SearchHit} into a POJO. This can be useful when using * aggregations to transform raw {@link SearchHit}s. * * @param searchHit a raw hit returned by ElasticSearch * @return the raw hit transformed into an object of the desired class */ public E transformHit(SearchHit searchHit) { try { EntityDescriptor descriptor = indexAccess.getDescriptor(clazz); E entity = clazz.newInstance(); entity.initSourceTracing(); entity.setId(searchHit.getId()); entity.setVersion(searchHit.getVersion()); entity.setMatchedNamedQueries(searchHit.getMatchedQueries()); descriptor.readSource(entity, searchHit.getSourceAsMap()); return entity; } catch (Exception e) { throw Exceptions.handle() .error(e) .to(IndexAccess.LOG) .withSystemErrorMessage("Cannot transform SearchHit to POJO: %s", toString()) .handle(); } }
private boolean processHit(ResultHandler<? super E> handler, EntityDescriptor entityDescriptor, TaskContext ctx, RateLimit rateLimit, Limit lim, SearchHit hit) { try { E entity = clazz.newInstance(); entity.setId(hit.getId()); entity.initSourceTracing(); entity.setVersion(hit.getVersion()); entity.setMatchedNamedQueries(hit.getMatchedQueries()); entityDescriptor.readSource(entity, hit.getSourceAsMap()); if (lim.nextRow()) { if (!handler.handleRow(entity)) { return false; } if (!lim.shouldContinue()) { return false; } } if (rateLimit.check() && !ctx.isActive()) { return false; } } catch (Exception e) { Exceptions.handle().to(IndexAccess.LOG).error(e).handle(); } return true; }