# Faceting on non-existent field

**URL:** https://discuss.elastic.co/t/faceting-on-non-existent-field/12474
**Category:** Elasticsearch
**Created:** [June 19, 2013, 7:49am UTC](https://discuss.elastic.co/t/faceting-on-non-existent-field/12474 "2013-06-19T07:49:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Allan\_Johns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/allan_johns/32/2387_2.png) [@Allan\_Johns](https://discuss.elastic.co/u/Allan_Johns)
#### Post date: [June 19, 2013, 7:49am UTC](https://discuss.elastic.co/t/faceting-on-non-existent-field/12474/1 "2013-06-19T07:49:21Z")

</div>

Hi all,

When doing a faceted filter/query where the facet term doesn't exist in any  
document, is it possible for elasticsearch to return an empty facet result,  
rather than throw an exception?

If this isn't possible, would it be reasonable to add an option to the API  
to turn this functionality on?

Thanks  
A

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [June 24, 2013, 1:45pm UTC](https://discuss.elastic.co/t/faceting-on-non-existent-field/12474/2 "2013-06-24T13:45:38Z")

</div>

Hey,

can you sent a gist of what you do in order to trigger an exception.  
Usually an empty result like this is returned

curl -X PUT localhost:9200/foo  
{"ok":true,"acknowledged":true}

curl -X POST 'localhost:9200/foo/\_search?pretty' -d '{ "facets" : { "foo"  
: { "terms" : { "field" : "bar" } } } }'  
{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" :   
},  
"facets" : {  
"foo" : {  
"\_type" : "terms",  
"missing" : 0,  
"total" : 0,  
"other" : 0,  
"terms" :   
}  
}  
}

Maybe you had a slight error in your query somewhere?

--Alex

On Wed, Jun 19, 2013 at 9:49 AM, Allan Johns [nerdvegas@gmail.com](mailto:nerdvegas@gmail.com) wrote:

> Hi all,
> 
> When doing a faceted filter/query where the facet term doesn't exist in  
> any document, is it possible for elasticsearch to return an empty facet  
> result, rather than throw an exception?
> 
> If this isn't possible, would it be reasonable to add an option to the API  
> to turn this functionality on?
> 
> Thanks  
> A
> 
> --  
> 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).  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Allan\_Johns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/allan_johns/32/2387_2.png) [@Allan\_Johns](https://discuss.elastic.co/u/Allan_Johns)
#### Post date: [June 24, 2013, 11:05pm UTC](https://discuss.elastic.co/t/faceting-on-non-existent-field/12474/3 "2013-06-24T23:05:36Z")

</div>

Hey Alexander,

Running your example query I get:

FacetPhaseExecutionException[Facet [foo]: failed to find mapping for  
[bar]];

In a duplicate thread someone has said this is fixed in 0.90.1 (I'm on  
0.90.0), so I'm goign to try that.

Thanks for your help  
A

On Mon, Jun 24, 2013 at 11:45 PM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de)wrote:

> Hey,
> 
> can you sent a gist of what you do in order to trigger an exception.  
> Usually an empty result like this is returned
> 
> curl -X PUT localhost:9200/foo  
> {"ok":true,"acknowledged":true}
> 
> curl -X POST 'localhost:9200/foo/\_search?pretty' -d '{ "facets" : { "foo"  
> : { "terms" : { "field" : "bar" } } } }'  
> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> },  
> "facets" : {  
> "foo" : {  
> "\_type" : "terms",  
> "missing" : 0,  
> "total" : 0,  
> "other" : 0,  
> "terms" :   
> }  
> }  
> }
> 
> Maybe you had a slight error in your query somewhere?
> 
> --Alex
> 
> On Wed, Jun 19, 2013 at 9:49 AM, Allan Johns [nerdvegas@gmail.com](mailto:nerdvegas@gmail.com) wrote:
> 
> > Hi all,
> > 
> > When doing a faceted filter/query where the facet term doesn't exist in  
> > any document, is it possible for elasticsearch to return an empty facet  
> > result, rather than throw an exception?
> > 
> > If this isn't possible, would it be reasonable to add an option to the  
> > API to turn this functionality on?
> > 
> > Thanks  
> > A
> > 
> > --  
> > 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).  
> > 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).  
> 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).  
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, 2:29am UTC](https://discuss.elastic.co/t/faceting-on-non-existent-field/12474/4 "2017-07-06T02:29:41Z")

</div>


