本文整理汇总了Java中org.elasticsearch.index.IndexNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java IndexNotFoundException类的具体用法?Java IndexNotFoundException怎么用?Java IndexNotFoundException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndexNotFoundException类属于org.elasticsearch.index包,在下文中一共展示了IndexNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: activePrimaryShardsGrouped
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
/**
* All the *active* primary shards for the provided indices grouped (each group is a single element, consisting
* of the primary shard). This is handy for components that expect to get group iterators, but still want in some
* cases to iterate over all primary shards (and not just one shard in replication group).
*
* @param indices The indices to return all the shards (replicas)
* @return All the primary shards grouped into a single shard element group each
* @throws IndexNotFoundException If an index passed does not exists
* @see IndexRoutingTable#groupByAllIt()
*/
public GroupShardsIterator activePrimaryShardsGrouped(String[] indices, boolean includeEmpty) {
// use list here since we need to maintain identity across shards
ArrayList<ShardIterator> set = new ArrayList<>();
for (String index : indices) {
IndexRoutingTable indexRoutingTable = index(index);
if (indexRoutingTable == null) {
throw new IndexNotFoundException(index);
}
for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
ShardRouting primary = indexShardRoutingTable.primaryShard();
if (primary.active()) {
set.add(primary.shardsIt());
} else if (includeEmpty) { // we need this for counting properly, just make it an empty one
set.add(new PlainShardIterator(primary.shardId(), Collections.<ShardRouting>emptyList()));
}
}
}
return new GroupShardsIterator(set);
}
示例2: resolve
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
@Override
public List<String> resolve(Context context, List<String> expressions) {
IndicesOptions options = context.getOptions();
MetaData metaData = context.getState().metaData();
if (options.expandWildcardsClosed() == false && options.expandWildcardsOpen() == false) {
return expressions;
}
if (isEmptyOrTrivialWildcard(expressions)) {
return resolveEmptyOrTrivialWildcard(options, metaData, true);
}
Set<String> result = innerResolve(context, expressions, options, metaData);
if (result == null) {
return expressions;
}
if (result.isEmpty() && !options.allowNoIndices()) {
IndexNotFoundException infe = new IndexNotFoundException((String)null);
infe.setResources("index_or_alias", expressions.toArray(new String[0]));
throw infe;
}
return new ArrayList<>(result);
}
示例3: clusterHealth
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
private ClusterHealthResponse clusterHealth(ClusterHealthRequest request, ClusterState clusterState, int numberOfPendingTasks, int numberOfInFlightFetch,
TimeValue pendingTaskTimeInQueue) {
if (logger.isTraceEnabled()) {
logger.trace("Calculating health based on state version [{}]", clusterState.version());
}
String[] concreteIndices;
try {
concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
} catch (IndexNotFoundException e) {
// one of the specified indices is not there - treat it as RED.
ClusterHealthResponse response = new ClusterHealthResponse(clusterState.getClusterName().value(), Strings.EMPTY_ARRAY, clusterState,
numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState),
pendingTaskTimeInQueue);
response.setStatus(ClusterHealthStatus.RED);
return response;
}
return new ClusterHealthResponse(clusterState.getClusterName().value(), concreteIndices, clusterState, numberOfPendingTasks,
numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), pendingTaskTimeInQueue);
}
示例4: testDynamicDisabled
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
public void testDynamicDisabled() {
IndexRequest request = new IndexRequest("index", "type", "1");
request.source(Requests.INDEX_CONTENT_TYPE, "foo", 3);
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(request);
final AtomicBoolean onFailureCalled = new AtomicBoolean();
transportBulkAction.execute(bulkRequest, new ActionListener<BulkResponse>() {
@Override
public void onResponse(BulkResponse bulkResponse) {
fail("onResponse shouldn't be called");
}
@Override
public void onFailure(Exception e) {
onFailureCalled.set(true);
assertThat(e, instanceOf(IndexNotFoundException.class));
assertEquals("no such index and [index.mapper.dynamic] is [false]", e.getMessage());
}
});
assertTrue(onFailureCalled.get());
}
示例5: testAllAssignedShardsGrouped
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
public void testAllAssignedShardsGrouped() {
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
initPrimaries();
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(this.totalNumberOfShards));
try {
clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, false);
} catch (IndexNotFoundException e) {
fail("Calling with non-existing index should be ignored at the moment");
}
}
示例6: testAllShardsForMultipleIndices
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
public void testAllShardsForMultipleIndices() {
assertThat(this.emptyRoutingTable.allShards(new String[0]).size(), is(0));
assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
initPrimaries();
assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
startInitializingShards(TEST_INDEX_1);
assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
startInitializingShards(TEST_INDEX_2);
assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1, TEST_INDEX_2}).size(), is(this.totalNumberOfShards));
try {
clusterState.routingTable().allShards(new String[]{TEST_INDEX_1, "not_exists"});
} catch (IndexNotFoundException e) {
fail("Calling with non-existing index should be ignored at the moment");
}
}
示例7: testUnknownIndexOrShardOnReroute
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
public void testUnknownIndexOrShardOnReroute() throws InterruptedException {
final String index = "test";
// no replicas in oder to skip the replication part
setState(clusterService, state(index, true,
randomBoolean() ? ShardRoutingState.INITIALIZING : ShardRoutingState.UNASSIGNED));
logger.debug("--> using initial state:\n{}", clusterService.state());
Request request = new Request(new ShardId("unknown_index", "_na_", 0)).timeout("1ms");
PlainActionFuture<TestResponse> listener = new PlainActionFuture<>();
ReplicationTask task = maybeTask();
TestAction.ReroutePhase reroutePhase = action.new ReroutePhase(task, request, listener);
reroutePhase.run();
assertListenerThrows("must throw index not found exception", listener, IndexNotFoundException.class);
assertPhase(task, "failed");
assertTrue(request.isRetrySet.get());
request = new Request(new ShardId(index, "_na_", 10)).timeout("1ms");
listener = new PlainActionFuture<>();
reroutePhase = action.new ReroutePhase(null, request, listener);
reroutePhase.run();
assertListenerThrows("must throw shard not found exception", listener, ShardNotFoundException.class);
assertFalse(request.isRetrySet.get()); //TODO I'd have expected this to be true but we fail too early?
}
示例8: checkIfIndexExists
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
private void checkIfIndexExists(final ActionListener<ActionResponse> listener) {
client.admin().indices().prepareExists(IndexingProxyPlugin.INDEX_NAME).execute(wrap(response -> {
if (response.isExists()) {
if (logger.isDebugEnabled()) {
logger.debug(IndexingProxyPlugin.INDEX_NAME + " exists.");
}
listener.onResponse(response);
} else {
createIndex(listener);
}
}, e -> {
if (e instanceof IndexNotFoundException) {
createIndex(listener);
} else {
listener.onFailure(e);
}
}));
}
示例9: getSource
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
/**
* Returns the source (a map of fields and values) for and object.
* The source is extracted from the index directly not the data store.
* @param appid name of the {@link com.erudika.para.core.App}
* @param key the object id
* @return a map representation of the object
*/
protected Map<String, Object> getSource(String appid, String key) {
Map<String, Object> map = new HashMap<String, Object>();
if (StringUtils.isBlank(key) || StringUtils.isBlank(appid)) {
return map;
}
try {
GetRequestBuilder grb = client().prepareGet().setIndex(getIndexName(appid)).setId(key);
GetResponse gres = grb.execute().actionGet();
if (gres.isExists()) {
map = gres.getSource();
}
} catch (IndexNotFoundException ex) {
logger.warn("Index not created yet. Call '_setup' first.");
} catch (Exception e) {
Throwable cause = e.getCause();
String msg = cause != null ? cause.getMessage() : e.getMessage();
logger.warn("Could not get any data from index '{}': {}", appid, msg);
}
return map;
}
示例10: count
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
@Override
public long count(String index, int shardId, WhereClause whereClause) throws IOException, InterruptedException {
IndexService indexService;
try {
indexService = indicesService.indexServiceSafe(index);
} catch (IndexNotFoundException e) {
if (PartitionName.isPartition(index)) {
return 0L;
}
throw e;
}
IndexShard indexShard = indexService.shardSafe(shardId);
try (Engine.Searcher searcher = indexShard.acquireSearcher("count-operation")) {
LuceneQueryBuilder.Context queryCtx = queryBuilder.convert(
whereClause, indexService.mapperService(), indexService.fieldData(), indexService.cache());
if (Thread.interrupted()) {
throw new InterruptedException();
}
return searcher.searcher().count(queryCtx.query());
}
}
示例11: getShardIterators
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
private GroupShardsIterator getShardIterators(WhereClause whereClause,
@Nullable String preference,
ClusterState clusterState) throws IndexNotFoundException {
String[] routingIndices = concreteIndices;
if (whereClause.partitions().size() > 0) {
routingIndices = whereClause.partitions().toArray(new String[whereClause.partitions().size()]);
}
Map<String, Set<String>> routingMap = null;
if (whereClause.clusteredBy().isPresent()) {
routingMap = indexNameExpressionResolver.resolveSearchRouting(
clusterState, whereClause.routingValues(), routingIndices);
}
return clusterService.operationRouting().searchShards(
clusterState,
routingIndices,
routingMap,
preference
);
}
示例12: getRouting
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
@Nullable
private Routing getRouting(ClusterState state, WhereClause whereClause, String preference, final List<ShardId> missingShards) {
final Map<String, Map<String, List<Integer>>> locations = new TreeMap<>();
GroupShardsIterator shardIterators;
try {
shardIterators = getShardIterators(whereClause, preference, state);
} catch (IndexNotFoundException e) {
return new Routing(locations);
}
fillLocationsFromShardIterators(locations, shardIterators, missingShards);
if (missingShards.isEmpty()) {
return new Routing(locations);
} else {
return null;
}
}
示例13: generateShardId
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
@SuppressForbidden(reason = "Math#abs is trappy")
private int generateShardId(ClusterState clusterState, String index, String type, String id, @Nullable String routing) {
IndexMetaData indexMetaData = clusterState.metaData().index(index);
if (indexMetaData == null) {
throw new IndexNotFoundException(index);
}
final Version createdVersion = indexMetaData.getCreationVersion();
final HashFunction hashFunction = indexMetaData.getRoutingHashFunction();
final boolean useType = indexMetaData.getRoutingUseType();
final int hash;
if (routing == null) {
if (!useType) {
hash = hash(hashFunction, id);
} else {
hash = hash(hashFunction, type, id);
}
} else {
hash = hash(hashFunction, routing);
}
if (createdVersion.onOrAfter(Version.V_2_0_0_beta1)) {
return MathUtils.mod(hash, indexMetaData.getNumberOfShards());
} else {
return Math.abs(hash % indexMetaData.getNumberOfShards());
}
}
示例14: clusterHealth
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的package包/类
private ClusterHealthResponse clusterHealth(ClusterHealthRequest request, ClusterState clusterState, int numberOfPendingTasks, int numberOfInFlightFetch,
TimeValue pendingTaskTimeInQueue) {
if (logger.isTraceEnabled()) {
logger.trace("Calculating health based on state version [{}]", clusterState.version());
}
if (request.getHeader(LoginUserContext.TENANT_FILTER) != null) {
clusterState = AuthService.filterState(clusterState, clusterState.metaData(), (Long) request.getHeader(LoginUserContext.TENANT_FILTER));
}
String[] concreteIndices;
try {
concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request);
} catch (IndexNotFoundException e) {
// one of the specified indices is not there - treat it as RED.
ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState,
numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState),
pendingTaskTimeInQueue);
response.setStatus(ClusterHealthStatus.RED);
return response;
}
return new ClusterHealthResponse(clusterName.value(), concreteIndices, clusterState, numberOfPendingTasks,
numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), pendingTaskTimeInQueue);
}
示例15: updateIndexName
import org.elasticsearch.index.IndexNotFoundException; //导入依赖的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 (ResourceAlreadyExistsException ilee) {
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}