# My query returns no facets? Any idea?

**URL:** <https://discuss.elastic.co/t/my-query-returns-no-facets-any-idea/15201>\
**Category:** Elasticsearch\
**Created:** [January 10, 2014, 4:24pm UTC](https://discuss.elastic.co/t/my-query-returns-no-facets-any-idea/15201 "2014-01-10T16:24:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgi\_mateev](https://avatars.discourse-cdn.com/v4/letter/g/a6a055/32.png) [@georgi\_mateev](https://discuss.elastic.co/u/georgi_mateev)\
**Post date:** [January 10, 2014, 4:24pm UTC](https://discuss.elastic.co/t/my-query-returns-no-facets-any-idea/15201/1 "2014-01-10T16:24:31Z")

</div>

[http://pastebin.ca/2532879](http://pastebin.ca/2532879)

As you can see, I am getting total, took, \_shards and hits, but no facets.  
What am I doing wrong?

Thank you for your time!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/86a1d8d1-c5a9-4e27-80eb-0a42d7c610aa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/86a1d8d1-c5a9-4e27-80eb-0a42d7c610aa%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 10, 2014, 4:37pm UTC](https://discuss.elastic.co/t/my-query-returns-no-facets-any-idea/15201/2 "2014-01-10T16:37:20Z")

</div>

A few things.

- I am surprised the response did not return an error. Facets work on the  
document set returned by the query, so it is incorrect to add a query  
section to the facet. Try it again without the query.

- Did you really use a JSON with a "body" section?

- The fields parameter does not form part of the query, but part of the  
request.

Try something like:

{  
"query": {  
"match\_all": {}  
},  
"fields": [  
"title"  
],  
"facets": {  
"company": {  
"terms": {  
"field": "locations"  
}  
}  
}  
}

On Fri, Jan 10, 2014 at 8:24 AM, [georgi.mateev@jobvector.com](mailto:georgi.mateev@jobvector.com) wrote:

> [http://pastebin.ca/2532879](http://pastebin.ca/2532879)
> 
> As you can see, I am getting total, took, \_shards and hits, but no facets.  
> What am I doing wrong?
> 
> Thank you for your time!
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/86a1d8d1-c5a9-4e27-80eb-0a42d7c610aa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/86a1d8d1-c5a9-4e27-80eb-0a42d7c610aa%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQC\_SWBgYfMSTC5gw0KrKhF3p7q%3DrRE4B\_8S-gvHZwLwNQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQC_SWBgYfMSTC5gw0KrKhF3p7q%3DrRE4B_8S-gvHZwLwNQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![georgi\_mateev](https://avatars.discourse-cdn.com/v4/letter/g/a6a055/32.png) [@georgi\_mateev](https://discuss.elastic.co/u/georgi_mateev)\
**Post date:** [January 10, 2014, 4:51pm UTC](https://discuss.elastic.co/t/my-query-returns-no-facets-any-idea/15201/3 "2014-01-10T16:51:57Z")

</div>

I did the following request now:

{  
"query": {  
"match\_all": {}  
},  
"facets": {  
"company": {  
"terms": {  
"field": "locations",  
"all\_terms": true  
}  
}  
}  
}

And I got exactly the same response ☹

Am Freitag, 10. Januar 2014 17:37:20 UTC+1 schrieb Ivan Brusic:

> A few things.
> 
> - I am surprised the response did not return an error. Facets work on the  
> document set returned by the query, so it is incorrect to add a query  
> section to the facet. Try it again without the query.
> 
> - Did you really use a JSON with a "body" section?
> 
> - The fields parameter does not form part of the query, but part of the  
> request.
> 
> Try something like:
> 
> {  
> "query": {  
> "match\_all": {}  
> },  
> "fields": [  
> "title"  
> ],  
> "facets": {  
> "company": {  
> "terms": {  
> "field": "locations"  
> }  
> }  
> }  
> }
> 
> On Fri, Jan 10, 2014 at 8:24 AM, \<[georgi...@jobvector.com](mailto:georgi...@jobvector.com) \<javascript:\>\>wrote:
> 
> > [http://pastebin.ca/2532879](http://pastebin.ca/2532879)
> > 
> > As you can see, I am getting total, took, \_shards and hits, but no  
> > facets. What am I doing wrong?
> > 
> > Thank you for your time!
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/86a1d8d1-c5a9-4e27-80eb-0a42d7c610aa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/86a1d8d1-c5a9-4e27-80eb-0a42d7c610aa%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/24d42cc9-4f56-41c0-a18f-236bee7538ff%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/24d42cc9-4f56-41c0-a18f-236bee7538ff%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![georgi\_mateev](https://avatars.discourse-cdn.com/v4/letter/g/a6a055/32.png) [@georgi\_mateev](https://discuss.elastic.co/u/georgi_mateev)\
**Post date:** [January 10, 2014, 6:44pm UTC](https://discuss.elastic.co/t/my-query-returns-no-facets-any-idea/15201/4 "2014-01-10T18:44:49Z")

</div>

There is no error in the request, the HEAD plugin just doesn't show the  
facets ... If I do the request with CURL I get the facets

Am Freitag, 10. Januar 2014 17:24:31 UTC+1 schrieb [georgi...@jobvector.com](mailto:georgi...@jobvector.com):

> [http://pastebin.ca/2532879](http://pastebin.ca/2532879)
> 
> As you can see, I am getting total, took, \_shards and hits, but no facets.  
> What am I doing wrong?
> 
> Thank you for your time!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/50701c11-8883-4c66-9c41-f5562d3dd4ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/50701c11-8883-4c66-9c41-f5562d3dd4ec%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [January 10, 2014, 10:33pm UTC](https://discuss.elastic.co/t/my-query-returns-no-facets-any-idea/15201/5 "2014-01-10T22:33:46Z")

</div>

Here's an example of a facet query, complete with the results of  
post-processing it as a hierarchical combination facet (not yet available  
in ES 0.90.X). The script is used to provide the response in such a way  
that I can easily break it down into a hierarchical combination of  
arbitrary depth. In this example, it shows the top ten words used in cities  
in the USA and Puerto Rico by state.

First, the full query, including the facet. It was issued against  
approximately 26K documents within a type that contains all cities in the  
US and Puerto Rico (originally from the US Census). That's why the  
match\_all with no additional filtering is used. The query was built using  
the Java API, and the JSON below was emitted by the Java API:

{  
"from" : 0,  
"size" : 50000,  
"timeout" : 60000,  
"query" : {  
"match\_all" : { }  
},  
"version" : true,  
"explain" : false,  
"fields" : ["\_ttl", "\_source"],  
"facets" : {  
"state\_city\_combinations" : {  
"terms" : {  
"size" : 10,  
"script" : "doc['state'].value + "~~~" + doc['city'].value"  
}  
}  
}  
}

The response. The "terms" JSON object is what ElasticSearch returned, while  
the "combinations" is what I calculated by processing what ElasticSearch  
returned. Just as a point of interest:

{  
"facets" : {  
"state\_city\_combinations" : {  
"\_type" : "terms",  
"total" : 25376,  
"other" : 25123,  
"missing" : 0,  
"combinations" : {  
"fl" : {  
"beach" : 61,  
"lake" : 18,  
"citi" : 13  
},  
"mo" : {  
"citi" : 36  
},  
"tx" : {  
"citi" : 33  
},  
"il" : {  
"citi" : 22  
},  
"ny" : {  
"east" : 21  
},  
"mn" : {  
"lake" : 19  
},  
"wi" : {  
"lake" : 16  
},  
"ia" : {  
"citi" : 14  
}  
},  
"terms" : [ {  
"term" : "fl~~~beach",  
"count" : 61  
}, {  
"term" : "mo~~~citi",  
"count" : 36  
}, {  
"term" : "tx~~~citi",  
"count" : 33  
}, {  
"term" : "il~~~citi",  
"count" : 22  
}, {  
"term" : "ny~~~east",  
"count" : 21  
}, {  
"term" : "mn~~~lake",  
"count" : 19  
}, {  
"term" : "fl~~~lake",  
"count" : 18  
}, {  
"term" : "wi~~~lake",  
"count" : 16  
}, {  
"term" : "ia~~~citi",  
"count" : 14  
}, {  
"term" : "fl~~~citi",  
"count" : 13  
} ]  
}  
}  
}

Brian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a4e90cd6-3785-498e-a1fe-a3b1acca2ba9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a4e90cd6-3785-498e-a1fe-a3b1acca2ba9%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:57am UTC](https://discuss.elastic.co/t/my-query-returns-no-facets-any-idea/15201/6 "2017-07-06T01:57:20Z")

</div>


