# Problem with facet query

**URL:** <https://discuss.elastic.co/t/problem-with-facet-query/7625>\
**Category:** Elasticsearch\
**Created:** [May 10, 2012, 7:26am UTC](https://discuss.elastic.co/t/problem-with-facet-query/7625 "2012-05-10T07:26:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [May 10, 2012, 7:26am UTC](https://discuss.elastic.co/t/problem-with-facet-query/7625/1 "2012-05-10T07:26:47Z")

</div>

Hi,

I have a problem with facet query. The following query works without a  
problem:  
{"sort":[{"date":{"order":"desc"}},"\_score"],"from":0,"fields":["\_source"],"query":{"query\_string":{"query":"test"}},"size":10,"facets":{"tags":{"terms":{"field":"tags"}},"types":{"terms":{"field":"type"}},"count":{"query":{"match\_all":[]}}}}

However, when I change the order of keys in the "facets" part of the query  
ElasticSearch throws an exception. For example:  
{"sort":[{"date":{"order":"desc"}},"\_score"],"from":0,"fields":["\_source"],"query":{"query\_string":{"query":"test"}},"size":10,"facets":{"tags":{"terms":{"field":"tags"}},"count":{"query":{"match\_all":[]}},"types":{"terms":{"field":"type"}}}}

Am I missing something or do I have an error in the query ?

Thanks  
Rafał  
Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - ElasticSearch

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 13, 2012, 9:43am UTC](https://discuss.elastic.co/t/problem-with-facet-query/7625/2 "2012-05-13T09:43:07Z")

</div>

Maybe its the fact that your match\_all is not constructed correctly? It  
should be match\_all: {}, not match\_all : . If you still get it, can you  
create a simple curl repro?

On Thu, May 10, 2012 at 10:26 AM, Rafał Kuć [r.kuc@solr.pl](mailto:r.kuc@solr.pl) wrote:

> Hi,
> 
> I have a problem with facet query. The following query works without a  
> problem:
> 
> {"sort":[{"date":{"order":"desc"}},"\_score"],"from":0,"fields":["\_source"],"query":{"query\_string":{"query":"test"}},"size":10,"facets":{"tags":{"terms":{"field":"tags"}},"types":{"terms":{"field":"type"}},"count":{"query":{"match\_all":}}}}
> 
> However, when I change the order of keys in the "facets" part of the query  
> Elasticsearch throws an exception. For example:
> 
> {"sort":[{"date":{"order":"desc"}},"\_score"],"from":0,"fields":["\_source"],"query":{"query\_string":{"query":"test"}},"size":10,"facets":{"tags":{"terms":{"field":"tags"}},"count":{"query":{"match\_all":}},"types":{"terms":{"field":"type"}}}}
> 
> Am I missing something or do I have an error in the query ?
> 
> Thanks  
> Rafał  
> Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - Elasticsearch

---

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [May 14, 2012, 10:20am UTC](https://discuss.elastic.co/t/problem-with-facet-query/7625/3 "2012-05-14T10:20:37Z")

</div>

Hello!

Thanks Shay, it worked. Don't know why I haven't spotted that 🙂

_--_

Regards,

Rafał Kuć

Sematext :: [http://sematext.com/](http://sematext.com/) _:: Solr - Lucene - Nutch - ElasticSearch_

Maybe its the fact that your match\_all is not constructed correctly? It should be match\_all: {}, not match\_all : []. If you still get it, can you create a simple curl repro?

On Thu, May 10, 2012 at 10:26 AM, Rafał Kuć \<[r.kuc@solr.pl](mailto:r.kuc@solr.pl)\> wrote:

Hi,

I have a problem with facet query. The following query works without a problem:

{"sort":[{"date":{"order":"desc"}},"\_score"],"from":0,"fields":["\_source"],"query":{"query\_string":{"query":"test"}},"size":10,"facets":{"tags":{"terms":{"field":"tags"}},"types":{"terms":{"field":"type"}},"count":{"query":{"match\_all":[]}}}}

However, when I change the order of keys in the "facets" part of the query ElasticSearch throws an exception. For example:

{"sort":[{"date":{"order":"desc"}},"\_score"],"from":0,"fields":["\_source"],"query":{"query\_string":{"query":"test"}},"size":10,"facets":{"tags":{"terms":{"field":"tags"}},"count":{"query":{"match\_all":[]}},"types":{"terms":{"field":"type"}}}}

Am I missing something or do I have an error in the query ?

Thanks

Rafał

Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - ElasticSearch

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 15, 2012, 8:35pm UTC](https://discuss.elastic.co/t/problem-with-facet-query/7625/4 "2012-05-15T20:35:35Z")

</div>

Yea, we should properly fail in this case..., open an issue?

On Mon, May 14, 2012 at 1:20 PM, Rafał Kuć [r.kuc@solr.pl](mailto:r.kuc@solr.pl) wrote:

> Hello!
> 
> Thanks Shay, it worked. Don't know why I haven't spotted that 🙂
> 
> \*--  
> Regards,  
> Rafał Kuć  
> Sematext :: _[http://sematext.com/](http://sematext.com/)_ :: Solr - Lucene - Nutch -  
> Elasticsearch
> 
> - 
> 
> Maybe its the fact that your match\_all is not constructed correctly? It  
> should be match\_all: {}, not match\_all : . If you still get it, can you  
> create a simple curl repro?
> 
> On Thu, May 10, 2012 at 10:26 AM, Rafał Kuć [r.kuc@solr.pl](mailto:r.kuc@solr.pl) wrote:  
> Hi,
> 
> I have a problem with facet query. The following query works without a  
> problem:
> 
> {"sort":[{"date":{"order":"desc"}},"\_score"],"from":0,"fields":["\_source"],"query":{"query\_string":{"query":"test"}},"size":10,"facets":{"tags":{"terms":{"field":"tags"}},"types":{"terms":{"field":"type"}},"count":{"query":{"match\_all":}}}}
> 
> However, when I change the order of keys in the "facets" part of the query  
> Elasticsearch throws an exception. For example:
> 
> {"sort":[{"date":{"order":"desc"}},"\_score"],"from":0,"fields":["\_source"],"query":{"query\_string":{"query":"test"}},"size":10,"facets":{"tags":{"terms":{"field":"tags"}},"count":{"query":{"match\_all":}},"types":{"terms":{"field":"type"}}}}
> 
> Am I missing something or do I have an error in the query ?
> 
> Thanks  
> Rafał  
> Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - Elasticsearch

---

<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:28am UTC](https://discuss.elastic.co/t/problem-with-facet-query/7625/5 "2017-07-06T03:28:41Z")

</div>


