@Override public void close() { if (!closed) { searchService.clearScroll(scrollResult); closed = true; pos = -1; } }
/** * Reinitialize the index of a repository. This will drop the existing index, recreate it with its settings and * mapping, the index will be empty. * * @since 7.1 */ default void dropAndInitRepositoryIndex(String repositoryName) { dropAndInitRepositoryIndex(repositoryName, true); }
@Override public boolean hasNext() { checkNotClosed(); return pos < size; }
protected String getESIndexName() { ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); return esa.getIndexNameForType(ElasticSearchConstants.ENTRY_TYPE); }
protected ESClient getESClient() { ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); return esa.getClient(); }
protected String[] getIndexNames() { ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); List<String> repositoryNames = Framework.getService(ElasticSearchAdmin.class).getRepositoryNames(); String indices[] = new String[repositoryNames.size()]; int i = 0; for (String repo : repositoryNames) { indices[i++] = esa.getIndexNameForRepository(repo); } return indices; }
private SearchHit nextHit() { if (relativePos == scrollResult.getElasticsearchResponse().getHits().getHits().length) { // Retrieve next scroll scrollResult = searchService.scroll(scrollResult); relativePos = 0; } SearchHit hit = scrollResult.getElasticsearchResponse().getHits().getAt(relativePos); relativePos++; pos++; return hit; }
@Override public EsScrollResult scroll(EsScrollResult scrollResult) { SearchResponse response = nextScroll(scrollResult.getScrollId(), scrollResult.getKeepAlive()); return getScrollResults(scrollResult.getQueryBuilder(), response, response.getScrollId(), scrollResult.getKeepAlive()); }
@Override public void run() throws NuxeoException { if (StringUtils.isNotBlank(this.query)) { // ES query ElasticSearchService ess = ToutaticeEsQueryHelper.getElasticSearchService(); NxQueryBuilder queryBuilder = new NxQueryBuilder(super.session).fetchFromElasticsearch().nxql(this.query).limit(this.limit); this.iqr = ess.queryAndAggregate(queryBuilder).getRows(); } else { throw new NuxeoException("No query defined."); } }
/** * Reindex documents matching the NXQL query, This is done in an asynchronous job. * * @since 7.1 */ default void runReindexingWorker(String repositoryName, String nxql) { runReindexingWorker(repositoryName, nxql, false); }
public static EsScrollResult unrestrictedScroll(ElasticSearchService ess, EsScrollResult currentResults) { return ess.scroll(currentResults); }
@Override public void skipTo(long pos) { checkNotClosed(); if (pos < this.pos) { throw new IllegalArgumentException("Cannot go back in Iterable."); } else if (pos > size) { pos = size; } else { while (pos > this.pos) { nextHit(); } } this.pos = pos; }
SearchResponse runRequest(SearchRequest request) { logSearchRequest(request); SearchResponse response = esClient.search(request); logSearchResponse(response); return response; }
@Override public void close() { ClearScrollRequest request = new ClearScrollRequest(); request.addScrollId(scrollId); esClient.clearScroll(request); end = true; // Call super close to clear cursor super.close(); }
@SuppressWarnings("deprecation") @Override public boolean isLife() { return mustBeClosed(); }
protected void checkClusterHealth(String... indexNames) { if (client == null) { throw new IllegalStateException("No Elasticsearch Client available"); } client.waitForYellowStatus(indexNames, TIMEOUT_WAIT_FOR_CLUSTER_SECOND); }
@Override public void clearScroll(EsScrollResult scrollResult) { clearScroll(scrollResult.getScrollId()); }
@Override public DocumentModelList query(NxQueryBuilder queryBuilder) { return queryAndAggregate(queryBuilder).getDocuments(); }
protected EsScrollResult getScrollResults(NxQueryBuilder queryBuilder, SearchResponse response, String scrollId, long keepAlive) { if (queryBuilder.returnsDocuments()) { DocumentModelListImpl docs = getDocumentModels(queryBuilder, response); return new EsScrollResult(docs, response, queryBuilder, scrollId, keepAlive); } else if (queryBuilder.returnsRows()) { IterableQueryResult rows = getRows(queryBuilder, response); return new EsScrollResult(rows, response, queryBuilder, scrollId, keepAlive); } return new EsScrollResult(response, queryBuilder, scrollId, keepAlive); }
@Override public void flushRepositoryIndex(String repositoryName) { log.warn("Flushing index associated with repo: " + repositoryName); getClient().flush(getWriteIndexName(getIndexNameForRepository(repositoryName))); log.info("Flushing index done"); }