Search in sources :

Example 1 with IndexResponse

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);
}
Also used : CreateIndexResponse(co.elastic.clients.elasticsearch.indices.CreateIndexResponse) DeleteIndexResponse(co.elastic.clients.elasticsearch.indices.DeleteIndexResponse) IndexResponse(co.elastic.clients.elasticsearch.core.IndexResponse) Map(java.util.Map) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener)

Example 2 with IndexResponse

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());
}
Also used : CreateIndexResponse(co.elastic.clients.elasticsearch.indices.CreateIndexResponse) GetIndexResponse(co.elastic.clients.elasticsearch.indices.GetIndexResponse) IndexResponse(co.elastic.clients.elasticsearch.core.IndexResponse) Test(org.junit.Test)

Example 3 with IndexResponse

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";
}
Also used : JobExecutionException(org.quartz.JobExecutionException) IndexResponse(co.elastic.clients.elasticsearch.core.IndexResponse) Map(java.util.Map) IOException(java.io.IOException) JobExecutionException(org.quartz.JobExecutionException)

Aggregations

IndexResponse (co.elastic.clients.elasticsearch.core.IndexResponse)3 CreateIndexResponse (co.elastic.clients.elasticsearch.indices.CreateIndexResponse)2 Map (java.util.Map)2 DeleteIndexResponse (co.elastic.clients.elasticsearch.indices.DeleteIndexResponse)1 GetIndexResponse (co.elastic.clients.elasticsearch.indices.GetIndexResponse)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 JobExecutionException (org.quartz.JobExecutionException)1 TransactionalEventListener (org.springframework.transaction.event.TransactionalEventListener)1