@Override public String toString() { StringBuilder message = new StringBuilder().append("ES get request"); message.append(String.format(" for key '%s'", request.id())); message.append(String.format(" on index '%s'", request.index())); message.append(String.format(" on type '%s'", request.type())); return message.toString(); }
try (Writer writer = new FileWriter(filepath)) { final GetResponse response = tc.get(new GetRequest(index).type(type).id(id).refresh(true).realtime(false)).actionGet();
/** * Sets the id of the document to fetch. */ public GetRequestBuilder setId(String id) { request.id(id); return this; }
public static Request sourceExists(GetRequest getRequest) { Request request = new Request(HttpMethod.HEAD.name(), endpoint(getRequest.index(), getRequest.type(), getRequest.id(), "_source")); Params parameters = new Params(request); parameters.withPreference(getRequest.preference()); parameters.withRouting(getRequest.routing()); parameters.withRefresh(getRequest.refresh()); parameters.withRealtime(getRequest.realtime()); // Version params are not currently supported by the source exists API so are not passed return request; }
private static Request getStyleRequest(String method, GetRequest getRequest) { Request request = new Request(method, endpoint(getRequest.index(), getRequest.type(), getRequest.id())); Params parameters = new Params(request); parameters.withPreference(getRequest.preference()); parameters.withRouting(getRequest.routing()); parameters.withRefresh(getRequest.refresh()); parameters.withRealtime(getRequest.realtime()); parameters.withStoredFields(getRequest.storedFields()); parameters.withVersion(getRequest.version()); parameters.withVersionType(getRequest.versionType()); parameters.withFetchSourceContext(getRequest.fetchSourceContext()); return request; }
try { if (!response.isExists()) { throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() + "] not found"); throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() + "] source disabled"); throw new IllegalStateException("Shape with name [" + getRequest.id() + "] found but missing " + path + " field");
@Override protected ShardIterator shards(ClusterState state, InternalRequest request) { return clusterService.operationRouting() .getShards(clusterService.state(), request.concreteIndex(), request.request().id(), request.request().routing(), request.request().preference()); }
/** * Sets the id of the document to fetch. */ public GetRequestBuilder setId(String id) { request.id(id); return this; }
/** * Sets the id of the document to fetch. */ public GetRequestBuilder setId(String id) { request.id(id); return this; }
@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); }
@Override protected void resolveRequest(ClusterState state, InternalRequest request) { IndexMetaData indexMeta = state.getMetaData().index(request.concreteIndex()); // update the routing (request#index here is possibly an alias) request.request().routing(state.metaData().resolveIndexRouting(request.request().parent(), request.request().routing(), request.request().index())); // Fail fast on the node that received the request. if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) { throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id()); } }
@Converter public static GetRequest toGetRequest(Object document, Exchange exchange) { if (document instanceof GetRequest) { return (GetRequest) document; } return new GetRequest(exchange.getIn().getHeader( ElasticsearchConstants.PARAM_INDEX_NAME, String.class)) .type(exchange.getIn().getHeader( ElasticsearchConstants.PARAM_INDEX_TYPE, String.class)).id((String) document); }
private static void checkDocumentEquality(Map<String, Object> expectedDataOfDocument, GetRequestBuilder getRequestBuilder, GetResponse dataOfDocumentResponse) { final Map<String, Object> dataOfDocument = new LinkedHashMap<>(dataOfDocumentResponse.getSource()); if (!DeepEquals.deepEquals(dataOfDocument, expectedDataOfDocument)) { try { throw FailureHandler.createFailure("Expected document for index: %s - type: %s - id: %s is %s, but %s was found.", getRequestBuilder.request().index(), getRequestBuilder.request().type(), getRequestBuilder.request().id(), OBJECT_MAPPER.writeValueAsString(expectedDataOfDocument), OBJECT_MAPPER.writeValueAsString(dataOfDocument)); } catch (IOException e) { throw new IllegalArgumentException(e); } } }
private static void checkDocumentEquality(Map<String, Object> expectedDataOfDocument, GetRequestBuilder getRequestBuilder, GetResponse dataOfDocumentResponse) { final Map<String, Object> dataOfDocument = new LinkedHashMap<>(dataOfDocumentResponse.getSource()); if (!DeepEquals.deepEquals(dataOfDocument, expectedDataOfDocument)) { try { throw FailureHandler.createFailure("Expected document for index: %s - type: %s - id: %s is %s, but %s was found.", getRequestBuilder.request().index(), getRequestBuilder.request().type(), getRequestBuilder.request().id(), OBJECT_MAPPER.writeValueAsString(expectedDataOfDocument), OBJECT_MAPPER.writeValueAsString(dataOfDocument)); } catch (IOException e) { throw new IllegalArgumentException(e); } } }
private static void checkExistanceOfDocument(GetRequestBuilder getRequestBuilder, GetResponse dataOfDocumentResponse) throws Error { if (!dataOfDocumentResponse.isExists()) { throw FailureHandler.createFailure( "Document with index: %s - type: %s - id: %s has not returned any document.", getRequestBuilder.request().index(), getRequestBuilder.request().type(), getRequestBuilder.request().id()); } }
private static void checkExistenceOfDocument(GetRequestBuilder getRequestBuilder, GetResponse dataOfDocumentResponse) { if (!dataOfDocumentResponse.isExists()) { throw FailureHandler.createFailure( "Document with index: %s - type: %s - id: %s has not returned any document.", getRequestBuilder.request().index(), getRequestBuilder.request().type(), getRequestBuilder.request().id()); } }
private static void checkExistanceOfDocument(GetRequestBuilder getRequestBuilder, GetResponse dataOfDocumentResponse) throws Error { if (!dataOfDocumentResponse.isExists()) { throw FailureHandler.createFailure( "Document with index: %s - type: %s - id: %s has not returned any document.", getRequestBuilder.request().index(), getRequestBuilder.request().type(), getRequestBuilder.request().id()); } }
@Override protected ShardIterator shards(ClusterState state, InternalRequest request) { return clusterService.operationRouting() .getShards(clusterService.state(), request.concreteIndex(), request.request().id(), request.request().routing(), request.request().preference()); }
@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); }
protected SearchRequest toSearchRequest(final GetRequest request) { final SearchRequest searchRequest = new SearchRequest(); searchRequest.listenerThreaded(false); searchRequest.routing(request.routing()); searchRequest.copyContextFrom(request); searchRequest.preference(request.preference()); searchRequest.indices(request.indices()); searchRequest.types(request.type()); searchRequest.source(SearchSourceBuilder.searchSource().query(new IdsQueryBuilder(request.type()).addIds(request.id()))); return searchRequest; }