# Filters in Query DSL

**URL:** https://discuss.elastic.co/t/filters-in-query-dsl/3098
**Category:** Elasticsearch
**Created:** [July 14, 2010, 3:11pm UTC](https://discuss.elastic.co/t/filters-in-query-dsl/3098 "2010-07-14T15:11:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew\_Degtiariov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_degtiariov/32/3223_2.png) [@Andrew\_Degtiariov](https://discuss.elastic.co/u/Andrew_Degtiariov)
#### Post date: [July 14, 2010, 3:11pm UTC](https://discuss.elastic.co/t/filters-in-query-dsl/3098/1 "2010-07-14T15:11:34Z")

</div>

Hello!

I'm trying to understand how to use filters in queries. For example:

curl -XGET '[http://localhost:9200/contacts/contact/\_sea'ch'](http://localhost:9200/contacts/contact/_sea'ch') -d '  
{  
"filtered" : {  
"query" : {  
"match\_all": {}  
},  
"filter" : {  
"term" : {  
"company\_id": "4ba0c449fa5bd85769000001"  
}  
}  
}  
}

It close to an example from documentation (http://  
[www.elasticsearch.com/docs/elasticsearch/rest\_api/query\_dsl/filtered\_query/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/filtered_query/))  
but I'm get an error:  
...  
Parse Failure [No parser for element [filtered]]

Where am I wrong?

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [July 14, 2010, 3:20pm UTC](https://discuss.elastic.co/t/filters-in-query-dsl/3098/2 "2010-07-14T15:20:11Z")

</div>

On Wed, 2010-07-14 at 08:11 -0700, ad wrote:

> curl -XGET '[http://localhost:9200/contacts/contact/\_sea'ch'](http://localhost:9200/contacts/contact/_sea'ch') -d '  
> {  
> "filtered" : {  
> "query" : {  
> "match\_all": {}  
> },  
> "filter" : {  
> "term" : {  
> "company\_id": "4ba0c449fa5bd85769000001"  
> }  
> }  
> }  
> }

You're missing "query":

curl -XGET '[http://localhost:9200/contacts/contact/\_search](http://localhost:9200/contacts/contact/_search)' -d '  
{  
"query": {  
"filtered" : {  
"query" : {  
"match\_all": {}  
},  
"filter" : {  
"term" : {  
"company\_id": "4ba0c449fa5bd85769000001"  
}  
}  
}  
}  
}

And the same query but somewhat more efficient (apparently):

curl -XGET '[http://localhost:9200/contacts/contact/\_search](http://localhost:9200/contacts/contact/_search)' -d '  
{  
"query": {  
"constant\_score" : {  
"filter" : {  
"term" : {  
"company\_id": "4ba0c449fa5bd85769000001"  
}  
}  
}  
}  
}

clint

---

<div class="post-metadata">

### Author: ![Andrew\_Degtiariov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_degtiariov/32/3223_2.png) [@Andrew\_Degtiariov](https://discuss.elastic.co/u/Andrew_Degtiariov)
#### Post date: [July 14, 2010, 3:26pm UTC](https://discuss.elastic.co/t/filters-in-query-dsl/3098/3 "2010-07-14T15:26:08Z")

</div>

Oh, thank you!  
It's worked 🙂

2010/7/14 Clinton Gormley [clinton@iannounce.co.uk](mailto:clinton@iannounce.co.uk):

> On Wed, 2010-07-14 at 08:11 -0700, ad wrote:
> 
> > curl -XGET '[http://localhost:9200/contacts/contact/\_sea'ch'](http://localhost:9200/contacts/contact/_sea'ch') -d '  
> > {  
> > "filtered" : {  
> > "query" : {  
> > "match\_all": {}  
> > },  
> > "filter" : {  
> > "term" : {  
> > "company\_id": "4ba0c449fa5bd85769000001"  
> > }  
> > }  
> > }  
> > }
> 
> You're missing "query":
> 
> curl -XGET '[http://localhost:9200/contacts/contact/\_search](http://localhost:9200/contacts/contact/_search)' -d '  
> {  
> "query": {  
> "filtered" : {  
> "query" : {  
> "match\_all": {}  
> },  
> "filter" : {  
> "term" : {  
> "company\_id": "4ba0c449fa5bd85769000001"  
> }  
> }  
> }  
> }  
> }
> 
> And the same query but somewhat more efficient (apparently):
> 
> curl -XGET '[http://localhost:9200/contacts/contact/\_search](http://localhost:9200/contacts/contact/_search)' -d '  
> {  
> "query": {  
> "constant\_score" : {  
> "filter" : {  
> "term" : {  
> "company\_id": "4ba0c449fa5bd85769000001"  
> }  
> }  
> }  
> }  
> }
> 
> clint

--  
Andrew Degtiariov  
DA-RIPE

---

<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:22am UTC](https://discuss.elastic.co/t/filters-in-query-dsl/3098/4 "2017-07-06T04:22:17Z")

</div>


