Search in sources :

Example 6 with IndexException

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

the class IndexServiceInternalImpl method createIndex.

@Override
public void createIndex(final com.enonic.xp.repo.impl.index.CreateIndexRequest request) {
    final String indexName = request.getIndexName();
    final IndexSettings indexSettings = request.getIndexSettings();
    LOG.info("creating index {}", indexName);
    CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
    createIndexRequest.settings(indexSettings.getAsString());
    if (request.getMappings() != null) {
        for (Map.Entry<IndexType, IndexMapping> mappingEntry : request.getMappings().entrySet()) {
            createIndexRequest.mapping(mappingEntry.getKey().isDynamicTypes() ? ES_DEFAULT_INDEX_TYPE_NAME : mappingEntry.getKey().getName(), mappingEntry.getValue().getAsString());
        }
    }
    try {
        final CreateIndexResponse createIndexResponse = client.admin().indices().create(createIndexRequest).actionGet(CREATE_INDEX_TIMEOUT);
        LOG.info("Index {} created with status {}", indexName, createIndexResponse.isAcknowledged());
    } catch (ElasticsearchException e) {
        throw new IndexException("Failed to create index: " + indexName, e);
    }
}
Also used : IndexMapping(com.enonic.xp.repository.IndexMapping) IndexException(com.enonic.xp.repository.IndexException) UpdateIndexSettings(com.enonic.xp.repo.impl.index.UpdateIndexSettings) IndexSettings(com.enonic.xp.repository.IndexSettings) ElasticsearchException(org.elasticsearch.ElasticsearchException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) IndexType(com.enonic.xp.index.IndexType) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) Map(java.util.Map)

Example 7 with IndexException

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

the class XContentBuilderFactory method create.

static XContentBuilder create(final StoreRequest doc) {
    try {
        final XContentBuilder builder = startBuilder();
        final Multimap<String, Object> values = doc.getEntries();
        for (final String key : values.keySet()) {
            addField(builder, key, values.get(key));
        }
        endBuilder(builder);
        return builder;
    } catch (Exception e) {
        throw new IndexException("Failed to build xContent for StorageDocument", e);
    }
}
Also used : IndexException(com.enonic.xp.repository.IndexException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexException(com.enonic.xp.repository.IndexException)

Example 8 with IndexException

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

the class RefreshCommand method execute.

public void execute() {
    final RepositoryId repositoryId = ContextAccessor.current().getRepositoryId();
    if (!indexServiceInternal.indicesExists(IndexNameResolver.resolveStorageIndexName(repositoryId))) {
        throw new IndexException("Cannot refresh index, index for repository [" + repositoryId + "] does not exist");
    }
    final List<String> indices = new ArrayList<>();
    if (refreshMode.equals(RefreshMode.ALL)) {
        indices.addAll(IndexNameResolver.resolveIndexNames(repositoryId));
    } else if (refreshMode.equals(RefreshMode.SEARCH)) {
        indices.add(IndexNameResolver.resolveSearchIndexName(repositoryId));
    } else {
        indices.add(IndexNameResolver.resolveStorageIndexName(repositoryId));
    }
    this.indexServiceInternal.refresh(indices.toArray(new String[0]));
}
Also used : IndexException(com.enonic.xp.repository.IndexException) ArrayList(java.util.ArrayList) RepositoryId(com.enonic.xp.repository.RepositoryId)

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