@Override public void onResponse(FirstResult result) { onFirstPhaseResult(shardIndex, shard, result, shardIt); }
@Override public void onFailure(Throwable t) { onFirstPhaseResult(shardIndex, shard, node.id(), shardIt, t); } });
void performFirstPhase(final int shardIndex, final ShardIterator shardIt, final ShardRouting shard) { if (shard == null) { // no more active shards... (we should not really get here, but just for safety) onFirstPhaseResult(shardIndex, null, null, shardIt, new NoShardAvailableActionException(shardIt.shardId())); } else { final DiscoveryNode node = nodes.get(shard.currentNodeId()); if (node == null) { onFirstPhaseResult(shardIndex, shard, null, shardIt, new NoShardAvailableActionException(shardIt.shardId())); } else { String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterState, shard.index(), request.indices()); sendExecuteFirstPhase(node, internalSearchRequest(shard, shardsIts.size(), request, filteringAliases, startTime()), new ActionListener<FirstResult>() { @Override public void onResponse(FirstResult result) { onFirstPhaseResult(shardIndex, shard, result, shardIt); } @Override public void onFailure(Throwable t) { onFirstPhaseResult(shardIndex, shard, node.id(), shardIt, t); } }); } } }
public void start() { if (expectedSuccessfulOps == 0) { // no search shards to search on, bail with empty response (it happens with search across _all with no indices around and consistent with broadcast operations) listener.onResponse(new SearchResponse(InternalSearchResponse.empty(), null, 0, 0, buildTookInMillis(), ShardSearchFailure.EMPTY_ARRAY)); return; } int shardIndex = -1; for (final ShardIterator shardIt : shardsIts) { shardIndex++; final ShardRouting shard = shardIt.nextOrNull(); if (shard != null) { performFirstPhase(shardIndex, shardIt, shard); } else { // really, no shards active in this group onFirstPhaseResult(shardIndex, null, null, shardIt, new NoShardAvailableActionException(shardIt.shardId())); } } }
performFirstPhase(shardIndex, shardIt, nextShard); } catch (Throwable t1) { onFirstPhaseResult(shardIndex, shard, shard.currentNodeId(), shardIt, t1);