Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate the limit filter. #10532

Merged
merged 1 commit into from Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/reference/migration/migrate_2_0.asciidoc
Expand Up @@ -383,3 +383,6 @@ be used separately to control whether `routing_nodes` should be returned.
=== Query DSL

The `fuzzy_like_this` and `fuzzy_like_this_field` queries have been removed.

The `limit` filter is deprecated and becomes a no-op. You can achieve similar
behaviour using the <<search-request-body,terminate_after>> parameter.
2 changes: 2 additions & 0 deletions docs/reference/query-dsl/filters/limit-filter.asciidoc
@@ -1,6 +1,8 @@
[[query-dsl-limit-filter]]
=== Limit Filter

deprecated[2.0.0, Use <<search-request-body,terminate_after>> instead]

A limit filter limits the number of documents (per shard) to execute on.
For example:

Expand Down

This file was deleted.

Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.index.query;

import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.geo.GeoPoint;
Expand All @@ -39,7 +40,9 @@ public static MatchAllFilterBuilder matchAllFilter() {

/**
* A filter that limits the results to the provided limit value (per shard!).
* @deprecated Use {@link SearchRequestBuilder#setTerminateAfter(int)} instead.
*/
@Deprecated
public static LimitFilterBuilder limitFilter(int limit) {
return new LimitFilterBuilder(limit);
}
Expand Down
Expand Up @@ -19,10 +19,15 @@

package org.elasticsearch.index.query;

import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;

/**
* @deprecated Use {@link SearchRequestBuilder#setTerminateAfter(int)} instead.
*/
@Deprecated
public class LimitFilterBuilder extends BaseFilterBuilder {

private final int limit;
Expand Down
Expand Up @@ -21,7 +21,7 @@

import org.apache.lucene.search.Filter;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.search.LimitFilter;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;
Expand Down Expand Up @@ -62,6 +62,7 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
throw new QueryParsingException(parseContext.index(), "No value specified for limit filter");
}

return new LimitFilter(limit);
// this filter is deprecated and parses to a filter that matches everything
return Queries.MATCH_ALL_FILTER;
}
}
Expand Up @@ -303,7 +303,7 @@ public void testLimitFilter() throws Exception {
client().prepareIndex("test", "type1", "4").setSource("field3", "value3_4"));

CountResponse countResponse = client().prepareCount().setQuery(filteredQuery(matchAllQuery(), limitFilter(2))).get();
assertHitCount(countResponse, 2l);
assertHitCount(countResponse, 4l); // limit is a no-op
}

@Test
Expand Down
Expand Up @@ -1280,20 +1280,6 @@ public void testFilteredQuery4() throws IOException {
assertThat(getTerm(filteredQuery.getFilter()), equalTo(new Term("name.last", "banon")));
}

@Test
public void testLimitFilter() throws Exception {
IndexQueryParserService queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/limit-filter.json");
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, instanceOf(FilteredQuery.class));
FilteredQuery filteredQuery = (FilteredQuery) parsedQuery;
assertThat(filteredQuery.getFilter(), instanceOf(LimitFilter.class));
assertThat(((LimitFilter) filteredQuery.getFilter()).getLimit(), equalTo(2));

assertThat(filteredQuery.getQuery(), instanceOf(TermQuery.class));
assertThat(((TermQuery) filteredQuery.getQuery()).getTerm(), equalTo(new Term("name.first", "shay")));
}

@Test
public void testTermFilterQuery() throws Exception {
IndexQueryParserService queryParser = queryParser();
Expand Down
14 changes: 0 additions & 14 deletions src/test/java/org/elasticsearch/index/query/limit-filter.json

This file was deleted.

Expand Up @@ -677,7 +677,7 @@ public void testLimitFilter() throws Exception {
client().prepareIndex("test", "type1", "3").setSource("field2", "value2_3"),
client().prepareIndex("test", "type1", "4").setSource("field3", "value3_4"));

assertHitCount(client().prepareSearch().setQuery(filteredQuery(matchAllQuery(), limitFilter(2))).get(), 2l);
assertHitCount(client().prepareSearch().setQuery(filteredQuery(matchAllQuery(), limitFilter(2))).get(), 4l); // no-op
}

@Test
Expand Down