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