Search in sources :

Example 1 with IndexException

use of com.enonic.xp.repository.IndexException in project xp by enonic.

the class IndexServiceInternalImpl method openIndices.

@Override
public void openIndices(final String... indices) {
    for (final String indexName : indices) {
        OpenIndexRequestBuilder openIndexRequestBuilder = new OpenIndexRequestBuilder(this.client.admin().indices(), OpenIndexAction.INSTANCE).setIndices(indexName);
        try {
            this.client.admin().indices().open(openIndexRequestBuilder.request()).actionGet();
            LOG.info("Opened index " + indexName);
        } catch (ElasticsearchException e) {
            LOG.error("Could not open index [" + indexName + "]", e);
            throw new IndexException("Cannot open index [" + indexName + "]", e);
        }
    }
}
Also used : IndexException(com.enonic.xp.repository.IndexException) OpenIndexRequestBuilder(org.elasticsearch.action.admin.indices.open.OpenIndexRequestBuilder) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 2 with IndexException

use of com.enonic.xp.repository.IndexException in project xp by enonic.

the class IndexServiceInternalImpl method getIndexMapping.

@Override
public Map<String, Object> getIndexMapping(final RepositoryId repositoryId, final Branch branch, final IndexType indexType) {
    if (repositoryId == null || indexType == null) {
        return null;
    }
    final String indexName = IndexType.SEARCH == indexType ? IndexNameResolver.resolveSearchIndexName(repositoryId) : IndexNameResolver.resolveStorageIndexName(repositoryId);
    final ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> repoMappings = this.client.admin().indices().getMappings(new GetMappingsRequest().indices(indexName)).actionGet(GET_SETTINGS_TIMEOUT).getMappings();
    final ImmutableOpenMap<String, MappingMetaData> indexTypeMappings = repoMappings.get(indexName);
    final MappingMetaData mappingMetaData = indexTypeMappings.get(branch.getValue());
    try {
        return mappingMetaData.getSourceAsMap();
    } catch (IOException e) {
        throw new IndexException("Failed to get index mapping of index: " + indexName, e);
    }
}
Also used : IndexException(com.enonic.xp.repository.IndexException) IOException(java.io.IOException) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest)

Example 3 with IndexException

use of com.enonic.xp.repository.IndexException in project xp by enonic.

the class IndexServiceInternalImpl method updateIndex.

@Override
public void updateIndex(final String indexName, final UpdateIndexSettings settings) {
    LOG.info("updating index {}", indexName);
    final UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest().indices(indexName).settings(settings.getSettingsAsString());
    try {
        final UpdateSettingsResponse updateSettingsResponse = client.admin().indices().updateSettings(updateSettingsRequest).actionGet(UPDATE_INDEX_TIMEOUT);
        LOG.info("Index {} updated with status {}", indexName, updateSettingsResponse.isAcknowledged());
    } catch (ElasticsearchException e) {
        throw new IndexException("Failed to update index: " + indexName, e);
    }
}
Also used : UpdateSettingsResponse(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse) IndexException(com.enonic.xp.repository.IndexException) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 4 with IndexException

use of com.enonic.xp.repository.IndexException in project xp by enonic.

the class StoreExecutor method execute.

public void execute(final Collection<IndexDocument> indexDocuments) {
    for (IndexDocument indexDocument : indexDocuments) {
        final String id = indexDocument.getId();
        final XContentBuilder xContentBuilder = StoreDocumentXContentBuilderFactory.create(indexDocument);
        final IndexRequest req = Requests.indexRequest().id(id).index(indexDocument.getIndexName()).type(indexDocument.getIndexTypeName()).source(xContentBuilder).refresh(indexDocument.isRefreshAfterOperation());
        try {
            this.client.index(req).actionGet(storeTimeout);
        } catch (Exception e) {
            final String msg = "Failed to store document with id [" + id + "] in index [" + indexDocument.getIndexName() + "] branch " + indexDocument.getIndexTypeName();
            LOG.error(msg, e);
            throw new IndexException(msg, e);
        }
    }
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) IndexException(com.enonic.xp.repository.IndexException) IndexRequest(org.elasticsearch.action.index.IndexRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexException(com.enonic.xp.repository.IndexException)

Example 5 with IndexException

use of com.enonic.xp.repository.IndexException in project xp by enonic.

the class StoreDocumentXContentBuilderFactory method create.

public static XContentBuilder create(final IndexDocument indexDocument) {
    try {
        final XContentBuilder builder = startBuilder();
        addDocumentAnalyzer(builder, indexDocument);
        addIndexDocumentItems(builder, indexDocument);
        endBuilder(builder);
        return builder;
    } catch (Exception e) {
        throw new IndexException("Failed to build xContent for indexSource", e);
    }
}
Also used : IndexException(com.enonic.xp.repository.IndexException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexException(com.enonic.xp.repository.IndexException)

Aggregations

IndexException (com.enonic.xp.repository.IndexException)8 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)2 IndexType (com.enonic.xp.index.IndexType)1 IndexDocument (com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument)1 UpdateIndexSettings (com.enonic.xp.repo.impl.index.UpdateIndexSettings)1 IndexMapping (com.enonic.xp.repository.IndexMapping)1 IndexSettings (com.enonic.xp.repository.IndexSettings)1 RepositoryId (com.enonic.xp.repository.RepositoryId)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 GetMappingsRequest (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest)1 OpenIndexRequestBuilder (org.elasticsearch.action.admin.indices.open.OpenIndexRequestBuilder)1 UpdateSettingsRequest (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)1 UpdateSettingsResponse (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1