/** * Pre process the write request before it is sent to the server, eg. by setting the * {@link WriteRequest#setRefreshPolicy(String) refresh policy} if applicable. * * @param request must not be {@literal null}. * @param <R> * @return the processed {@link WriteRequest}. */ protected <R extends WriteRequest<R>> R prepareWriteRequest(R request) { if (refreshPolicy == null) { return request; } return request.setRefreshPolicy(refreshPolicy); }
/** * Set up the read {@link IndicesOptions}. Default is set to {@link IndicesOptions#strictExpandOpenAndForbidClosed()}. * * @return {@literal null} to use the server defaults. */ @Nullable protected IndicesOptions indicesOptions() { return IndicesOptions.strictExpandOpenAndForbidClosed(); }
Params withRefreshPolicy(RefreshPolicy refreshPolicy) { if (refreshPolicy != RefreshPolicy.NONE) { return putParam("refresh", refreshPolicy.getValue()); } return this; }
Params withIndicesOptions(IndicesOptions indicesOptions) { withIgnoreUnavailable(indicesOptions.ignoreUnavailable()); putParam("allow_no_indices", Boolean.toString(indicesOptions.allowNoIndices())); String expandWildcards; if (!indicesOptions.expandWildcardsOpen() && !indicesOptions.expandWildcardsClosed()) { expandWildcards = "none"; } else { StringJoiner joiner = new StringJoiner(","); if (indicesOptions.expandWildcardsOpen()) { joiner.add("open"); } if (indicesOptions.expandWildcardsClosed()) { joiner.add("closed"); } expandWildcards = joiner.toString(); } putParam("expand_wildcards", expandWildcards); return this; }
@Override public String[] provide(String[] original, Object request, boolean supportsReplace) { if(supportsReplace) { if(retainMode && original != null && original.length > 0) { //TODO datemath? List<String> originalAsList = Arrays.asList(original); if(originalAsList.contains("*") || originalAsList.contains("_all")) { return replacements; } original = resolver.concreteIndexNames(clusterService.state(), IndicesOptions.lenientExpandOpen(), original); final String[] retained = WildcardMatcher.getMatchAny(original, replacements).toArray(new String[0]); return retained; } return replacements; } else { return NOOP; } } }, false);
protected void updateRequestWithIndexAndRoutingOptions(Select select, SearchRequestBuilder request) { for (Hint hint : select.getHints()) { if (hint.getType() == HintType.IGNORE_UNAVAILABLE) { //saving the defaults from TransportClient search request.setIndicesOptions(IndicesOptions.fromOptions(true, false, true, false, IndicesOptions.strictExpandOpenAndForbidClosed())); } if (hint.getType() == HintType.ROUTINGS) { Object[] routings = hint.getParams(); String[] routingsAsStringArray = new String[routings.length]; for (int i = 0; i < routings.length; i++) { routingsAsStringArray[i] = routings[i].toString(); } request.setRouting(routingsAsStringArray); } } }
@Override public final <Request extends ActionRequest, Response extends ActionResponse> void apply(Task task, String action, Request request, ActionListener<Response> listener, ActionFilterChain<Request, Response> chain) { if (apply(action, request, listener)) { chain.proceed(task, action, request, listener); } }
/** * Parse the refresh policy from a string, only modifying it if the string is non null. Convenient to use with request parsing. */ @SuppressWarnings("unchecked") default B setRefreshPolicy(String refreshPolicy) { request().setRefreshPolicy(refreshPolicy); return (B) this; } }
/** * Parse the refresh policy from a string, only modifying it if the string is non null. Convenient to use with request parsing. */ @SuppressWarnings("unchecked") default R setRefreshPolicy(String refreshPolicy) { if (refreshPolicy != null) { setRefreshPolicy(RefreshPolicy.parse(refreshPolicy)); } return (R) this; }
_indices = new ArrayList<>(Arrays.asList(resolver.concreteIndexNames(state, IndicesOptions.fromOptions(false, true, true, false), requestedPatterns))); if (log.isDebugEnabled()) { log.debug("Resolved pattern {} to {}", requestedPatterns, _indices);
Params withWaitForActiveShards(ActiveShardCount activeShardCount, ActiveShardCount defaultActiveShardCount) { if (activeShardCount != null && activeShardCount != defaultActiveShardCount) { return putParam("wait_for_active_shards", activeShardCount.toString().toLowerCase(Locale.ROOT)); } return this; }
@Override public void addListener(final ActionListener<T> listener) { super.addListener(new ThreadedActionListener<>(logger, threadPool, ThreadPool.Names.LISTENER, listener, false)); } }
/** * If a failure is already present, should this failure override it or not for read operations. */ public static boolean isReadOverrideException(Exception e) { return !isShardNotAvailableException(e); }
/** * This method returns a listenable future. The listeners will be called on completion of the future. * The listeners will be executed by the same thread that completes the future. * * @param <T> the result of the future * @return a listenable future */ public static <T> PlainListenableActionFuture<T> newListenableFuture() { return new PlainListenableActionFuture<>(); }
/** * The REST status that should be used for the response */ public RestStatus getStatus() { if (failedShards > 0) { return shardFailures[0].status(); } else { return RestStatus.OK; } }
/** * Customization hook to modify a generated {@link DeleteByQueryRequest} prior to its execution. Eg. by setting the * {@link WriteRequest#setRefreshPolicy(String) refresh policy} if applicable. * * @param request the generated {@link DeleteByQueryRequest}. * @return never {@literal null}. */ protected DeleteByQueryRequest prepareDeleteByRequest(DeleteByQueryRequest request) { if (refreshPolicy != null && !RefreshPolicy.NONE.equals(refreshPolicy)) { request = request.setRefresh(true); } if (indicesOptions != null) { request = request.setIndicesOptions(indicesOptions); } return request; }
final String[] allIndices = resolver.concreteIndexNames(cs.state(), IndicesOptions.lenientExpandOpen(), "*"); final Set<String> wanted = new HashSet<>(Arrays.asList(allIndices)); WildcardMatcher.wildcardRetainInSet(wanted, permitted);
/** * Should this request trigger a refresh ({@linkplain RefreshPolicy#IMMEDIATE}), wait for a refresh ( * {@linkplain RefreshPolicy#WAIT_UNTIL}), or proceed ignore refreshes entirely ({@linkplain RefreshPolicy#NONE}, the default). */ @SuppressWarnings("unchecked") default B setRefreshPolicy(RefreshPolicy refreshPolicy) { request().setRefreshPolicy(refreshPolicy); return (B) this; }
private String[] getResolvedIndexPattern(User user, IndexNameExpressionResolver resolver, ClusterService cs) { String unresolved = getUnresolvedIndexPattern(user); String[] resolved = null; if(WildcardMatcher.containsWildcard(unresolved)) { final String[] aliasesForPermittedPattern = cs.state().getMetaData().getAliasAndIndexLookup() .entrySet().stream() .filter(e->e.getValue().isAlias()) .filter(e->WildcardMatcher.match(unresolved, e.getKey())) .map(e->e.getKey()).toArray(String[]::new); if(aliasesForPermittedPattern != null && aliasesForPermittedPattern.length > 0) { resolved = resolver.concreteIndexNames(cs.state(), IndicesOptions.lenientExpandOpen(), aliasesForPermittedPattern); } } if(resolved == null && !unresolved.isEmpty()) { resolved = resolver.concreteIndexNames(cs.state(), IndicesOptions.lenientExpandOpen(), unresolved); } if(resolved == null || resolved.length == 0) { return new String[]{unresolved}; } else { //append unresolved value for pattern matching String[] retval = Arrays.copyOf(resolved, resolved.length +1); retval[retval.length-1] = unresolved; return retval; } }