Java Code Examples for org.elasticsearch.action.get.MultiGetRequest#realtime()
The following examples show how to use
org.elasticsearch.action.get.MultiGetRequest#realtime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestMultiGetAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { MultiGetRequest multiGetRequest = new MultiGetRequest(); multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh())); multiGetRequest.preference(request.param("preference")); multiGetRequest.realtime(request.paramAsBoolean("realtime", null)); multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false)); String[] sFields = null; String sField = request.param("fields"); if (sField != null) { sFields = Strings.splitStringByCommaToArray(sField); } FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request); multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"), RestActions.getRestContent(request), allowExplicitIndex); client.multiGet(multiGetRequest, new RestToXContentListener<MultiGetResponse>(channel)); }
Example 2
Source File: ConfigurationLoader.java From openshift-elasticsearch-plugin with Apache License 2.0 | 4 votes |
public void loadAsync(final String[] events, final ConfigCallback callback) { if(events == null || events.length == 0) { log.warn("No config events requested to load"); return; } final MultiGetRequest mget = new MultiGetRequest(); for (int i = 0; i < events.length; i++) { final String event = events[i]; mget.add(searchguardIndex, event, "0"); } mget.refresh(true); mget.realtime(true); try (StoredContext ctx = threadContext.stashContext()) { threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true"); client.multiGet(mget, new ActionListener<MultiGetResponse>() { @Override public void onResponse(MultiGetResponse response) { MultiGetItemResponse[] responses = response.getResponses(); for (int i = 0; i < responses.length; i++) { MultiGetItemResponse singleResponse = responses[i]; if(singleResponse != null && !singleResponse.isFailed()) { GetResponse singleGetResponse = singleResponse.getResponse(); if(singleGetResponse.isExists() && !singleGetResponse.isSourceEmpty()) { //success Long version = singleGetResponse.getVersion(); final Settings _settings = toSettings(singleGetResponse.getSourceAsBytesRef(), singleGetResponse.getType()); if(_settings != null) { callback.success(singleGetResponse.getType(), _settings, version); } else { log.error("Cannot parse settings for " + singleGetResponse.getType()); } } else { //does not exist or empty source callback.noData(singleGetResponse.getType()); } } else { //failure callback.singleFailure(singleResponse == null ? null : singleResponse.getFailure()); } } } @Override public void onFailure(Exception e) { callback.failure(e); } }); } }