# Filtered Element makes facets not work?

**URL:** <https://discuss.elastic.co/t/filtered-element-makes-facets-not-work/6433>\
**Category:** Elasticsearch\
**Created:** [January 18, 2012, 8:14pm UTC](https://discuss.elastic.co/t/filtered-element-makes-facets-not-work/6433 "2012-01-18T20:14:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BobbyTables](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bobbytables/32/2444_2.png) [@BobbyTables](https://discuss.elastic.co/u/BobbyTables)\
**Post date:** [January 18, 2012, 8:14pm UTC](https://discuss.elastic.co/t/filtered-element-makes-facets-not-work/6433/1 "2012-01-18T20:14:25Z")

</div>

When I try to use facets with my filtered search I don't get facets. Remove the "filtered" element and it works.

Without filtered:  
curl -X GET "[http://localhost:9200/products/product/\_search?pretty=true](http://localhost:9200/products/product/_search?pretty=true)" -d '{  
"query": {  
"bool": {  
"must": [{  
"query\_string": {  
"query": "\*",  
"default\_operator": "AND"  
}  
}]  
}  
},  
"facets": {  
"tags": {  
"terms": {  
"field": "tag\_names",  
"size": 10,  
"all\_terms": false  
}  
}  
}  
}'

This returns my facets as expected:

{ "took" : 3, "timed\_out" : false, "\_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 2, "max\_score" : 1.0, "hits" : [{ "\_index" : "encore\_dev\_product", "\_type" : "product", "\_id" : "1", "\_score" : 1.0, "\_source" : {"client\_id":1,"description":"","name":"Green Day concert tickets","location\_coordinates":["32.716254,-117.160118"],"tag\_names":["concert","entertainment"]} }, { "\_index" : "encore\_dev\_product", "\_type" : "product", "\_id" : "2", "\_score" : 1.0, "\_source" : {"client\_id":1,"description":null,"name":"Gift certificate","location\_coordinates":["32.716254,-117.160118","33.8095868,-117.9229975"],"tag\_names":["food","restaurant"]} } ] }, "facets" : { "tags" : { "\_type" : "terms", "missing" : 0, "total" : 4, "other" : 0, "terms" : [{ "term" : "restaurant", "count" : 1 }, { "term" : "food", "count" : 1 }, { "term" : "entertainment", "count" : 1 }, { "term" : "concert", "count" : 1 }] } }

With filtered:  
  
curl -X GET "[http://localhost:9200/products/product/\_search?pretty=true](http://localhost:9200/products/product/_search?pretty=true)" -d '{  
"query": {  
"bool": {  
"must": [{  
"query\_string": {  
"query": "\*",  
"default\_operator": "AND"  
}  
}]  
},  
"filtered": {  
"filter": [{  
"geo\_distance": {  
"location\_coordinates": "33.6147846,-117.637617",  
"distance": "90mi"  
}  
}]  
}  
},  
"facets": {  
"tags": {  
"terms": {  
"field": "tag\_names",  
"size": 10,  
"all\_terms": false  
}  
}  
}  
}'

Returns no facets...  
  
{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 2,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "products",  
"\_type" : "product",  
"\_id" : "1",  
"\_score" : 1.0, "\_source" : {"client\_id":1,"description":"","name":"Green Day concert tickets","location\_coordinates":["32.716254,-117.160118"],"tag\_names":["concert","entertainment"]}  
}, {  
"\_index" : "products",  
"\_type" : "product",  
"\_id" : "2",  
"\_score" : 1.0, "\_source" : {"client\_id":1,"description":null,"name":"Gift certificate","location\_coordinates":["32.716254,-117.160118","33.8095868,-117.9229975"],"tag\_names":["food","restaurant"]}  
} ]  
}

What am I doing wrong?

---

<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, 3:42am UTC](https://discuss.elastic.co/t/filtered-element-makes-facets-not-work/6433/2 "2017-07-06T03:42:17Z")

</div>


