# Is facet filter allowed inside a filtered query?

**URL:** <https://discuss.elastic.co/t/is-facet-filter-allowed-inside-a-filtered-query/5496>\
**Category:** Elasticsearch\
**Created:** [October 2, 2011, 12:50am UTC](https://discuss.elastic.co/t/is-facet-filter-allowed-inside-a-filtered-query/5496 "2011-10-02T00:50:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liyu](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@Liyu](https://discuss.elastic.co/u/Liyu)\
**Post date:** [October 2, 2011, 12:50am UTC](https://discuss.elastic.co/t/is-facet-filter-allowed-inside-a-filtered-query/5496/1 "2011-10-02T00:50:54Z")

</div>

Hi, I got the following exception, saying "No parser for element  
[term]", when putting a facet filter inside a filtered query.

[2011-10-01 16:37:57,759][DEBUG][action.search.type]  
[Stratosfire] [master][0], node[i6Fw5LCsSPekSt4tvKYLkA], [P],  
s[STARTED]: Failed to execute  
[org.elasticsearch.action.search.SearchRequest@a3ba72]  
org.elasticsearch.search.SearchParseException: [master][0]:  
query[ConstantScore(FilterCacheFilterWrapper(account:acct\_1))],from[-1],size[-1]:  
Parse Failure [Failed to parse source [{"query":{"filtered":{"query":  
{"match\_all":{}},"filter":{"term":{"account":"acct\_1"}},"from":  
0,"size":10,"sort":[],"facets":{"daily\_success":{"date\_histogram":  
{"field":"timeStamp","interval":"day","global":false},"facet\_filter":  
{"term":{"status":"success"}}}}}}}]]  
at  
org.elasticsearch.search.SearchService.parseSource(SearchService.java:  
495)  
at  
org.elasticsearch.search.SearchService.createContext(SearchService.java:  
407)  
at  
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:  
230)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:  
134)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction  
$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:  
80)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction  
$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:204)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction  
$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction  
$BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)  
at java.util.concurrent.ThreadPoolExecutor  
$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor  
$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:619)  
Caused by: org.elasticsearch.search.SearchParseException: [master][0]:  
query[ConstantScore(FilterCacheFilterWrapper(account:acct\_1))],from[-1],size[-1]:  
Parse Failure [No parser for element [term]]  
at  
org.elasticsearch.search.SearchService.parseSource(SearchService.java:  
481)  
... 10 more

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"term": {  
"account": "acct\_1"  
}  
},  
"from": 0,  
"size": 10,  
"sort": [],  
"facets": {  
"daily\_success": {  
"date\_histogram": {  
"field": "timeStamp",  
"interval": "day",  
"global": false  
},  
"facet\_filter": {  
"term": {  
"status": "success"  
}  
}  
}  
}  
}  
}  
}

But if I remove the term clause

```
        "term": {
          "status": "success"
        }

```

Then the query worked fine.

Any sugguestions?

Thanks,

-- Liyu

---

<div class="post-metadata">

**Author:** ![Liyu](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@Liyu](https://discuss.elastic.co/u/Liyu)\
**Post date:** [October 2, 2011, 1:21am UTC](https://discuss.elastic.co/t/is-facet-filter-allowed-inside-a-filtered-query/5496/2 "2011-10-02T01:21:11Z")

</div>

OK, It appears to me the facet must be outside of the query. So the right  
query should be

{  
"query": {  
"filtered": {  
"query": { "match\_all": {} },  
"filter": { "term": { "account": "acct\_1" }  
}  
},  
"from": 0,  
"size": 10,  
"sort": ,  
"facets": {  
"daily\_success": {  
"date\_histogram": {  
"field": "timeStamp",  
"interval": "day",  
"global": false  
},  
"facet\_filter": {  
"term": { "status": "success" }  
}  
}  
}  
}  
}

On Sat, Oct 1, 2011 at 5:50 PM, Liyu [liyuyi@gmail.com](mailto:liyuyi@gmail.com) wrote:

> Hi, I got the following exception, saying "No parser for element  
> [term]", when putting a facet filter inside a filtered query.
> 
> [2011-10-01 16:37:57,759][DEBUG][action.search.type]  
> [Stratosfire] [master][0], node[i6Fw5LCsSPekSt4tvKYLkA], [P],  
> s[STARTED]: Failed to execute  
> [org.elasticsearch.action.search.SearchRequest@a3ba72]  
> org.elasticsearch.search.SearchParseException: [master][0]:
> 
> query[ConstantScore(FilterCacheFilterWrapper(account:acct\_1))],from[-1],size[-1]:  
> Parse Failure [Failed to parse source [{"query":{"filtered":{"query":  
> {"match\_all":{}},"filter":{"term":{"account":"acct\_1"}},"from":  
> 0,"size":10,"sort":,"facets":{"daily\_success":{"date\_histogram":  
> {"field":"timeStamp","interval":"day","global":false},"facet\_filter":  
> {"term":{"status":"success"}}}}}}}]]  
> at  
> org.elasticsearch.search.SearchService.parseSource(SearchService.java:  
> 495)  
> at  
> org.elasticsearch.search.SearchService.createContext(SearchService.java:  
> 407)  
> at
> 
> org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:  
> 230)  
> at
> 
> org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:  
> 134)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction
> 
> $AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:  
> 80)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction  
> $BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:204)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction  
> $BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction  
> $BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)  
> at java.util.concurrent.ThreadPoolExecutor  
> $Worker.runTask(ThreadPoolExecutor.java:886)  
> at java.util.concurrent.ThreadPoolExecutor  
> $Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:619)  
> Caused by: org.elasticsearch.search.SearchParseException: [master][0]:
> 
> query[ConstantScore(FilterCacheFilterWrapper(account:acct\_1))],from[-1],size[-1]:  
> Parse Failure [No parser for element [term]]  
> at  
> org.elasticsearch.search.SearchService.parseSource(SearchService.java:  
> 481)  
> ... 10 more
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "term": {  
> "account": "acct\_1"  
> }  
> },  
> "from": 0,  
> "size": 10,  
> "sort": ,  
> "facets": {  
> "daily\_success": {  
> "date\_histogram": {  
> "field": "timeStamp",  
> "interval": "day",  
> "global": false  
> },  
> "facet\_filter": {  
> "term": {  
> "status": "success"  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> But if I remove the term clause
> 
> ```
> "term": {
> "status": "success"
> }
> 
> ```
> 
> Then the query worked fine.
> 
> Any sugguestions?
> 
> Thanks,
> 
> -- Liyu

---

<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:53am UTC](https://discuss.elastic.co/t/is-facet-filter-allowed-inside-a-filtered-query/5496/3 "2017-07-06T03:53:13Z")

</div>


