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(); }
/** * 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); }
public RequestValidator() { ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); indexTypes = new HashMap<>(); for (String name : esa.getRepositoryNames()) { List<String> types = new ArrayList<>(); types.add(ElasticSearchConstants.DOC_TYPE); indexTypes.put(esa.getIndexNameForRepository(name), types); } }
protected String getIndexName(CoreSession session, Map<String, Serializable> properties) { if (properties.containsKey(INDEX_OPTION)) { return (String) properties.get(INDEX_OPTION); } ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); return esa.getWriteIndexName(esa.getIndexNameForRepository(session.getRepositoryName())); }
protected void updateAliasIfNeeded(BulkCommand command) { Boolean updateAlias = command.getParam(INDEX_UPDATE_ALIAS_PARAM); if (Boolean.TRUE.equals(updateAlias)) { log.warn("Update alias requested by command: " + command.getId()); ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); esa.syncSearchAndWriteAlias(esa.getIndexNameForRepository(command.getRepository())); } }
throw new TimeoutException(); esa.prepareWaitForIndexing().get(computeRemainingTime(start), TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); esa.refreshRepositoryIndex(repo.getRepositoryName()); if (waitForAuditStoredInEs) { esa.getClient().refresh(esa.getIndexNameForType(ElasticSearchConstants.ENTRY_TYPE));
@Override public void init() { if (esClient != null) { return; } ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); esClient = esa.getClient(); indexName = esa.getIndexNameForType(ElasticSearchConstants.SEQ_ID_TYPE); try { boolean indexExists = esClient.indexExists(indexName); if (!indexExists) { throw new NuxeoException( String.format("Sequencer %s needs an elasticSearchIndex contribution with type %s", getName(), ElasticSearchConstants.SEQ_ID_TYPE)); } } catch (NoSuchElementException | NuxeoException e) { dispose(); throw e; } }
protected void refreshIndexIfNeeded(BulkCommand command) { Boolean refresh = command.getParam(REFRESH_INDEX_PARAM); if (Boolean.TRUE.equals(refresh)) { log.warn("Refresh index requested by command: " + command.getId()); ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); esa.refreshRepositoryIndex(command.getRepository()); } }
protected static MoreLikeThisQueryBuilder.Item[] getItems(Object value) { RepositoryManager rm = Framework.getService(RepositoryManager.class); String repo = rm.getDefaultRepository().getName(); ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); String esIndex = esa.getIndexNameForRepository(repo); String[] values; if (value instanceof Object[]) { values = (String[]) value; } else { values = new String[] { (String) value }; } MoreLikeThisQueryBuilder.Item[] ret = new MoreLikeThisQueryBuilder.Item[values.length]; for (int i = 0; i < values.length; i++) { ret[i] = new MoreLikeThisQueryBuilder.Item(esIndex, DOC_TYPE, values[i]); } return ret; }
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; }
@Override protected void doWork() { ElasticSearchIndexing esi = Framework.getService(ElasticSearchIndexing.class); openSystemSession(); int bucketSize = Math.min(documentCount, getBucketSize()); List<String> ids = new ArrayList<>(bucketSize); for (DocumentLocation doc : getDocuments()) { ids.add(doc.getIdRef().value); if ((ids.size() % bucketSize) == 0) { esi.indexNonRecursive(getIndexingCommands(session, ids)); ids.clear(); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } } if (!ids.isEmpty()) { esi.indexNonRecursive(getIndexingCommands(session, ids)); ids.clear(); } if (syncAlias) { log.warn(String.format("Re-indexing job: %s completed.", getSchedulePath().getParentPath())); ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); esa.syncSearchAndWriteAlias(esa.getIndexNameForRepository(repositoryName)); } }
@Override public void init(CoreSession session, String indices, String types, String rawQuery, String payload) { principal = session.getPrincipal(); if (!principal.isAdministrator()) { throw new IllegalArgumentException("Invalid index submitted: " + indices); } ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); this.indices = esa.getIndexNameForType(ElasticSearchConstants.ENTRY_TYPE); this.types = ElasticSearchConstants.ENTRY_TYPE; this.rawQuery = rawQuery; this.payload = payload; if (payload == null && !principal.isAdministrator()) { // here we turn the UriSearch query_string into a body search extractPayloadFromQuery(); } }
protected ESClient getClient() { log.info("Activate Elasticsearch backend for Audit"); ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); ESClient client = esa.getClient(); ensureUIDSequencer(client); return client; }
@OperationMethod public Blob run() throws IOException { checkAccess(); esa.dropAndInitRepositoryIndex(session.getRepositoryName(), false); String commandId = submitBulkCommand("SELECT ecm:uuid FROM Document", true); log.warn(String.format("Submitted index command: %s to index the entire %s repository.", commandId, session.getRepositoryName())); return Blobs.createJSONBlobFromValue(Collections.singletonMap("commandId", commandId)); }
@Override public void init(CoreSession session, String indices, String types, String rawQuery, String payload) { this.session = session; principal = session.getPrincipal(); ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); this.indices = esa.getIndexNameForType(ElasticSearchConstants.ENTRY_TYPE); this.types = ElasticSearchConstants.ENTRY_TYPE; this.rawQuery = rawQuery; this.payload = payload; if (payload == null && !principal.isAdministrator()) { // here we turn the UriSearch query_string into a body search extractPayloadFromQuery(); } }
@Override public ProbeStatus run() { String[] indices = getIndexNames(); try { ClusterHealthStatus clusterStatus = Framework.getService(ElasticSearchAdmin.class) .getClient() .getHealthStatus(indices); switch (clusterStatus) { case GREEN: case YELLOW: return ProbeStatus.newSuccess(clusterStatus.toString()); default: return ProbeStatus.newFailure(clusterStatus.toString()); } } catch (NuxeoException e) { return ProbeStatus.newError(e); } }