# Re: Filter a query without a term

**URL:** <https://discuss.elastic.co/t/re-filter-a-query-without-a-term/4098>\
**Category:** Elasticsearch\
**Created:** [March 15, 2011, 11:51am UTC](https://discuss.elastic.co/t/re-filter-a-query-without-a-term/4098 "2011-03-15T11:51:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IvanBrusic](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@IvanBrusic](https://discuss.elastic.co/u/IvanBrusic)\
**Post date:** [March 15, 2011, 11:51am UTC](https://discuss.elastic.co/t/re-filter-a-query-without-a-term/4098/1 "2011-03-15T11:51:35Z")

</div>

I can think of two possible solutions, both requiring you to change  
the JSON format if there is no query provided (no graceful syntax  
change).

One solution is the match\_all query, which can be followed up by your  
filter: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/match-all-query.html)

Another solution would be to use a constant score query, which always  
wraps around a filter: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/constant-score-query.html)

I do not know the performance implications of either query, but I  
would assume the latter solution is better since there is no scoring  
involved.

Ivan

On Mar 14, 8:07 pm, Rob Faraj [rfa...@gmail.com](mailto:rfa...@gmail.com) wrote:

> I'm still relatively new to Elasticsearch and can't seem to figure out  
> if I'm doing this correctly. I am trying to produce a query that  
> searches for a given string. In addition to this query I also want to  
> filter the results off of an integer field in the document. I am using  
> the request below and its working...
> 
> curl -XPOST '[http://localhost:9200/index/type/\_search](http://localhost:9200/index/type/_search)?  
> pretty=true&fields=\_id,item\_id' -d '  
> {  
> "query" : {  
> "query\_string" : {  
> "query" : "foobar"  
> }  
> },  
> "filter" : {  
> "query" : {  
> "field": {  
> "status\_id" : "1"  
> }  
> }  
> }}
> 
> '
> 
> Sometimes there is no term provided, but I would still like to filter  
> the results. I have substituted the term (foobar) for "\*" which I  
> guess matches everything. Is this a good approach for what I'm trying  
> to accomplish?
> 
> Thanks in advance.

---

<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, 4:10am UTC](https://discuss.elastic.co/t/re-filter-a-query-without-a-term/4098/2 "2017-07-06T04:10:04Z")

</div>


