# ES JAVA API | QueryBuilders.java | FilterBuilders does not have nullable queryBuilder as arguement

**URL:** <https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059>\
**Category:** Elasticsearch\
**Created:** [February 10, 2015, 10:24am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059 "2015-02-10T10:24:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piyush\_Goyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piyush_goyal/32/8025_2.png) [@Piyush\_Goyal](https://discuss.elastic.co/u/Piyush_Goyal)\
**Post date:** [February 10, 2015, 10:24am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059/1 "2015-02-10T10:24:36Z")

</div>

Hi All,

If I try to write a filtered query through sense, it allows me to just add  
a filter and query is not a mandatory field. For example:  
{  
"query": {  
"filtered": {  
"filter": {  
"term": {  
"response\_timestamp": "2015-01-01"  
}  
}  
}  
}

is a valid query through sense. However, if I try to implement the same  
through JAVA API, I have to use the abstract class QueryBuilders.java and  
its method:

filteredQuery(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder)

Please note that here FilterBuilder argument is nullable and QueryBuilder  
argument is not. Which means that eventually I have to write a query inside  
the Filtered part. If this correct, then how can I write a complete query  
with aggregations such that I don't want any score to be calculated and the  
response time is faster?

Regards  
Piyush

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 10, 2015, 10:43am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059/2 "2015-02-10T10:43:56Z")

</div>

Use a matchAllQuery for the query part.  
All scores will be set to 1.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 10 févr. 2015 à 11:24, piyush goyal [coolpiyush85@gmail.com](mailto:coolpiyush85@gmail.com) a écrit :
> 
> Hi All,
> 
> If I try to write a filtered query through sense, it allows me to just add a filter and query is not a mandatory field. For example:  
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "term": {  
> "response\_timestamp": "2015-01-01"  
> }  
> }  
> }  
> }
> 
> is a valid query through sense. However, if I try to implement the same through JAVA API, I have to use the abstract class QueryBuilders.java and its method:
> 
> filteredQuery(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder)
> 
> Please note that here FilterBuilder argument is nullable and QueryBuilder argument is not. Which means that eventually I have to write a query inside the Filtered part. If this correct, then how can I write a complete query with aggregations such that I don't want any score to be calculated and the response time is faster?
> 
> ## Regards Piyush
> 
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/69DBE300-0B0B-4441-8734-E0856B959E67%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/69DBE300-0B0B-4441-8734-E0856B959E67%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Piyush\_Goyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piyush_goyal/32/8025_2.png) [@Piyush\_Goyal](https://discuss.elastic.co/u/Piyush_Goyal)\
**Post date:** [February 10, 2015, 10:53am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059/3 "2015-02-10T10:53:43Z")

</div>

I don't need the query part. All I need is a filter.

Not sure how matchAllQuery will help.

On Tuesday, 10 February 2015 16:14:51 UTC+5:30, David Pilato wrote:

> Use a matchAllQuery for the query part.  
> All scores will be set to 1.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 10 févr. 2015 à 11:24, piyush goyal \<[coolpi...@gmail.com](mailto:coolpi...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hi All,
> 
> If I try to write a filtered query through sense, it allows me to just add  
> a filter and query is not a mandatory field. For example:  
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "term": {  
> "response\_timestamp": "2015-01-01"  
> }  
> }  
> }  
> }
> 
> is a valid query through sense. However, if I try to implement the same  
> through JAVA API, I have to use the abstract class QueryBuilders.java and  
> its method:
> 
> filteredQuery(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder)
> 
> Please note that here FilterBuilder argument is nullable and QueryBuilder  
> argument is not. Which means that eventually I have to write a query inside  
> the Filtered part. If this correct, then how can I write a complete query  
> with aggregations such that I don't want any score to be calculated and the  
> response time is faster?
> 
> Regards  
> Piyush
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/57cfc674-7ad7-4232-aa14-534fb394ef34%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/57cfc674-7ad7-4232-aa14-534fb394ef34%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Piyush\_Goyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piyush_goyal/32/8025_2.png) [@Piyush\_Goyal](https://discuss.elastic.co/u/Piyush_Goyal)\
**Post date:** [February 11, 2015, 6:46am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059/4 "2015-02-11T06:46:19Z")

</div>

Hi Folks,

Any inputs?

Regards  
Piyush

On Tuesday, 10 February 2015 16:23:43 UTC+5:30, piyush goyal wrote:

> I don't need the query part. All I need is a filter.
> 
> Not sure how matchAllQuery will help.
> 
> On Tuesday, 10 February 2015 16:14:51 UTC+5:30, David Pilato wrote:
> 
> > Use a matchAllQuery for the query part.  
> > All scores will be set to 1.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 10 févr. 2015 à 11:24, piyush goyal [coolpi...@gmail.com](mailto:coolpi...@gmail.com) a écrit :
> > 
> > Hi All,
> > 
> > If I try to write a filtered query through sense, it allows me to just  
> > add a filter and query is not a mandatory field. For example:  
> > {  
> > "query": {  
> > "filtered": {  
> > "filter": {  
> > "term": {  
> > "response\_timestamp": "2015-01-01"  
> > }  
> > }  
> > }  
> > }
> > 
> > is a valid query through sense. However, if I try to implement the same  
> > through JAVA API, I have to use the abstract class QueryBuilders.java and  
> > its method:
> > 
> > filteredQuery(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder)
> > 
> > Please note that here FilterBuilder argument is nullable and QueryBuilder  
> > argument is not. Which means that eventually I have to write a query inside  
> > the Filtered part. If this correct, then how can I write a complete query  
> > with aggregations such that I don't want any score to be calculated and the  
> > response time is faster?
> > 
> > Regards  
> > Piyush
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 11, 2015, 6:55am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059/5 "2015-02-11T06:55:31Z")

</div>

I think I answered.  
This is what is done by default in REST: [https://github.com/elasticsearch/elasticsearch/blob/1816951b6b0320e7a011436c7c7519ec2bfabc6e/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java#L54](https://github.com/elasticsearch/elasticsearch/blob/1816951b6b0320e7a011436c7c7519ec2bfabc6e/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java#L54)

David

> Le 11 févr. 2015 à 07:46, piyush goyal [coolpiyush85@gmail.com](mailto:coolpiyush85@gmail.com) a écrit :
> 
> Hi Folks,
> 
> Any inputs?
> 
> Regards  
> Piyush
> 
> > On Tuesday, 10 February 2015 16:23:43 UTC+5:30, piyush goyal wrote:  
> > I don't need the query part. All I need is a filter.
> > 
> > Not sure how matchAllQuery will help.
> > 
> > > On Tuesday, 10 February 2015 16:14:51 UTC+5:30, David Pilato wrote:  
> > > Use a matchAllQuery for the query part.  
> > > All scores will be set to 1.
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > > Le 10 févr. 2015 à 11:24, piyush goyal [coolpi...@gmail.com](mailto:coolpi...@gmail.com) a écrit :
> > > > 
> > > > Hi All,
> > > > 
> > > > If I try to write a filtered query through sense, it allows me to just add a filter and query is not a mandatory field. For example:  
> > > > {  
> > > > "query": {  
> > > > "filtered": {  
> > > > "filter": {  
> > > > "term": {  
> > > > "response\_timestamp": "2015-01-01"  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > is a valid query through sense. However, if I try to implement the same through JAVA API, I have to use the abstract class QueryBuilders.java and its method:
> > > > 
> > > > filteredQuery(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder)
> > > > 
> > > > Please note that here FilterBuilder argument is nullable and QueryBuilder argument is not. Which means that eventually I have to write a query inside the Filtered part. If this correct, then how can I write a complete query with aggregations such that I don't want any score to be calculated and the response time is faster?
> > > > 
> > > > ## Regards Piyush
> > > > 
> > > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/285D20CC-7F96-4A46-9159-887B87F9075C%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/285D20CC-7F96-4A46-9159-887B87F9075C%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Piyush\_Goyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piyush_goyal/32/8025_2.png) [@Piyush\_Goyal](https://discuss.elastic.co/u/Piyush_Goyal)\
**Post date:** [February 11, 2015, 7:30am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059/6 "2015-02-11T07:30:16Z")

</div>

Ahh.. Now I got you.

But does that mean, if my rest query through sense does not have any query  
part and only has a filter part, by default ES adds a matchAll Query to the  
query part. So one more question, might be I am asking a wrong question but  
just to clear up my doubts.

So now this query will do separate things:

1.) What a normal match all query does.  
2.) What ever my filter operations are there, the query will perform the  
same as well.

And then ES picks up the intersection of two. Am I right?

Regards  
Piyush

On Wednesday, 11 February 2015 12:25:43 UTC+5:30, David Pilato wrote:

> I think I answered.  
> This is what is done by default in REST:  
> [https://github.com/elasticsearch/elasticsearch/blob/1816951b6b0320e7a011436c7c7519ec2bfabc6e/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java#L54](https://github.com/elasticsearch/elasticsearch/blob/1816951b6b0320e7a011436c7c7519ec2bfabc6e/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java#L54)
> 
> David
> 
> Le 11 févr. 2015 à 07:46, piyush goyal \<[coolpi...@gmail.com](mailto:coolpi...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hi Folks,
> 
> Any inputs?
> 
> Regards  
> Piyush
> 
> On Tuesday, 10 February 2015 16:23:43 UTC+5:30, piyush goyal wrote:
> 
> > I don't need the query part. All I need is a filter.
> > 
> > Not sure how matchAllQuery will help.
> > 
> > On Tuesday, 10 February 2015 16:14:51 UTC+5:30, David Pilato wrote:
> > 
> > > Use a matchAllQuery for the query part.  
> > > All scores will be set to 1.
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 10 févr. 2015 à 11:24, piyush goyal [coolpi...@gmail.com](mailto:coolpi...@gmail.com) a écrit :
> > > 
> > > Hi All,
> > > 
> > > If I try to write a filtered query through sense, it allows me to just  
> > > add a filter and query is not a mandatory field. For example:  
> > > {  
> > > "query": {  
> > > "filtered": {  
> > > "filter": {  
> > > "term": {  
> > > "response\_timestamp": "2015-01-01"  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > is a valid query through sense. However, if I try to implement the same  
> > > through JAVA API, I have to use the abstract class QueryBuilders.java and  
> > > its method:
> > > 
> > > filteredQuery(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder)
> > > 
> > > Please note that here FilterBuilder argument is nullable and  
> > > QueryBuilder argument is not. Which means that eventually I have to write a  
> > > query inside the Filtered part. If this correct, then how can I write a  
> > > complete query with aggregations such that I don't want any score to be  
> > > calculated and the response time is faster?
> > > 
> > > Regards  
> > > Piyush
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f5e22135-746c-4613-92b3-dbac84247677%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f5e22135-746c-4613-92b3-dbac84247677%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 11, 2015, 7:59am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059/7 "2015-02-11T07:59:09Z")

</div>

Actually in a filtered query, filters are applied first.  
The match all query then only said that all filtered documents match.

David

> Le 11 févr. 2015 à 08:30, piyush goyal [coolpiyush85@gmail.com](mailto:coolpiyush85@gmail.com) a écrit :
> 
> Ahh.. Now I got you.
> 
> But does that mean, if my rest query through sense does not have any query part and only has a filter part, by default ES adds a matchAll Query to the query part. So one more question, might be I am asking a wrong question but just to clear up my doubts.
> 
> So now this query will do separate things:
> 
> 1.) What a normal match all query does.  
> 2.) What ever my filter operations are there, the query will perform the same as well.
> 
> And then ES picks up the intersection of two. Am I right?
> 
> Regards  
> Piyush
> 
> > On Wednesday, 11 February 2015 12:25:43 UTC+5:30, David Pilato wrote:  
> > I think I answered.  
> > This is what is done by default in REST: [https://github.com/elasticsearch/elasticsearch/blob/1816951b6b0320e7a011436c7c7519ec2bfabc6e/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java#L54](https://github.com/elasticsearch/elasticsearch/blob/1816951b6b0320e7a011436c7c7519ec2bfabc6e/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java#L54)
> > 
> > David
> > 
> > > Le 11 févr. 2015 à 07:46, piyush goyal [coolpi...@gmail.com](mailto:coolpi...@gmail.com) a écrit :
> > > 
> > > Hi Folks,
> > > 
> > > Any inputs?
> > > 
> > > Regards  
> > > Piyush
> > > 
> > > > On Tuesday, 10 February 2015 16:23:43 UTC+5:30, piyush goyal wrote:  
> > > > I don't need the query part. All I need is a filter.
> > > > 
> > > > Not sure how matchAllQuery will help.
> > > > 
> > > > > On Tuesday, 10 February 2015 16:14:51 UTC+5:30, David Pilato wrote:  
> > > > > Use a matchAllQuery for the query part.  
> > > > > All scores will be set to 1.
> > > > > 
> > > > > --  
> > > > > David 😉  
> > > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > > 
> > > > > > Le 10 févr. 2015 à 11:24, piyush goyal [coolpi...@gmail.com](mailto:coolpi...@gmail.com) a écrit :
> > > > > > 
> > > > > > Hi All,
> > > > > > 
> > > > > > If I try to write a filtered query through sense, it allows me to just add a filter and query is not a mandatory field. For example:  
> > > > > > {  
> > > > > > "query": {  
> > > > > > "filtered": {  
> > > > > > "filter": {  
> > > > > > "term": {  
> > > > > > "response\_timestamp": "2015-01-01"  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > is a valid query through sense. However, if I try to implement the same through JAVA API, I have to use the abstract class QueryBuilders.java and its method:
> > > > > > 
> > > > > > filteredQuery(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder)
> > > > > > 
> > > > > > Please note that here FilterBuilder argument is nullable and QueryBuilder argument is not. Which means that eventually I have to write a query inside the Filtered part. If this correct, then how can I write a complete query with aggregations such that I don't want any score to be calculated and the response time is faster?
> > > > > > 
> > > > > > ## Regards Piyush
> > > > > > 
> > > > > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com).  
> > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f5e22135-746c-4613-92b3-dbac84247677%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f5e22135-746c-4613-92b3-dbac84247677%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/03F95F22-945D-4CC6-914C-45D415ED52D2%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/03F95F22-945D-4CC6-914C-45D415ED52D2%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Piyush\_Goyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piyush_goyal/32/8025_2.png) [@Piyush\_Goyal](https://discuss.elastic.co/u/Piyush_Goyal)\
**Post date:** [February 11, 2015, 8:27am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059/8 "2015-02-11T08:27:15Z")

</div>

Ok. That helps a lot in getting the things but still I do feel, since ES is  
internally marking the query as MatchAll query, the method definition  
should have Nullable query as well.

Thanks once again for helping out. 🙂

Regards  
Piyush

On Wednesday, 11 February 2015 13:29:32 UTC+5:30, David Pilato wrote:

> Actually in a filtered query, filters are applied first.  
> The match all query then only said that all filtered documents match.
> 
> David
> 
> Le 11 févr. 2015 à 08:30, piyush goyal \<[coolpi...@gmail.com](mailto:coolpi...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Ahh.. Now I got you.
> 
> But does that mean, if my rest query through sense does not have any query  
> part and only has a filter part, by default ES adds a matchAll Query to the  
> query part. So one more question, might be I am asking a wrong question but  
> just to clear up my doubts.
> 
> So now this query will do separate things:
> 
> 1.) What a normal match all query does.  
> 2.) What ever my filter operations are there, the query will perform the  
> same as well.
> 
> And then ES picks up the intersection of two. Am I right?
> 
> Regards  
> Piyush
> 
> On Wednesday, 11 February 2015 12:25:43 UTC+5:30, David Pilato wrote:
> 
> > I think I answered.  
> > This is what is done by default in REST:  
> > [https://github.com/elasticsearch/elasticsearch/blob/1816951b6b0320e7a011436c7c7519ec2bfabc6e/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java#L54](https://github.com/elasticsearch/elasticsearch/blob/1816951b6b0320e7a011436c7c7519ec2bfabc6e/src/main/java/org/elasticsearch/index/query/FilteredQueryParser.java#L54)
> > 
> > David
> > 
> > Le 11 févr. 2015 à 07:46, piyush goyal [coolpi...@gmail.com](mailto:coolpi...@gmail.com) a écrit :
> > 
> > Hi Folks,
> > 
> > Any inputs?
> > 
> > Regards  
> > Piyush
> > 
> > On Tuesday, 10 February 2015 16:23:43 UTC+5:30, piyush goyal wrote:
> > 
> > > I don't need the query part. All I need is a filter.
> > > 
> > > Not sure how matchAllQuery will help.
> > > 
> > > On Tuesday, 10 February 2015 16:14:51 UTC+5:30, David Pilato wrote:
> > > 
> > > > Use a matchAllQuery for the query part.  
> > > > All scores will be set to 1.
> > > > 
> > > > --  
> > > > David 😉  
> > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > 
> > > > Le 10 févr. 2015 à 11:24, piyush goyal [coolpi...@gmail.com](mailto:coolpi...@gmail.com) a écrit :
> > > > 
> > > > Hi All,
> > > > 
> > > > If I try to write a filtered query through sense, it allows me to just  
> > > > add a filter and query is not a mandatory field. For example:  
> > > > {  
> > > > "query": {  
> > > > "filtered": {  
> > > > "filter": {  
> > > > "term": {  
> > > > "response\_timestamp": "2015-01-01"  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > is a valid query through sense. However, if I try to implement the same  
> > > > through JAVA API, I have to use the abstract class QueryBuilders.java and  
> > > > its method:
> > > > 
> > > > filteredQuery(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder)
> > > > 
> > > > Please note that here FilterBuilder argument is nullable and  
> > > > QueryBuilder argument is not. Which means that eventually I have to write a  
> > > > query inside the Filtered part. If this correct, then how can I write a  
> > > > complete query with aggregations such that I don't want any score to be  
> > > > calculated and the response time is faster?
> > > > 
> > > > Regards  
> > > > Piyush
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d1bfad33-93d3-407a-8c0a-8184045f88ec%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google Groups  
> > > > "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c44055a5-1654-48fa-9787-503228e39de9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/f5e22135-746c-4613-92b3-dbac84247677%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f5e22135-746c-4613-92b3-dbac84247677%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/f5e22135-746c-4613-92b3-dbac84247677%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f5e22135-746c-4613-92b3-dbac84247677%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/cf379e01-76ee-4ed3-94ba-92bb2a95845f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cf379e01-76ee-4ed3-94ba-92bb2a95845f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:33am UTC](https://discuss.elastic.co/t/es-java-api-querybuilders-java-filterbuilders-does-not-have-nullable-querybuilder-as-arguement/22059/9 "2017-07-06T00:33:39Z")

</div>


