Skip to content

Commit

Permalink
Search: deprecate the limit filter.
Browse files Browse the repository at this point in the history
This is really a Collector instead of a filter. This commit deprecates the
`limit` filter, makes it a no-op and recommends to use the `terminate_after`
parameter instead that we introduced in the meantime.
  • Loading branch information
jpountz committed Apr 10, 2015
1 parent bdc4c7f commit fc91bad
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 111 deletions.
5 changes: 5 additions & 0 deletions docs/reference/migration/migrate_2_0.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,8 @@ http.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/
The cluster state api doesn't return the `routing_nodes` section anymore when
`routing_table` is requested. The newly introduced `routing_nodes` flag can
be used separately to control whether `routing_nodes` should be returned.

=== Query DSL

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
Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1281,20 +1281,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.

Original file line number Diff line number Diff line change
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

0 comments on commit fc91bad

Please sign in to comment.