本文整理汇总了Java中org.elasticsearch.indices.IndexAlreadyExistsException类的典型用法代码示例。如果您正苦于以下问题:Java IndexAlreadyExistsException类的具体用法?Java IndexAlreadyExistsException怎么用?Java IndexAlreadyExistsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndexAlreadyExistsException类属于org.elasticsearch.indices包,在下文中一共展示了IndexAlreadyExistsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setException
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
private void setException(SettableFuture<Long> result, Throwable e, CreateTableAnalyzedStatement statement) {
e = Exceptions.unwrap(e);
String message = e.getMessage();
// sometimes message is empty
if ("mapping [default]".equals(message) && e.getCause() != null) {
// this is a generic mapping parse exception,
// the cause has usually a better more detailed error message
result.setException(e.getCause());
} else if (statement.ifNotExists() &&
(e instanceof IndexAlreadyExistsException
|| (e instanceof IndexTemplateAlreadyExistsException && statement.templateName() != null))) {
result.set(null);
} else {
result.setException(e);
}
}
示例2: createIndexAndExecuteUpsertRequest
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
private void createIndexAndExecuteUpsertRequest(final UpsertByIdNode.Item item,
final SettableFuture<TaskResult> futureResult) {
transportCreateIndexAction.execute(
new CreateIndexRequest(item.index()).cause("upsert single item"),
new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse createIndexResponse) {
executeUpsertRequest(item, futureResult);
}
@Override
public void onFailure(Throwable e) {
e = ExceptionsHelper.unwrapCause(e);
if (e instanceof IndexAlreadyExistsException) {
executeUpsertRequest(item, futureResult);
} else {
futureResult.setException(e);
}
}
});
}
示例3: doExecute
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
@Override
protected void doExecute(final Task task, final DeleteRequest request, final ActionListener<DeleteResponse> listener) {
ClusterState state = clusterService.state();
if (autoCreateIndex.shouldAutoCreate(request.index(), state)) {
createIndexAction.execute(task, new CreateIndexRequest(request).index(request.index()).cause("auto(delete api)")
.masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse result) {
innerExecute(task, request, listener);
}
@Override
public void onFailure(Throwable e) {
if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
// we have the index, do it
innerExecute(task, request, listener);
} else {
listener.onFailure(e);
}
}
});
} else {
innerExecute(task, request, listener);
}
}
示例4: updateIndexName
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
private void updateIndexName(Configuration config) {
this.logIndexPrefix = config.getProperty("workflow.elasticsearch.tasklog.index.name", "task_log");
this.logIndexName = this.logIndexPrefix + "_" + sdf.format(new Date());
try {
client.admin().indices().prepareGetIndex().addIndices(logIndexName).execute().actionGet();
} catch (IndexNotFoundException infe) {
try {
client.admin().indices().prepareCreate(logIndexName).execute().actionGet();
} catch (IndexAlreadyExistsException ilee) {
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
示例5: createLiferayIndexInESServer
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
/**
* Creates the liferay index in Elasticsearch server with default dynamic
* mapping template.
*/
private void createLiferayIndexInESServer() {
try {
CreateIndexResponse createIndexResponse = client.admin().indices()
.prepareCreate(ElasticsearchIndexerConstants.ELASTIC_SEARCH_LIFERAY_INDEX)
.addMapping("_default_", loadMappings())
.setSettings(loadSettings())
.execute().actionGet();
_log.info("Index created with dynamic template mapping provided, Result:"
+ createIndexResponse.isAcknowledged());
} catch (IndexAlreadyExistsException iaeEx) {
_log.warn("Index already exists, no need to create again....");
} catch (Exception e) {
_log.error("Failed to load file for elasticsearch mapping settings", e);
}
}
示例6: createContentIndex
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
public static boolean createContentIndex(Client esClient, String name) {
checkNotNull(esClient);
ActionFuture<IndicesExistsResponse> exists = esClient.admin().indices().exists(
Requests.indicesExistsRequest(name)
);
if (!timeoutGet(exists).isExists()) {
try {
LOG.info("Creating index {}", name);
timeoutGet(esClient.admin().indices().create(Requests.createIndexRequest(name)));
} catch (IndexAlreadyExistsException e) {
LOG.info("Index already exists: {}", e);
return false;
}
return true;
} else {
LOG.info("Index {} exists", name);
return false;
}
}
示例7: start
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
@Override
public void start() {
logger.info("starting Jolokia river: hosts [{}], uri [{}], strategy [{}], index [{}]/[{}]",
riverSetting.getHosts(), riverSetting.getUrl(), strategy, indexName, typeName);
try {
riverFlow.startDate(new Date());
riverMouth.createIndexIfNotExists(indexSettings, typeMapping);
} catch (Exception e) {
if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
riverFlow.startDate(null);
// that's fine, continue.
} else if (ExceptionsHelper.unwrapCause(e) instanceof ClusterBlockException) {
// ok, not recovered yet..., lets start indexing and hope we recover by the first bulk
} else {
logger.warn("failed to create index [{}], disabling Jolokia river...", e, indexName);
return;
}
}
thread = EsExecutors.daemonThreadFactory(settings.globalSettings(), "Jolokia river [" + riverName.name() + '/' + strategy + ']')
.newThread(riverFlow);
thread.start();
}
示例8: validateAndFilterExistingIndices
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
private void validateAndFilterExistingIndices(ClusterState currentState,
List<String> indicesToCreate,
BulkCreateIndicesRequest request) {
for (String index : request.indices()) {
try {
createIndexService.validateIndexName(index, currentState);
indicesToCreate.add(index);
} catch (IndexAlreadyExistsException e) {
// ignore
}
}
}
示例9: esToCrateException
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
/**
* Returns the cause throwable of a {@link org.elasticsearch.transport.RemoteTransportException}
* and {@link org.elasticsearch.action.search.ReduceSearchPhaseException}.
* Also transform throwable to {@link io.crate.exceptions.CrateException}.
*/
private Throwable esToCrateException(Throwable e) {
e = Exceptions.unwrap(e);
if (e instanceof IllegalArgumentException || e instanceof ParsingException) {
return new SQLParseException(e.getMessage(), (Exception) e);
} else if (e instanceof UnsupportedOperationException) {
return new UnsupportedFeatureException(e.getMessage(), (Exception) e);
} else if (e instanceof DocumentAlreadyExistsException) {
return new DuplicateKeyException(
"A document with the same primary key exists already", e);
} else if (e instanceof IndexAlreadyExistsException) {
return new TableAlreadyExistsException(((IndexAlreadyExistsException) e).getIndex(), e);
} else if ((e instanceof InvalidIndexNameException)) {
if (e.getMessage().contains("already exists as alias")) {
// treat an alias like a table as aliases are not officially supported
return new TableAlreadyExistsException(((InvalidIndexNameException) e).getIndex(),
e);
}
return new InvalidTableNameException(((InvalidIndexNameException) e).getIndex(), e);
} else if (e instanceof InvalidIndexTemplateException) {
PartitionName partitionName = PartitionName.fromIndexOrTemplate(((InvalidIndexTemplateException) e).name());
return new InvalidTableNameException(partitionName.tableIdent().fqn(), e);
} else if (e instanceof IndexNotFoundException) {
return new TableUnknownException(((IndexNotFoundException) e).getIndex(), e);
} else if (e instanceof org.elasticsearch.common.breaker.CircuitBreakingException) {
return new CircuitBreakingException(e.getMessage());
} else if (e instanceof InterruptedException) {
return new JobKilledException();
} else if (e instanceof RepositoryMissingException) {
return new RepositoryUnknownException(((RepositoryMissingException) e).repository());
} else if (e instanceof SnapshotMissingException) {
return new SnapshotUnknownException(((SnapshotMissingException) e).snapshot(), e);
} else if (e instanceof InvalidSnapshotNameException) {
if (((InvalidSnapshotNameException) e).getDetailedMessage().contains("snapshot with such name already exists")) {
return new SnapShotAlreadyExistsExeption(((InvalidSnapshotNameException) e).snapshot());
}
}
return e;
}
示例10: validateIndexName
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
public void validateIndexName(String index, ClusterState state) {
if (state.routingTable().hasIndex(index)) {
throw new IndexAlreadyExistsException(new Index(index));
}
if (state.metaData().hasIndex(index)) {
throw new IndexAlreadyExistsException(new Index(index));
}
if (!Strings.validFileName(index)) {
throw new InvalidIndexNameException(new Index(index), index, "must not contain the following characters " + Strings.INVALID_FILENAME_CHARS);
}
if (index.contains("#")) {
throw new InvalidIndexNameException(new Index(index), index, "must not contain '#'");
}
if (index.charAt(0) == '_') {
throw new InvalidIndexNameException(new Index(index), index, "must not start with '_'");
}
if (!index.toLowerCase(Locale.ROOT).equals(index)) {
throw new InvalidIndexNameException(new Index(index), index, "must be lowercase");
}
int byteCount = 0;
try {
byteCount = index.getBytes("UTF-8").length;
} catch (UnsupportedEncodingException e) {
// UTF-8 should always be supported, but rethrow this if it is not for some reason
throw new ElasticsearchException("Unable to determine length of index name", e);
}
if (byteCount > MAX_INDEX_NAME_BYTES) {
throw new InvalidIndexNameException(new Index(index), index,
"index name is too long, (" + byteCount +
" > " + MAX_INDEX_NAME_BYTES + ")");
}
if (state.metaData().hasAlias(index)) {
throw new InvalidIndexNameException(new Index(index), index, "already exists as alias");
}
if (index.equals(".") || index.equals("..")) {
throw new InvalidIndexNameException(new Index(index), index, "must not be '.' or '..'");
}
}
示例11: masterOperation
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
@Override
protected void masterOperation(final CreateIndexRequest request, final ClusterState state, final ActionListener<CreateIndexResponse> listener) {
String cause = request.cause();
if (cause.length() == 0) {
cause = "api";
}
final String indexName = indexNameExpressionResolver.resolveDateMathExpression(request.index());
final CreateIndexClusterStateUpdateRequest updateRequest = new CreateIndexClusterStateUpdateRequest(request, cause, indexName, request.updateAllTypes())
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
.settings(request.settings()).mappings(request.mappings())
.aliases(request.aliases()).customs(request.customs());
createIndexService.createIndex(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {
@Override
public void onResponse(ClusterStateUpdateResponse response) {
listener.onResponse(new CreateIndexResponse(response.isAcknowledged()));
}
@Override
public void onFailure(Throwable t) {
if (t instanceof IndexAlreadyExistsException) {
logger.trace("[{}] failed to create", t, request.index());
} else {
logger.debug("[{}] failed to create", t, request.index());
}
listener.onFailure(t);
}
});
}
示例12: doExecute
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
@Override
protected void doExecute(final UpdateRequest request, final ActionListener<UpdateResponse> listener) {
// if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
if (autoCreateIndex.shouldAutoCreate(request.index(), clusterService.state())) {
createIndexAction.execute(new CreateIndexRequest(request).index(request.index()).cause("auto(update api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse result) {
innerExecute(request, listener);
}
@Override
public void onFailure(Throwable e) {
if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
// we have the index, do it
try {
innerExecute(request, listener);
} catch (Throwable e1) {
listener.onFailure(e1);
}
} else {
listener.onFailure(e);
}
}
});
} else {
innerExecute(request, listener);
}
}
示例13: doExecute
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
@Override
protected void doExecute(final Task task, final IndexRequest request, final ActionListener<IndexResponse> listener) {
// if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
ClusterState state = clusterService.state();
if (autoCreateIndex.shouldAutoCreate(request.index(), state)) {
CreateIndexRequest createIndexRequest = new CreateIndexRequest(request);
createIndexRequest.index(request.index());
createIndexRequest.mapping(request.type());
createIndexRequest.cause("auto(index api)");
createIndexRequest.masterNodeTimeout(request.timeout());
createIndexAction.execute(task, createIndexRequest, new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse result) {
innerExecute(task, request, listener);
}
@Override
public void onFailure(Throwable e) {
if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
// we have the index, do it
try {
innerExecute(task, request, listener);
} catch (Throwable e1) {
listener.onFailure(e1);
}
} else {
listener.onFailure(e);
}
}
});
} else {
innerExecute(task, request, listener);
}
}
示例14: createIndexAndMapping
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
private void createIndexAndMapping(Client client) {
// Create the Index and Mappings before indexing the entities:
try {
createIndex(client, getIndexName());
createMapping(client, getIndexName(), getMapping());
} catch (IndexAlreadyExistsException e) {
// No need to worry. Someone else has already initialized the Elasticsearch database...
}
}
示例15: createIndex
import org.elasticsearch.indices.IndexAlreadyExistsException; //导入依赖的package包/类
private void createIndex(final String type, final String indexName) {
// 加载配置文件
final String indexConfig = indexConfigLoader.load(type);
// 创建索引
try {
client.admin().indices().prepareCreate(indexName).setSource(indexConfig).execute().actionGet();
} catch (IndexAlreadyExistsException ex) {
log.error("conflict while create index: {}, it's not serious.", indexName);
}
}