private static Map<String, AliasOrIndex> suffixWildcard(Context context, MetaData metaData, String expression) { assert expression.length() >= 2 : "expression [" + expression + "] should have at least a length of 2"; String fromPrefix = expression.substring(0, expression.length() - 1); char[] toPrefixCharArr = fromPrefix.toCharArray(); toPrefixCharArr[toPrefixCharArr.length - 1]++; String toPrefix = new String(toPrefixCharArr); SortedMap<String,AliasOrIndex> subMap = metaData.getAliasAndIndexLookup().subMap(fromPrefix, toPrefix); if (context.getOptions().ignoreAliases()) { return subMap.entrySet().stream() .filter(entry -> entry.getValue().isAlias() == false) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } return subMap; }
private static Map<String, AliasOrIndex> otherWildcard(Context context, MetaData metaData, String expression) { final String pattern = expression; return metaData.getAliasAndIndexLookup() .entrySet() .stream() .filter(e -> context.getOptions().ignoreAliases() == false || e.getValue().isAlias() == false) .filter(e -> Regex.simpleMatch(pattern, e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
private static boolean aliasOrIndexExists(IndicesOptions options, MetaData metaData, String expression) { AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression); //treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api) return aliasOrIndex != null && (options.ignoreAliases() == false || aliasOrIndex.isAlias() == false); }
public static Map<String, AliasOrIndex> matches(Context context, MetaData metaData, String expression) { if (Regex.isMatchAllPattern(expression)) { // Can only happen if the expressions was initially: '-*' if (context.getOptions().ignoreAliases()) { return metaData.getAliasAndIndexLookup().entrySet().stream() .filter(e -> e.getValue().isAlias() == false) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } else { return metaData.getAliasAndIndexLookup(); } } else if (expression.indexOf("*") == expression.length() - 1) { return suffixWildcard(context, metaData, expression); } else { return otherWildcard(context, metaData, expression); } }
public static IndicesOptions fromOptions(boolean ignoreUnavailable, boolean allowNoIndices, boolean expandToOpenIndices, boolean expandToClosedIndices, IndicesOptions defaultOptions) { return fromOptions(ignoreUnavailable, allowNoIndices, expandToOpenIndices, expandToClosedIndices, defaultOptions.allowAliasesToMultipleIndices(), defaultOptions.forbidClosedIndices(), defaultOptions.ignoreAliases(), defaultOptions.ignoreThrottled()); }
if (aliasOrIndex == null) { throw indexNotFoundException(expression); } else if (aliasOrIndex.isAlias() && options.ignoreAliases()) { throw aliasesNotSupportedException(expression);
public static IndicesOptions fromParameters(Object wildcardsString, Object ignoreUnavailableString, Object allowNoIndicesString, Object ignoreThrottled, IndicesOptions defaultSettings) { if (wildcardsString == null && ignoreUnavailableString == null && allowNoIndicesString == null && ignoreThrottled == null) { return defaultSettings; } EnumSet<WildcardStates> wildcards = WildcardStates.parseParameter(wildcardsString, defaultSettings.expandWildcards); // note that allowAliasesToMultipleIndices is not exposed, always true (only for internal use) return fromOptions( nodeBooleanValue(ignoreUnavailableString, "ignore_unavailable", defaultSettings.ignoreUnavailable()), nodeBooleanValue(allowNoIndicesString, "allow_no_indices", defaultSettings.allowNoIndices()), wildcards.contains(WildcardStates.OPEN), wildcards.contains(WildcardStates.CLOSED), defaultSettings.allowAliasesToMultipleIndices(), defaultSettings.forbidClosedIndices(), defaultSettings.ignoreAliases(), nodeBooleanValue(ignoreThrottled, "ignore_throttled", defaultSettings.ignoreThrottled()) ); }
@Override public String toString() { return "IndicesOptions[" + "ignore_unavailable=" + ignoreUnavailable() + ", allow_no_indices=" + allowNoIndices() + ", expand_wildcards_open=" + expandWildcardsOpen() + ", expand_wildcards_closed=" + expandWildcardsClosed() + ", allow_aliases_to_multiple_indices=" + allowAliasesToMultipleIndices() + ", forbid_closed_indices=" + forbidClosedIndices() + ", ignore_aliases=" + ignoreAliases() + ", ignore_throttled=" + ignoreThrottled() + ']'; } }
/** * See: {@link #fromByte(byte)} */ private static byte toByte(IndicesOptions options) { byte id = 0; if (options.ignoreUnavailable()) { id |= 1; } if (options.allowNoIndices()) { id |= 2; } if (options.expandWildcardsOpen()) { id |= 4; } if (options.expandWildcardsClosed()) { id |= 8; } // true is default here, for bw comp we keep the first 16 values // in the array same as before + the default value for the new flag if (options.allowAliasesToMultipleIndices() == false) { id |= 16; } if (options.forbidClosedIndices()) { id |= 32; } if (options.ignoreAliases()) { id |= 64; } return id; }
continue; } else if (aliasOrIndex.isAlias() && context.getOptions().ignoreAliases()) { if (failNoIndices) { throw aliasesNotSupportedException(expression);
private static Map<String, AliasOrIndex> suffixWildcard(Context context, MetaData metaData, String expression) { assert expression.length() >= 2 : "expression [" + expression + "] should have at least a length of 2"; String fromPrefix = expression.substring(0, expression.length() - 1); char[] toPrefixCharArr = fromPrefix.toCharArray(); toPrefixCharArr[toPrefixCharArr.length - 1]++; String toPrefix = new String(toPrefixCharArr); SortedMap<String,AliasOrIndex> subMap = metaData.getAliasAndIndexLookup().subMap(fromPrefix, toPrefix); if (context.getOptions().ignoreAliases()) { return subMap.entrySet().stream() .filter(entry -> entry.getValue().isAlias() == false) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } return subMap; }
private static Map<String, AliasOrIndex> otherWildcard(Context context, MetaData metaData, String expression) { final String pattern = expression; return metaData.getAliasAndIndexLookup() .entrySet() .stream() .filter(e -> context.getOptions().ignoreAliases() == false || e.getValue().isAlias() == false) .filter(e -> Regex.simpleMatch(pattern, e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
private static boolean aliasOrIndexExists(IndicesOptions options, MetaData metaData, String expression) { AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression); //treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api) return aliasOrIndex != null && (options.ignoreAliases() == false || aliasOrIndex.isAlias() == false); }
private static Map<String, AliasOrIndex> otherWildcard(Context context, MetaData metaData, String expression) { final String pattern = expression; return metaData.getAliasAndIndexLookup() .entrySet() .stream() .filter(e -> context.getOptions().ignoreAliases() == false || e.getValue().isAlias() == false) .filter(e -> Regex.simpleMatch(pattern, e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
private static boolean aliasOrIndexExists(IndicesOptions options, MetaData metaData, String expression) { AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression); //treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api) return aliasOrIndex != null && (options.ignoreAliases() == false || aliasOrIndex.isAlias() == false); }
public static Map<String, AliasOrIndex> matches(Context context, MetaData metaData, String expression) { if (Regex.isMatchAllPattern(expression)) { // Can only happen if the expressions was initially: '-*' if (context.getOptions().ignoreAliases()) { return metaData.getAliasAndIndexLookup().entrySet().stream() .filter(e -> e.getValue().isAlias() == false) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } else { return metaData.getAliasAndIndexLookup(); } } else if (expression.indexOf("*") == expression.length() - 1) { return suffixWildcard(context, metaData, expression); } else { return otherWildcard(context, metaData, expression); } }
public static IndicesOptions fromOptions(boolean ignoreUnavailable, boolean allowNoIndices, boolean expandToOpenIndices, boolean expandToClosedIndices, IndicesOptions defaultOptions) { return fromOptions(ignoreUnavailable, allowNoIndices, expandToOpenIndices, expandToClosedIndices, defaultOptions.allowAliasesToMultipleIndices(), defaultOptions.forbidClosedIndices(), defaultOptions.ignoreAliases()); }
public static IndicesOptions fromOptions(boolean ignoreUnavailable, boolean allowNoIndices, boolean expandToOpenIndices, boolean expandToClosedIndices, IndicesOptions defaultOptions) { return fromOptions(ignoreUnavailable, allowNoIndices, expandToOpenIndices, expandToClosedIndices, defaultOptions.allowAliasesToMultipleIndices(), defaultOptions.forbidClosedIndices(), defaultOptions.ignoreAliases()); }
@Override public String toString() { return "IndicesOptions[" + "ignore_unavailable=" + ignoreUnavailable() + ", allow_no_indices=" + allowNoIndices() + ", expand_wildcards_open=" + expandWildcardsOpen() + ", expand_wildcards_closed=" + expandWildcardsClosed() + ", allow_aliases_to_multiple_indices=" + allowAliasesToMultipleIndices() + ", forbid_closed_indices=" + forbidClosedIndices() + ", ignore_aliases=" + ignoreAliases() + ']'; } }
@Override public String toString() { return "IndicesOptions[" + "ignore_unavailable=" + ignoreUnavailable() + ", allow_no_indices=" + allowNoIndices() + ", expand_wildcards_open=" + expandWildcardsOpen() + ", expand_wildcards_closed=" + expandWildcardsClosed() + ", allow_aliases_to_multiple_indices=" + allowAliasesToMultipleIndices() + ", forbid_closed_indices=" + forbidClosedIndices() + ", ignore_aliases=" + ignoreAliases() + ']'; } }