當前位置: 首頁>>代碼示例>>Java>>正文


Java IndexNotFoundException類代碼示例

本文整理匯總了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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:RoutingTable.java

示例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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:IndexNameExpressionResolver.java

示例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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:TransportClusterHealthAction.java

示例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());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:DynamicMappingDisabledTests.java

示例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");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:RoutingTableTests.java

示例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");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:RoutingTableTests.java

示例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?

}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:TransportReplicationActionTests.java

示例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);
        }
    }));
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:19,代碼來源:IndexingProxyService.java

示例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;
}
 
開發者ID:Erudika,項目名稱:para-search-elasticsearch,代碼行數:29,代碼來源:ElasticSearch.java

示例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());
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:23,代碼來源:InternalCountOperation.java

示例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
    );
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:21,代碼來源:DocTableInfo.java

示例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;
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:19,代碼來源:DocTableInfo.java

示例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());
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:27,代碼來源:OperationRouting.java

示例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);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:25,代碼來源:TransportClusterHealthAction.java

示例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);
		}
	}
}
 
開發者ID:Netflix,項目名稱:conductor,代碼行數:17,代碼來源:ElasticSearchDAO.java


注:本文中的org.elasticsearch.index.IndexNotFoundException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。