/** * Returns the filter associated with listed filtering aliases. * * <p>The list of filtering aliases should be obtained by calling MetaData.filteringAliases. * Returns <tt>null</tt> if no filtering is required. */ public Query aliasFilter(QueryShardContext context, String... aliasNames) { if (aliasNames == null || aliasNames.length == 0) { return null; } final ImmutableOpenMap<String, AliasMetaData> aliases = indexSettings.getIndexMetaData().getAliases(); if (aliasNames.length == 1) { AliasMetaData alias = aliases.get(aliasNames[0]); if (alias == null) { // This shouldn't happen unless alias disappeared after filteringAliases was called. throw new InvalidAliasNameException( index(), aliasNames[0], "Unknown alias name was passed to alias Filter"); } return parse(alias, context); } else { // we need to bench here a bit, to see maybe it makes sense to use OrFilter BooleanQuery.Builder combined = new BooleanQuery.Builder(); for (String aliasName : aliasNames) { AliasMetaData alias = aliases.get(aliasName); if (alias == null) { // This shouldn't happen unless alias disappeared after filteringAliases was called. throw new InvalidAliasNameException( indexSettings.getIndex(), aliasNames[0], "Unknown alias name was passed to alias Filter"); } Query parsedFilter = parse(alias, context); if (parsedFilter != null) { combined.add(parsedFilter, BooleanClause.Occur.SHOULD); } else { // The filter might be null only if filter was removed after filteringAliases was called return null; } } return combined.build(); } }
/** Returns the index this module is associated with */ public Index getIndex() { return indexSettings.getIndex(); }