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);
}
}
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);
}
}
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]));
}
Aggregations