parent
d7a068d02c
commit
0fd3ef6df0
|
@ -40,10 +40,10 @@ public class FilteredQueryBuilder extends BaseQueryBuilder implements BoostableQ
|
||||||
/**
|
/**
|
||||||
* A query that applies a filter to the results of another query.
|
* A query that applies a filter to the results of another query.
|
||||||
*
|
*
|
||||||
* @param queryBuilder The query to apply the filter to
|
* @param queryBuilder The query to apply the filter to (Can be null)
|
||||||
* @param filterBuilder The filter to apply on the query (Can be null)
|
* @param filterBuilder The filter to apply on the query (Can be null)
|
||||||
*/
|
*/
|
||||||
public FilteredQueryBuilder(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder) {
|
public FilteredQueryBuilder(@Nullable QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder) {
|
||||||
this.queryBuilder = queryBuilder;
|
this.queryBuilder = queryBuilder;
|
||||||
this.filterBuilder = filterBuilder;
|
this.filterBuilder = filterBuilder;
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,10 @@ public class FilteredQueryBuilder extends BaseQueryBuilder implements BoostableQ
|
||||||
@Override
|
@Override
|
||||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(FilteredQueryParser.NAME);
|
builder.startObject(FilteredQueryParser.NAME);
|
||||||
|
if (queryBuilder != null) {
|
||||||
builder.field("query");
|
builder.field("query");
|
||||||
queryBuilder.toXContent(builder, params);
|
queryBuilder.toXContent(builder, params);
|
||||||
|
}
|
||||||
if (filterBuilder != null) {
|
if (filterBuilder != null) {
|
||||||
builder.field("filter");
|
builder.field("filter");
|
||||||
filterBuilder.toXContent(builder, params);
|
filterBuilder.toXContent(builder, params);
|
||||||
|
|
|
@ -395,7 +395,7 @@ public abstract class QueryBuilders {
|
||||||
* @param queryBuilder The query to apply the filter to
|
* @param queryBuilder The query to apply the filter to
|
||||||
* @param filterBuilder The filter to apply on the query
|
* @param filterBuilder The filter to apply on the query
|
||||||
*/
|
*/
|
||||||
public static FilteredQueryBuilder filteredQuery(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder) {
|
public static FilteredQueryBuilder filteredQuery(@Nullable QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder) {
|
||||||
return new FilteredQueryBuilder(queryBuilder, filterBuilder);
|
return new FilteredQueryBuilder(queryBuilder, filterBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2662,6 +2662,18 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // see #7365
|
||||||
|
public void testFilteredQueryWithoutQuery() throws Exception {
|
||||||
|
createIndex("test");
|
||||||
|
ensureYellow("test");
|
||||||
|
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "value1"));
|
||||||
|
SearchResponse response = client().prepareSearch()
|
||||||
|
.setQuery(QueryBuilders.filteredQuery(null,
|
||||||
|
FilterBuilders.termFilter("field1", "value1"))).get();
|
||||||
|
assertSearchResponse(response);
|
||||||
|
assertHitCount(response, 1l);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryStringParserCache() throws Exception {
|
public void testQueryStringParserCache() throws Exception {
|
||||||
createIndex("test");
|
createIndex("test");
|
||||||
|
|
Loading…
Reference in New Issue