@Override public GetResponse newResponse() { return new GetResponse(); }
@Override protected GetResponse newResponse() { return new GetResponse(); }
@Override public void readFrom(StreamInput in) throws IOException { if (in.readBoolean()) { failure = MultiGetResponse.Failure.readFailure(in); } else { response = new GetResponse(); response.readFrom(in); } }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); locations = new IntArrayList(size); responses = new ArrayList<>(size); failures = new ArrayList<>(size); for (int i = 0; i < size; i++) { locations.add(in.readVInt()); if (in.readBoolean()) { GetResponse response = new GetResponse(); response.readFrom(in); responses.add(response); } else { responses.add(null); } if (in.readBoolean()) { failures.add(MultiGetResponse.Failure.readFailure(in)); } else { failures.add(null); } } }
/** * This method can be used to parse a {@link GetResponse} object when it has been printed out * as a xcontent using the {@link #toXContent(XContentBuilder, Params)} method. * <p> * For forward compatibility reason this method might not fail if it tries to parse a field it * doesn't know. But before returning the result it will check that enough information were * parsed to return a valid {@link GetResponse} instance and throws a {@link ParsingException} * otherwise. This is the case when we get a 404 back, which can be parsed as a normal * {@link GetResponse} with found set to false, or as an elasticsearch exception. The caller * of this method needs a way to figure out whether we got back a valid get response, which * can be done by catching ParsingException. * * @param parser {@link XContentParser} to parse the response from * @return a {@link GetResponse} * @throws IOException is an I/O exception occurs during the parsing */ public static GetResponse fromXContent(XContentParser parser) throws IOException { GetResult getResult = GetResult.fromXContent(parser); // At this stage we ensure that we parsed enough information to return // a valid GetResponse instance. If it's not the case, we throw an // exception so that callers know it and can handle it correctly. if (getResult.getIndex() == null && getResult.getType() == null && getResult.getId() == null) { throw new ParsingException(parser.getTokenLocation(), String.format(Locale.ROOT, "Missing required fields [%s,%s,%s]", GetResult._INDEX, GetResult._TYPE, GetResult._ID)); } return new GetResponse(getResult); }
@Override protected GetResponse newResponse() { return new GetResponse(); } }
@Override public GetResponse newResponse() { return new GetResponse(); }
@Override public GetResponse newResponse() { return new GetResponse(); }
@Override protected GetResponse newResponse() { return new GetResponse(); } }
@Override protected GetResponse shardOperation(GetRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.getShard(shardId.id()); if (request.refresh() && !request.realtime()) { indexShard.refresh("refresh_flag_get"); } GetResult result = indexShard.getService().get(request.type(), request.id(), request.storedFields(), request.realtime(), request.version(), request.versionType(), request.fetchSourceContext()); return new GetResponse(result); }
public static GetResponse readGetResponse(StreamInput in) throws IOException { GetResponse result = new GetResponse(); result.readFrom(in); return result; }
@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 public void readFrom(StreamInput in) throws IOException { if (in.readBoolean()) { failure = MultiGetResponse.Failure.readFailure(in); } else { response = new GetResponse(); response.readFrom(in); } }
@Override public void readFrom(StreamInput in) throws IOException { if (in.readBoolean()) { failure = MultiGetResponse.Failure.readFailure(in); } else { response = new GetResponse(); response.readFrom(in); } }
@Override public void readFrom(StreamInput in) throws IOException { if (in.readBoolean()) { failure = MultiGetResponse.Failure.readFailure(in); } else { response = new GetResponse(); response.readFrom(in); } }
@Override public void readFrom(StreamInput in) throws IOException { if (in.readBoolean()) { failure = MultiGetResponse.Failure.readFailure(in); } else { response = new GetResponse(); response.readFrom(in); } }
return new MultiGetItemResponse(null, new Failure(index, type, id, exception)); } else { GetResponse getResponse = new GetResponse(getResult); return new MultiGetItemResponse(getResponse, null);
@Override public GetResponse getDelegatedFromInstigator(final SearchResponse searchResponse) { if (searchResponse.getHits().getTotalHits() <= 0) { return new GetResponse(new GetResult(request.index(), request.type(), request.id(), request.version(), false, null, null)); } else if (searchResponse.getHits().getTotalHits() > 1) { throw new RuntimeException("cannot happen"); } else { final SearchHit sh = searchResponse.getHits().getHits()[0]; return new GetResponse(new GetResult(sh.index(), sh.type(), sh.id(), sh.version(), true, sh.getSourceRef(), null)); } } });
@Override protected GetResponse shardOperation(GetRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.getShard(0); if (request.refresh() && !request.realtime()) { indexShard.refresh("refresh_flag_get"); } GetResult result = indexShard.getService().get(request.type(), request.id(), request.storedFields(), request.realtime(), request.version(), request.versionType(), request.fetchSourceContext()); return new GetResponse(result); }
@Override protected GetResponse shardOperation(GetRequest request, ShardId shardId) { IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); IndexShard indexShard = indexService.getShard(shardId.id()); if (request.refresh() && !request.realtime()) { indexShard.refresh("refresh_flag_get"); } GetResult result = indexShard.getService().get(request.type(), request.id(), request.storedFields(), request.realtime(), request.version(), request.versionType(), request.fetchSourceContext()); return new GetResponse(result); }