use of co.elastic.clients.elasticsearch.core.IndexResponse in project syncope by apache.
the class ElasticsearchIndexManager method after.
@TransactionalEventListener
public void after(final AnyCreatedUpdatedEvent<Any<?>> event) throws IOException {
String index = ElasticsearchUtils.getContextDomainName(AuthContextUtils.getDomain(), event.getAny().getType().getKind());
IndexRequest<Map<String, Object>> request = new IndexRequest.Builder<Map<String, Object>>().index(index).id(event.getAny().getKey()).document(elasticsearchUtils.document(event.getAny(), event.getDomain())).build();
IndexResponse response = client.index(request);
LOG.debug("Index successfully created or updated for {}: {}", event.getAny(), response);
}
use of co.elastic.clients.elasticsearch.core.IndexResponse in project elasticsearch-java by elastic.
the class RequestTest method testRefresh.
@Test
public void testRefresh() throws IOException {
AppData appData = new AppData();
appData.setIntValue(42);
appData.setMsg("Some message");
IndexResponse ir = client.index(_0 -> _0.index("test").id("1").document(appData).refresh(Refresh.WaitFor));
assertEquals("1", ir.id());
}
use of co.elastic.clients.elasticsearch.core.IndexResponse in project syncope by apache.
the class ElasticsearchReindex method doExecute.
@Override
protected String doExecute(final boolean dryRun, final String executor, final JobExecutionContext context) throws JobExecutionException {
if (!dryRun) {
LOG.debug("Start rebuilding indexes");
try {
indexManager.createIndex(AuthContextUtils.getDomain(), AnyTypeKind.USER, userSettings(), userMapping());
indexManager.createIndex(AuthContextUtils.getDomain(), AnyTypeKind.GROUP, groupSettings(), groupMapping());
indexManager.createIndex(AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT, anyObjectSettings(), anyObjectMapping());
LOG.debug("Indexing users...");
for (int page = 1; page <= (userDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (String user : userDAO.findAllKeys(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexRequest<Map<String, Object>> request = new IndexRequest.Builder<Map<String, Object>>().index(ElasticsearchUtils.getContextDomainName(AuthContextUtils.getDomain(), AnyTypeKind.USER)).id(user).document(utils.document(userDAO.find(user), AuthContextUtils.getDomain())).build();
try {
IndexResponse response = client.index(request);
LOG.debug("Index successfully created for {}: {}", user, response);
} catch (Exception e) {
LOG.error("Could not create index for {} {}", AnyTypeKind.USER, user);
}
}
}
LOG.debug("Indexing groups...");
for (int page = 1; page <= (groupDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (String group : groupDAO.findAllKeys(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexRequest<Map<String, Object>> request = new IndexRequest.Builder<Map<String, Object>>().index(ElasticsearchUtils.getContextDomainName(AuthContextUtils.getDomain(), AnyTypeKind.GROUP)).id(group).document(utils.document(groupDAO.find(group), AuthContextUtils.getDomain())).build();
try {
IndexResponse response = client.index(request);
LOG.debug("Index successfully created for {}: {}", group, response);
} catch (Exception e) {
LOG.error("Could not create index for {} {}", AnyTypeKind.GROUP, group);
}
}
}
LOG.debug("Indexing any objects...");
for (int page = 1; page <= (anyObjectDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (String anyObject : anyObjectDAO.findAllKeys(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexRequest<Map<String, Object>> request = new IndexRequest.Builder<Map<String, Object>>().index(ElasticsearchUtils.getContextDomainName(AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT)).id(anyObject).document(utils.document(anyObjectDAO.find(anyObject), AuthContextUtils.getDomain())).build();
try {
IndexResponse response = client.index(request);
LOG.debug("Index successfully created for {}: {}", anyObject, response);
} catch (Exception e) {
LOG.error("Could not create index for {} {}", AnyTypeKind.ANY_OBJECT, anyObject);
}
}
}
LOG.debug("Rebuild indexes for domain {} successfully completed", AuthContextUtils.getDomain());
} catch (Exception e) {
throw new JobExecutionException("While rebuilding index for domain " + AuthContextUtils.getDomain(), e);
}
}
return "SUCCESS";
}
Aggregations