Skip to content

Commit

Permalink
Merge pull request #10532 from jpountz/deprecate/limit_filter
Browse files Browse the repository at this point in the history
Search: deprecate the limit filter.

Close #10532
  • Loading branch information
jpountz committed Apr 10, 2015
2 parents bad6656 + 5b3cc2f commit 0b413bd
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 111 deletions.
3 changes: 3 additions & 0 deletions docs/reference/migration/migrate_2_0.asciidoc
Original file line number Diff line number Diff line change
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
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 @@ -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.

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 0b413bd

Please sign in to comment.