/** * Sets the preference to execute the search. Defaults to randomize across shards. Can be set to * {@code _local} to prefer local shards, {@code _primary} to execute only on primary shards, or * a custom value, which guarantees that the same order will be used across different requests. */ public GetRequestBuilder setPreference(String preference) { request.preference(preference); 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; }
getRequest.preference("_local"); client.get(getRequest, new ActionListener<GetResponse>(){
private void fetch(TermsLookup termsLookup, Client client, ActionListener<List<Object>> actionListener) { GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.type(), termsLookup.id()) .preference("_local").routing(termsLookup.routing()); client.get(getRequest, new ActionListener<GetResponse>() { @Override public void onResponse(GetResponse getResponse) { List<Object> terms = new ArrayList<>(); if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap()); terms.addAll(extractedValues); } actionListener.onResponse(terms); } @Override public void onFailure(Exception e) { actionListener.onFailure(e); } }); }
@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 preference to execute the search. Defaults to randomize across shards. Can be set to * <tt>_local</tt> to prefer local shards, <tt>_primary</tt> to execute only on primary shards, or * a custom value, which guarantees that the same order will be used across different requests. */ public GetRequestBuilder setPreference(String preference) { request.preference(preference); return this; }
/** * Sets the preference to execute the search. Defaults to randomize across shards. Can be set to * {@code _local} to prefer local shards, {@code _primary} to execute only on primary shards, or * a custom value, which guarantees that the same order will be used across different requests. */ public GetRequestBuilder setPreference(String preference) { request.preference(preference); return this; }
/** * Sets the preference to execute the search. Defaults to randomize across shards. Can be set to * {@code _local} to prefer local shards, {@code _primary} to execute only on primary shards, or * a custom value, which guarantees that the same order will be used across different requests. */ public GetRequestBuilder setPreference(String preference) { request.preference(preference); return this; }
/** * Sets the preference to execute the search. Defaults to randomize across shards. Can be set to * <tt>_local</tt> to prefer local shards, <tt>_primary</tt> to execute only on primary shards, or * a custom value, which guarantees that the same order will be used across different requests. */ public GetRequestBuilder setPreference(String preference) { request.preference(preference); return this; }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id")); getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh())); getRequest.routing(request.param("routing")); getRequest.parent(request.param("parent")); getRequest.preference(request.param("preference")); getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime())); if (request.param("fields") != null) { throw new IllegalArgumentException("the parameter [fields] is no longer supported, " + "please use [stored_fields] to retrieve stored fields or [_source] to load the field from _source"); } final String fieldsParam = request.param("stored_fields"); if (fieldsParam != null) { final String[] fields = Strings.splitStringByCommaToArray(fieldsParam); if (fields != null) { getRequest.storedFields(fields); } } getRequest.version(RestActions.parseVersion(request)); getRequest.versionType(VersionType.fromString(request.param("version_type"), getRequest.versionType())); getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request)); return channel -> client.get(getRequest, new RestToXContentListener<GetResponse>(channel) { @Override protected RestStatus getStatus(final GetResponse response) { return response.isExists() ? OK : NOT_FOUND; } }); }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id")); getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh())); getRequest.routing(request.param("routing")); getRequest.parent(request.param("parent")); getRequest.preference(request.param("preference")); getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime())); getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request)); return channel -> { if (getRequest.fetchSourceContext() != null && !getRequest.fetchSourceContext().fetchSource()) { final ActionRequestValidationException validationError = new ActionRequestValidationException(); validationError.addValidationError("fetching source can not be disabled"); channel.sendResponse(new BytesRestResponse(channel, validationError)); } else { client.get(getRequest, new RestGetSourceResponseListener(channel, request)); } }; }
private List<Object> fetch(TermsLookup termsLookup, Client client) { List<Object> terms = new ArrayList<>(); GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.type(), termsLookup.id()) .preference("_local").routing(termsLookup.routing()); final GetResponse getResponse = client.get(getRequest).actionGet(); if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap()); terms.addAll(extractedValues); } return terms; }
@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 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 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 ShardIterator shards(ClusterState state, InternalRequest request) { return clusterService.operationRouting() .getShards(clusterService.state(), request.concreteIndex(), request.request().type(), request.request().id(), request.request().routing(), request.request().preference()); }
public void queryScriptIndex(GetIndexedScriptRequest request, final ActionListener<GetResponse> listener) { String scriptLang = validateScriptLanguage(request.scriptLang()); GetRequest getRequest = new GetRequest(request, SCRIPT_INDEX).type(scriptLang).id(request.id()) .version(request.version()).versionType(request.versionType()) .preference("_local"); //Set preference for no forking client.get(getRequest, listener); }
static Request sourceExists(GetRequest getRequest) { Request request = new Request(HttpHead.METHOD_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; }
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; }