use of org.elasticsearch.index.IndexNotFoundException in project graylog2-server by Graylog2.
the class MessageResource method analyze.
@GET
@Path("/{index}/analyze")
@Timed
@ApiOperation(value = "Analyze a message string", notes = "Returns what tokens/terms a message string (message or full_message) is split to.")
@RequiresPermissions(RestPermissions.MESSAGES_ANALYZE)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Specified index does not exist.") })
public MessageTokens analyze(@ApiParam(name = "index", value = "The index the message containing the string is stored in.", required = true) @PathParam("index") String index, @ApiParam(name = "analyzer", value = "The analyzer to use.") @QueryParam("analyzer") @Nullable String analyzer, @ApiParam(name = "string", value = "The string to analyze.", required = true) @QueryParam("string") @NotEmpty String string) {
final String indexAnalyzer = indexSetRegistry.getForIndex(index).map(indexSet -> indexSet.getConfig().indexAnalyzer()).orElse("standard");
final String messageAnalyzer = analyzer == null ? indexAnalyzer : analyzer;
try {
return MessageTokens.create(messages.analyze(string, index, messageAnalyzer));
} catch (IndexNotFoundException e) {
final String message = "Index " + index + " does not exist.";
LOG.error(message, e);
throw new NotFoundException(message);
}
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class BulkShardProcessor method processFailure.
private void processFailure(Throwable e, final ShardId shardId, final Request request, Optional<BulkRetryCoordinator> retryCoordinator) {
trace("execute failure");
e = SQLExceptions.unwrap(e);
// index missing exception on a partition should never bubble, mark all items as failed instead
if (e instanceof IndexNotFoundException && PartitionName.isPartition(request.index())) {
indicesDeleted.add(request.index());
markItemsAsFailedAndReleaseRetryLock(request, retryCoordinator);
return;
}
final BulkRetryCoordinator coordinator;
if (retryCoordinator.isPresent()) {
coordinator = retryCoordinator.get();
} else {
try {
coordinator = bulkRetryCoordinatorPool.coordinator(shardId);
} catch (Throwable coordinatorException) {
setFailure(coordinatorException);
return;
}
}
if (e instanceof EsRejectedExecutionException) {
trace("rejected execution: [%s] - retrying", e.getMessage());
coordinator.retry(request, requestExecutor, new ActionListener<ShardResponse>() {
@Override
public void onResponse(ShardResponse response) {
processResponse(response);
}
@Override
public void onFailure(Throwable e) {
processFailure(e, shardId, request, Optional.of(coordinator));
}
});
} else {
if (retryCoordinator.isPresent()) {
// release failed retry
coordinator.releaseWriteLock();
}
for (IntCursor intCursor : request.itemIndices()) {
synchronized (responsesLock) {
responses.set(intCursor.value, false);
}
}
setFailure(e);
}
}
use of org.elasticsearch.index.IndexNotFoundException in project fess-crawler by codelibs.
the class AbstractCrawlerService method createMapping.
protected void createMapping(final String mappingName) {
boolean exists = false;
try {
final IndicesExistsResponse response = esClient.get(c -> c.admin().indices().prepareExists(index).execute());
exists = response.isExists();
} catch (final IndexNotFoundException e) {
// ignore
}
if (!exists) {
final CreateIndexResponse indexResponse = esClient.get(c -> {
final String source = "{\"settings\":{\"index\":{\"number_of_shards\":" + numberOfShards + ",\"number_of_replicas\":" + numberOfReplicas + "}}}";
return c.admin().indices().prepareCreate(index).setSource(source, XContentType.JSON).execute();
});
if (indexResponse.isAcknowledged()) {
logger.info("Created " + index + " index.");
} else if (logger.isDebugEnabled()) {
logger.debug("Failed to create " + index + " index.");
}
}
final GetMappingsResponse getMappingsResponse = esClient.get(c -> c.admin().indices().prepareGetMappings(index).setTypes(type).execute());
final ImmutableOpenMap<String, MappingMetaData> indexMappings = getMappingsResponse.mappings().get(index);
if (indexMappings == null || !indexMappings.containsKey(type)) {
final PutMappingResponse putMappingResponse = esClient.get(c -> {
final String source = FileUtil.readText("mapping/" + mappingName + ".json");
return c.admin().indices().preparePutMapping(index).setType(type).setSource(source, XContentType.JSON).execute();
});
if (putMappingResponse.isAcknowledged()) {
logger.info("Created " + index + "/" + type + " mapping.");
} else {
logger.warn("Failed to create " + index + "/" + type + " mapping.");
}
} else if (logger.isDebugEnabled()) {
logger.debug(index + "/" + type + " mapping exists.");
}
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class Get method build.
@Override
public ExecutionPlan build(PlannerContext plannerContext, Set<PlanHint> hints, ProjectionBuilder projectionBuilder, int limitHint, int offsetHint, @Nullable OrderBy order, @Nullable Integer pageSizeHint, Row params, SubQueryResults subQueryResults) {
HashMap<String, Map<ShardId, List<PKAndVersion>>> idsByShardByNode = new HashMap<>();
DocTableInfo docTableInfo = tableRelation.tableInfo();
for (DocKeys.DocKey docKey : docKeys) {
String id = docKey.getId(plannerContext.transactionContext(), plannerContext.nodeContext(), params, subQueryResults);
if (id == null) {
continue;
}
List<String> partitionValues = docKey.getPartitionValues(plannerContext.transactionContext(), plannerContext.nodeContext(), params, subQueryResults);
String indexName = indexName(docTableInfo, partitionValues);
String routing = docKey.getRouting(plannerContext.transactionContext(), plannerContext.nodeContext(), params, subQueryResults);
ShardRouting shardRouting;
try {
shardRouting = plannerContext.resolveShard(indexName, id, routing);
} catch (IndexNotFoundException e) {
if (docTableInfo.isPartitioned()) {
continue;
}
throw e;
}
String currentNodeId = shardRouting.currentNodeId();
if (currentNodeId == null) {
// If relocating is fast enough this will work, otherwise it will result in a shard failure which
// will cause a statement retry
currentNodeId = shardRouting.relocatingNodeId();
if (currentNodeId == null) {
throw new ShardNotFoundException(shardRouting.shardId());
}
}
Map<ShardId, List<PKAndVersion>> idsByShard = idsByShardByNode.get(currentNodeId);
if (idsByShard == null) {
idsByShard = new HashMap<>();
idsByShardByNode.put(currentNodeId, idsByShard);
}
List<PKAndVersion> pkAndVersions = idsByShard.get(shardRouting.shardId());
if (pkAndVersions == null) {
pkAndVersions = new ArrayList<>();
idsByShard.put(shardRouting.shardId(), pkAndVersions);
}
long version = docKey.version(plannerContext.transactionContext(), plannerContext.nodeContext(), params, subQueryResults).orElse(Versions.MATCH_ANY);
long sequenceNumber = docKey.sequenceNo(plannerContext.transactionContext(), plannerContext.nodeContext(), params, subQueryResults).orElse(SequenceNumbers.UNASSIGNED_SEQ_NO);
long primaryTerm = docKey.primaryTerm(plannerContext.transactionContext(), plannerContext.nodeContext(), params, subQueryResults).orElse(SequenceNumbers.UNASSIGNED_PRIMARY_TERM);
pkAndVersions.add(new PKAndVersion(id, version, sequenceNumber, primaryTerm));
}
var docKeyColumns = new ArrayList<>(docTableInfo.primaryKey());
docKeyColumns.addAll(docTableInfo.partitionedBy());
docKeyColumns.add(docTableInfo.clusteredBy());
docKeyColumns.add(DocSysColumns.VERSION);
docKeyColumns.add(DocSysColumns.SEQ_NO);
docKeyColumns.add(DocSysColumns.PRIMARY_TERM);
var binder = new SubQueryAndParamBinder(params, subQueryResults);
List<Symbol> boundOutputs = Lists2.map(outputs, binder);
var boundQuery = binder.apply(query);
// Collect all columns which are used inside the query
// If the query contains only DocKeys, no filter is needed as all DocKeys are handled by the PKLookupOperation
AtomicBoolean requiresAdditionalFilteringOnNonDocKeyColumns = new AtomicBoolean(false);
var toCollectSet = new LinkedHashSet<>(boundOutputs);
Consumer<Reference> addRefIfMatch = ref -> {
toCollectSet.add(ref);
if (docKeyColumns.contains(ref.column()) == false) {
requiresAdditionalFilteringOnNonDocKeyColumns.set(true);
}
};
RefVisitor.visitRefs(boundQuery, addRefIfMatch);
var toCollect = boundOutputs;
ArrayList<Projection> projections = new ArrayList<>();
if (requiresAdditionalFilteringOnNonDocKeyColumns.get()) {
toCollect = List.copyOf(toCollectSet);
var filterProjection = ProjectionBuilder.filterProjection(toCollect, boundQuery);
filterProjection.requiredGranularity(RowGranularity.SHARD);
projections.add(filterProjection);
// reduce outputs which have been added for the filter projection
var evalProjection = new EvalProjection(InputColumn.mapToInputColumns(boundOutputs), RowGranularity.SHARD);
projections.add(evalProjection);
}
var collect = new Collect(new PKLookupPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), docTableInfo.partitionedBy(), toCollect, idsByShardByNode), TopN.NO_LIMIT, 0, toCollect.size(), docKeys.size(), null);
for (var projection : projections) {
collect.addProjection(projection);
}
return collect;
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class ShardCollectSource method createMultiShardScoreDocCollector.
private CompletableFuture<BatchIterator<Row>> createMultiShardScoreDocCollector(RoutedCollectPhase collectPhase, boolean supportMoveToStart, CollectTask collectTask, String localNodeId) {
Map<String, Map<String, IntIndexedContainer>> locations = collectPhase.routing().locations();
SharedShardContexts sharedShardContexts = collectTask.sharedShardContexts();
Map<String, IntIndexedContainer> indexShards = locations.get(localNodeId);
List<CompletableFuture<OrderedDocCollector>> orderedDocCollectors = new ArrayList<>();
Metadata metadata = clusterService.state().metadata();
for (Map.Entry<String, IntIndexedContainer> entry : indexShards.entrySet()) {
String indexName = entry.getKey();
Index index = metadata.index(indexName).getIndex();
for (IntCursor shard : entry.getValue()) {
ShardId shardId = new ShardId(index, shard.value);
try {
SharedShardContext context = sharedShardContexts.getOrCreateContext(shardId);
ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
orderedDocCollectors.add(shardCollectorProvider.getFutureOrderedCollector(collectPhase, context, collectTask, supportMoveToStart));
} catch (ShardNotFoundException | IllegalIndexShardStateException e) {
throw e;
} catch (IndexNotFoundException e) {
if (IndexParts.isPartitioned(indexName)) {
break;
}
throw e;
}
}
}
List<DataType<?>> columnTypes = Symbols.typeView(collectPhase.toCollect());
OrderBy orderBy = collectPhase.orderBy();
assert orderBy != null : "orderBy must not be null";
return CompletableFutures.allAsList(orderedDocCollectors).thenApply(collectors -> OrderedLuceneBatchIteratorFactory.newInstance(collectors, OrderingByPosition.rowOrdering(OrderByPositionVisitor.orderByPositions(orderBy.orderBySymbols(), collectPhase.toCollect()), orderBy.reverseFlags(), orderBy.nullsFirst()), new RowAccountingWithEstimators(columnTypes, collectTask.getRamAccounting()), executor, availableThreads, supportMoveToStart));
}
Aggregations