aFields = defaultFields; items.add(new Item(index, type, id).routing(routing).storedFields(aFields).parent(parent).version(version) .versionType(versionType) .fetchSourceContext(fetchSourceContext == FetchSourceContext.FETCH_SOURCE ? defaultFetchSource : fetchSourceContext));
concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, item).getName(); item.routing(clusterState.metaData().resolveIndexRouting(item.parent(), item.routing(), item.index())); if ((item.routing() == null) && (clusterState.getMetaData().routingRequired(concreteSingleIndex, item.type()))) { responses.set(i, newItemFailure(concreteSingleIndex, item.type(), item.id(), new RoutingMissingException(concreteSingleIndex, item.type(), item.id()))); continue; responses.set(i, newItemFailure(item.index(), item.type(), item.id(), e)); continue; .getShards(clusterState, concreteSingleIndex, item.id(), item.routing(), null) .shardId();
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); locations = new IntArrayList(size); items = new ArrayList<>(size); for (int i = 0; i < size; i++) { locations.add(in.readVInt()); items.add(MultiGetRequest.Item.readItem(in)); } preference = in.readOptionalString(); refresh = in.readBoolean(); realtime = in.readBoolean(); }
String[] newIndices = provider.provide(((MultiGetRequest.Item) request).indices(), request, true); if(checkIndices(request, newIndices, true, allowEmptyIndices) == false) { return false; ((MultiGetRequest.Item) request).index(newIndices.length!=1?null:newIndices[0]); } else if (request instanceof CreateIndexRequest) { String[] newIndices = provider.provide(((CreateIndexRequest) request).indices(), request, true);
aFields = defaultFields; items.add(new Item(index, type, id).routing(routing).storedFields(aFields).parent(parent).version(version).versionType(versionType) .fetchSourceContext(fetchSourceContext == FetchSourceContext.FETCH_SOURCE ? defaultFetchSource : fetchSourceContext));
aFields = defaultFields; items.add(new Item(index, type, id).routing(routing).fields(aFields).parent(parent).version(version).versionType(versionType) .fetchSourceContext(fetchSourceContext == null ? defaultFetchSource : fetchSourceContext));
aFields = defaultFields; items.add(new Item(index, type, id).routing(routing).storedFields(aFields).parent(parent).version(version).versionType(versionType) .fetchSourceContext(fetchSourceContext == FetchSourceContext.FETCH_SOURCE ? defaultFetchSource : fetchSourceContext));
aFields = defaultFields; items.add(new Item(index, type, id).routing(routing).storedFields(aFields).parent(parent).version(version).versionType(versionType) .fetchSourceContext(fetchSourceContext == FetchSourceContext.FETCH_SOURCE ? defaultFetchSource : fetchSourceContext));
try { concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, item); item.routing(clusterState.metaData().resolveIndexRouting(item.routing(), concreteSingleIndex)); if ((item.routing() == null) && (clusterState.getMetaData().routingRequired(concreteSingleIndex, item.type()))) { String message = "routing is required for [" + concreteSingleIndex + "]/[" + item.type() + "]/[" + item.id() + "]"; responses.set(i, newItemFailure(concreteSingleIndex, item.type(), item.id(), new IllegalArgumentException(message))); continue; responses.set(i, newItemFailure(item.index(), item.type(), item.id(), e)); continue; .getShards(clusterState, concreteSingleIndex, item.type(), item.id(), item.routing(), null).shardId(); MultiGetShardRequest shardRequest = shardRequests.get(shardId); if (shardRequest == null) {
for (GetRequest getRequest : existingDocsRequests) { multiGetRequest.add( new MultiGetRequest.Item(getRequest.index(), getRequest.type(), getRequest.id()) .routing(getRequest.routing()) );
concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, item).getName(); item.routing(clusterState.metaData().resolveIndexRouting(item.parent(), item.routing(), item.index())); if ((item.routing() == null) && (clusterState.getMetaData().routingRequired(concreteSingleIndex, item.type()))) { String message = "routing is required for [" + concreteSingleIndex + "]/[" + item.type() + "]/[" + item.id() + "]"; responses.set(i, newItemFailure(concreteSingleIndex, item.type(), item.id(), new IllegalArgumentException(message))); continue; responses.set(i, newItemFailure(item.index(), item.type(), item.id(), e)); continue; .getShards(clusterState, concreteSingleIndex, item.id(), item.routing(), null) .shardId();
concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, item).getName(); item.routing(clusterState.metaData().resolveIndexRouting(item.parent(), item.routing(), concreteSingleIndex)); if ((item.routing() == null) && (clusterState.getMetaData().routingRequired(concreteSingleIndex, item.type()))) { String message = "routing is required for [" + concreteSingleIndex + "]/[" + item.type() + "]/[" + item.id() + "]"; responses.set(i, newItemFailure(concreteSingleIndex, item.type(), item.id(), new IllegalArgumentException(message))); continue; responses.set(i, newItemFailure(item.index(), item.type(), item.id(), e)); continue; .getShards(clusterState, concreteSingleIndex, item.id(), item.routing(), null) .shardId().getIndex(), 0);
concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, item).getName(); item.routing(clusterState.metaData().resolveIndexRouting(item.parent(), item.routing(), item.index())); if ((item.routing() == null) && (clusterState.getMetaData().routingRequired(concreteSingleIndex, item.type()))) { responses.set(i, newItemFailure(concreteSingleIndex, item.type(), item.id(), new RoutingMissingException(concreteSingleIndex, item.type(), item.id()))); continue; responses.set(i, newItemFailure(item.index(), item.type(), item.id(), e)); continue; .getShards(clusterState, concreteSingleIndex, item.id(), item.routing(), null) .shardId();
@Override protected MultiGetShardResponse shardOperation(MultiGetShardRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.getShard(shardId.id()); if (request.refresh() && !request.realtime()) { indexShard.refresh("refresh_flag_mget"); } MultiGetShardResponse response = new MultiGetShardResponse(); for (int i = 0; i < request.locations.size(); i++) { MultiGetRequest.Item item = request.items.get(i); try { GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.storedFields(), request.realtime(), item.version(), item.versionType(), item.fetchSourceContext()); response.add(request.locations.get(i), new GetResponse(getResult)); } catch (RuntimeException e) { if (TransportActions.isShardNotAvailableException(e)) { throw e; } else { logger.debug(() -> new ParameterizedMessage("{} failed to execute multi_get for [{}]/[{}]", shardId, item.type(), item.id()), e); response.add(request.locations.get(i), new MultiGetResponse.Failure(request.index(), item.type(), item.id(), e)); } } } return response; } }
@Override protected MultiGetShardResponse shardOperation(MultiGetShardRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.getShard(shardId.id()); if (request.refresh() && !request.realtime()) { indexShard.refresh("refresh_flag_mget"); } MultiGetShardResponse response = new MultiGetShardResponse(); for (int i = 0; i < request.locations.size(); i++) { MultiGetRequest.Item item = request.items.get(i); try { GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.storedFields(), request.realtime(), item.version(), item.versionType(), item.fetchSourceContext()); response.add(request.locations.get(i), new GetResponse(getResult)); } catch (Exception e) { if (TransportActions.isShardNotAvailableException(e)) { throw (ElasticsearchException) e; } else { logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute multi_get for [{}]/[{}]", shardId, item.type(), item.id()), e); response.add(request.locations.get(i), new MultiGetResponse.Failure(request.index(), item.type(), item.id(), e)); } } } return response; } }
@Override protected MultiGetShardResponse shardOperation(MultiGetShardRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.shardSafe(shardId.id()); if (request.refresh() && !request.realtime()) { indexShard.refresh("refresh_flag_mget"); } MultiGetShardResponse response = new MultiGetShardResponse(); for (int i = 0; i < request.locations.size(); i++) { MultiGetRequest.Item item = request.items.get(i); try { GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.fields(), request.realtime(), item.version(), item.versionType(), item.fetchSourceContext(), request.ignoreErrorsOnGeneratedFields()); response.add(request.locations.get(i), new GetResponse(getResult)); } catch (Throwable t) { if (TransportActions.isShardNotAvailableException(t)) { throw (ElasticsearchException) t; } else { logger.debug("{} failed to execute multi_get for [{}]/[{}]", t, shardId, item.type(), item.id()); response.add(request.locations.get(i), new MultiGetResponse.Failure(request.index(), item.type(), item.id(), t)); } } } return response; } }
@Override @SuppressWarnings("unchecked") public <P extends ParaObject> List<P> findByIds(String appid, List<String> ids) { List<P> list = new LinkedList<P>(); if (ids == null || ids.isEmpty()) { return list; } try { MultiGetRequestBuilder mgr = client().prepareMultiGet(); for (String id : ids) { MultiGetRequest.Item i = new MultiGetRequest.Item(getIndexName(appid), null, id); mgr.add(i); } MultiGetResponse response = mgr.execute().actionGet(); for (MultiGetItemResponse multiGetItemResponse : response.getResponses()) { GetResponse res = multiGetItemResponse.getResponse(); if (res.isExists() && !res.isSourceEmpty()) { list.add((P) Utils.setAnnotatedFields(res.getSource())); } } } catch (Exception e) { logger.warn(null, e); } return list; }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); locations = new IntArrayList(size); items = new ArrayList<>(size); for (int i = 0; i < size; i++) { locations.add(in.readVInt()); items.add(MultiGetRequest.Item.readItem(in)); } preference = in.readOptionalString(); refresh = in.readBoolean(); byte realtime = in.readByte(); if (realtime == 0) { this.realtime = false; } else if (realtime == 1) { this.realtime = true; } ignoreErrorsOnGeneratedFields = in.readBoolean(); }
@Override protected MultiGetShardResponse shardOperation(MultiGetShardRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.getShard(shardId.id()); if (request.refresh() && !request.realtime()) { indexShard.refresh("refresh_flag_mget"); } MultiGetShardResponse response = new MultiGetShardResponse(); for (int i = 0; i < request.locations.size(); i++) { MultiGetRequest.Item item = request.items.get(i); try { GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.storedFields(), request.realtime(), item.version(), item.versionType(), item.fetchSourceContext()); response.add(request.locations.get(i), new GetResponse(getResult)); } catch (RuntimeException e) { if (TransportActions.isShardNotAvailableException(e)) { throw e; } else { logger.debug(() -> new ParameterizedMessage("{} failed to execute multi_get for [{}]/[{}]", shardId, item.type(), item.id()), e); response.add(request.locations.get(i), new MultiGetResponse.Failure(request.index(), item.type(), item.id(), e)); } } } return response; }