# Unable to execute "Terms Facet " query

**URL:** <https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151>\
**Category:** Elasticsearch\
**Created:** [July 26, 2010, 10:24am UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151 "2010-07-26T10:24:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishal\_ingle](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@vishal\_ingle](https://discuss.elastic.co/u/vishal_ingle)\
**Post date:** [July 26, 2010, 10:24am UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/1 "2010-07-26T10:24:23Z")

</div>

Hi,

I am facing a problem with "terms facet".  
The document contains "userscore" and "userid" fields. I m sorting  
them on "userscore" field . I want two things from one query .1) top  
score 2) score of given userid .

I have been trying the following query by passing it in the request  
body.

{  
"query" : {  
"term" : {  
"tournamentid" : "220"  
}  
},  
"sort": {  
"userscore" : {"reverse" : true}  
},  
"facets" : {  
"tag" : {  
"terms" : {  
"userid" : "potter",  
"size" : 10  
} ,  
"global" : false  
}  
}  
}

and i m getting this error "Parse Failure [No facet type found for  
[tag]]];"

Please let me know a solution for this.

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 26, 2010, 10:34am UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/2 "2010-07-26T10:34:52Z")

</div>

Hi,

I think you need to say:

"facets" : {  
"tag" : {  
"terms" : {  
"field" : "userid", // \<-- note the "field" string  
"size" : 10  
} ,  
"global" : false  
}  
}

Note that where you originally said "userid" there was "field" expected.

Regards,  
Lukas

On Mon, Jul 26, 2010 at 12:24 PM, vishal ingle [vishalingle@gmail.com](mailto:vishalingle@gmail.com)wrote:

> Hi,
> 
> I am facing a problem with "terms facet".  
> The document contains "userscore" and "userid" fields. I m sorting  
> them on "userscore" field . I want two things from one query .1) top  
> score 2) score of given userid .
> 
> I have been trying the following query by passing it in the request  
> body.
> 
> {  
> "query" : {  
> "term" : {  
> "tournamentid" : "220"  
> }  
> },  
> "sort": {  
> "userscore" : {"reverse" : true}  
> },  
> "facets" : {  
> "tag" : {  
> "terms" : {  
> "userid" : "potter",  
> "size" : 10  
> } ,  
> "global" : false  
> }  
> }  
> }
> 
> and i m getting this error "Parse Failure [No facet type found for  
> [tag]]];"
> 
> Please let me know a solution for this.

---

<div class="post-metadata">

**Author:** ![vishal\_ingle](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@vishal\_ingle](https://discuss.elastic.co/u/vishal_ingle)\
**Post date:** [July 26, 2010, 11:12am UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/3 "2010-07-26T11:12:09Z")

</div>

Hi,

I tried your solution Lukas but still its giving error. I think its the  
condition for the facet query .

Regards,  
Vishal Ingle

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 26, 2010, 11:48am UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/4 "2010-07-26T11:48:57Z")

</div>

I am using a very similar query and the facets portion of the json looks  
good to me (except the "field" part, you really need to use "field" string  
to tell elasticsearch which field you want to aggregate facets on).

Which version of elasticsearch are you using?

Lukas

On Mon, Jul 26, 2010 at 1:12 PM, vishal ingle [vishalingle@gmail.com](mailto:vishalingle@gmail.com) wrote:

> Hi,
> 
> I tried your solution Lukas but still its giving error. I think its the  
> condition for the facet query .
> 
> Regards,  
> Vishal Ingle

---

<div class="post-metadata">

**Author:** ![vishal\_ingle](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@vishal\_ingle](https://discuss.elastic.co/u/vishal_ingle)\
**Post date:** [July 26, 2010, 11:54am UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/5 "2010-07-26T11:54:51Z")

</div>

Version 0.8 .

I tried your solution but still its throwing error .

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 26, 2010, 12:10pm UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/6 "2010-07-26T12:10:27Z")

</div>

Do you think you can try it with 0.9.0-SNAPSHOT?  
0.9.0 should be released very very soon (probably today or tomorrow) anyway.

Also if you can send a stack trace from the server log it could help.

Regards,  
Lukas

On Mon, Jul 26, 2010 at 1:54 PM, vishal ingle [vishalingle@gmail.com](mailto:vishalingle@gmail.com) wrote:

> Version 0.8 .
> 
> I tried your solution but still its throwing error .

---

<div class="post-metadata">

**Author:** ![vishal\_ingle](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@vishal\_ingle](https://discuss.elastic.co/u/vishal_ingle)\
**Post date:** [July 26, 2010, 12:18pm UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/7 "2010-07-26T12:18:36Z")

</div>

[17:40:52,773][DEBUG][action.search.type] [Aunt May Parker]  
[tournament][3], Node[057b434a-6bc3-4660-b17f-b3bb24f3b440], [P],  
S[STARTED]: Failed to execute  
[org.elasticsearch.action.search.SearchRequest@2db51a5c]  
org.elasticsearch.search.SearchParseException: [tournament][3]:  
query[tournamentid:[220 TO 220]],from[-1],size[-1],sort[\<double:  
"userscore"\>!]: Parse Failure [Failed to parse [{  
"query" : {  
"term" : {  
"tournamentid" : "220"  
}  
},  
"sort": {  
"userscore" : {"reverse" : true}  
},  
"facets" : {  
"tag" : {  
"terms" : {  
"userid" : "potter",  
"size" : 10  
} ,  
"global" : false  
}  
}  
}]]  
at  
org.elasticsearch.search.SearchService.parseSource(SearchService.java:355)  
at  
org.elasticsearch.search.SearchService.createContext(SearchService.java:292)  
at  
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:161)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:129)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:77)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:180)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.access$000(TransportSearchTypeAction.java:78)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.run(TransportSearchTypeAction.java:142)  
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: [tournament][3]:  
query[tournamentid:[220 TO 220]],from[-1],size[-1],sort[\<double:  
"userscore"\>!]: Parse Failure [No facet type found for [tag]]  
at  
org.elasticsearch.search.facets.FacetsParseElement.parse(FacetsParseElement.java:90)  
at  
org.elasticsearch.search.SearchService.parseSource(SearchService.java:349)  
... 10 more

---

<div class="post-metadata">

**Author:** ![vishal\_ingle](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@vishal\_ingle](https://discuss.elastic.co/u/vishal_ingle)\
**Post date:** [July 26, 2010, 12:36pm UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/8 "2010-07-26T12:36:03Z")

</div>

The earlier was for the query i was trying... and as u suggested the query  
gave following error..

[18:00:45,910][DEBUG][action.search.type] [Aunt May Parker]  
[tournament][0], Node[057b434a-6bc3-4660-b17f-b3bb24f3b440], [P],  
S[STARTED]: Failed to execute  
[org.elasticsearch.action.search.SearchRequest@72556b3d]  
org.elasticsearch.search.SearchParseException: [tournament][0]:  
query[tournamentid:[220 TO 220]],from[-1],size[-1],sort[\<double:  
"userscore"\>!]: Parse Failure [Failed to parse [{  
"query" : {  
"term" : {  
"tournamentid" : "220"  
}  
},  
"sort": {  
"userscore" : {"reverse" : true}  
},  
"facets" : {  
"tag" : {  
"terms" : {  
"field" : "userid",  
"size" : 10  
} ,  
"global" : false  
}  
}  
}]]  
at  
org.elasticsearch.search.SearchService.parseSource(SearchService.java:355)  
at  
org.elasticsearch.search.SearchService.createContext(SearchService.java:292)  
at  
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:161)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:129)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:77)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:180)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.access$000(TransportSearchTypeAction.java:78)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.run(TransportSearchTypeAction.java:142)  
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: [tournament][0]:  
query[tournamentid:[220 TO 220]],from[-1],size[-1],sort[\<double:  
"userscore"\>!]: Parse Failure [No facet type found for [tag]]  
at  
org.elasticsearch.search.facets.FacetsParseElement.parse(FacetsParseElement.java:90)  
at  
org.elasticsearch.search.SearchService.parseSource(SearchService.java:349)  
... 10 more

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 26, 2010, 1:00pm UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/9 "2010-07-26T13:00:59Z")

</div>

## The syntax of query DSL has changed, so if I understand old documentation correctly ( [http://github.com/elasticsearch/elasticsearch.github.com/blob/09f7ac3248e6607e6bf1825fa26c0bb2b3b08e60/docs/elasticsearch/rest\_api/search/index.textile](http://github.com/elasticsearch/elasticsearch.github.com/blob/09f7ac3248e6607e6bf1825fa26c0bb2b3b08e60/docs/elasticsearch/rest_api/search/index.textile)

search for Facet Queries) then you should probably use "term" instead of  
"terms":

"facets" : {  
"tag" : {  
"term" : { // \<- here is the change  
"userid" : "potter",  
"size" : 10  
} ,  
"global" : false  
}  
}

But note that current online documentation is prepared for new 0.9.0 release  
and is not valid for older releases (so I am not sure about the "size" usage  
inside the facets in your case).

Regards,  
Lukas

On Mon, Jul 26, 2010 at 2:18 PM, vishal ingle [vishalingle@gmail.com](mailto:vishalingle@gmail.com) wrote:

> [17:40:52,773][DEBUG][action.search.type] [Aunt May Parker]  
> [tournament][3], Node[057b434a-6bc3-4660-b17f-b3bb24f3b440], [P],  
> S[STARTED]: Failed to execute  
> [org.elasticsearch.action.search.SearchRequest@2db51a5c]  
> org.elasticsearch.search.SearchParseException: [tournament][3]:  
> query[tournamentid:[220 TO 220]],from[-1],size[-1],sort[\<double:  
> "userscore"\>!]: Parse Failure [Failed to parse [{
> 
> "query" : {  
> "term" : {  
> "tournamentid" : "220"  
> }  
> },  
> "sort": {  
> "userscore" : {"reverse" : true}  
> },  
> "facets" : {  
> "tag" : {  
> "terms" : {  
> "userid" : "potter",  
> "size" : 10  
> } ,  
> "global" : false  
> }  
> }  
> }]]  
> at  
> org.elasticsearch.search.SearchService.parseSource(SearchService.java:355)  
> at  
> org.elasticsearch.search.SearchService.createContext(SearchService.java:292)  
> at  
> org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:161)  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:129)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:77)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:180)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.access$000(TransportSearchTypeAction.java:78)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.run(TransportSearchTypeAction.java:142)  
> 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: [tournament][3]:  
> query[tournamentid:[220 TO 220]],from[-1],size[-1],sort[\<double:  
> "userscore"\>!]: Parse Failure [No facet type found for [tag]]  
> at  
> org.elasticsearch.search.facets.FacetsParseElement.parse(FacetsParseElement.java:90)  
> at  
> org.elasticsearch.search.SearchService.parseSource(SearchService.java:349)  
> ... 10 more

---

<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:21am UTC](https://discuss.elastic.co/t/unable-to-execute-terms-facet-query/3151/10 "2017-07-06T04:21:37Z")

</div>


