Deprecate Indices query

This is in favour of just searching the _index field

Closes #12017
This commit is contained in:
Colin Goodheart-Smithe 2016-04-13 12:35:14 +01:00
parent 048d273408
commit b226cc7e7f
3 changed files with 22 additions and 4 deletions

View File

@ -24,6 +24,8 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
@ -34,9 +36,13 @@ import java.util.Collection;
import java.util.Objects;
/**
* A query that will execute the wrapped query only for the specified indices, and "match_all" when
* it does not match those indices (by default).
* A query that will execute the wrapped query only for the specified indices,
* and "match_all" when it does not match those indices (by default).
*
* @deprecated instead search on the `_index` field
*/
@Deprecated
// TODO remove this class in 6.0
public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilder> {
public static final String NAME = "indices";
@ -47,13 +53,20 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilde
private static final ParseField INDEX_FIELD = new ParseField("index");
private static final ParseField INDICES_FIELD = new ParseField("indices");
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(IndicesQueryBuilder.class));
private final QueryBuilder<?> innerQuery;
private final String[] indices;
private QueryBuilder<?> noMatchQuery = defaultNoMatchQuery();
/**
* @deprecated instead search on the `_index` field
*/
@Deprecated
public IndicesQueryBuilder(QueryBuilder<?> innerQuery, String... indices) {
DEPRECATION_LOGGER.deprecated("{} query is deprecated. Instead search on the '_index' field", NAME);
if (innerQuery == null) {
throw new IllegalArgumentException("inner query cannot be null");
}

View File

@ -587,10 +587,14 @@ public abstract class QueryBuilders {
}
/**
* A query that will execute the wrapped query only for the specified indices, and "match_all" when
* it does not match those indices.
* A query that will execute the wrapped query only for the specified
* indices, and "match_all" when it does not match those indices.
*
* @deprecated instead search on the `_index` field
*/
@Deprecated
public static IndicesQueryBuilder indicesQuery(QueryBuilder queryBuilder, String... indices) {
// TODO remove this method in 6.0
return new IndicesQueryBuilder(queryBuilder, indices);
}

View File

@ -588,6 +588,7 @@ public class SearchModule extends AbstractModule {
registerQuery(SpanOrQueryBuilder::new, SpanOrQueryBuilder::fromXContent, SpanOrQueryBuilder.QUERY_NAME_FIELD);
registerQuery(MoreLikeThisQueryBuilder::new, MoreLikeThisQueryBuilder::fromXContent, MoreLikeThisQueryBuilder.QUERY_NAME_FIELD);
registerQuery(WrapperQueryBuilder::new, WrapperQueryBuilder::fromXContent, WrapperQueryBuilder.QUERY_NAME_FIELD);
// TODO Remove IndicesQuery in 6.0
registerQuery(IndicesQueryBuilder::new, IndicesQueryBuilder::fromXContent, IndicesQueryBuilder.QUERY_NAME_FIELD);
registerQuery(CommonTermsQueryBuilder::new, CommonTermsQueryBuilder::fromXContent, CommonTermsQueryBuilder.QUERY_NAME_FIELD);
registerQuery(SpanMultiTermQueryBuilder::new, SpanMultiTermQueryBuilder::fromXContent, SpanMultiTermQueryBuilder.QUERY_NAME_FIELD);