# Are Facet Filters applied after trying to map an element?

**URL:** <https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454>\
**Category:** Elasticsearch\
**Created:** [July 18, 2012, 8:32pm UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454 "2012-07-18T20:32:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack\_Markarian](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jack\_Markarian](https://discuss.elastic.co/u/Jack_Markarian)\
**Post date:** [July 18, 2012, 8:32pm UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454/1 "2012-07-18T20:32:19Z")

</div>

Hey everyone,  
I'm having a problem with the facet filter "exists"... My document design  
looks like this: [http://pastie.org/4279850](http://pastie.org/4279850) ... I want to be able to do a  
statistical facet for date.cpX to get an aggregation.. So, an example use  
case is querying all users for docuements that had a session in a  
particular date range.. Then, I would aggregate each checkpoint for every  
date in that range.. However, not all documents will have a session on  
every day.. That's where I hoped to apply my facet filter  
here: [http://pastie.org/4279233](http://pastie.org/4279233)

As you can see in the query, I first want to match all, and then for all  
docuemnts that have a field "2016-07-01", I want to add up the values for  
"2016-07-01.cp1"... However, I get a "No mapping found for field"  
exception.. I would think this shouldn't happen, because I am disregarding  
documents that don't have a 2016-07-01 date stamp.. (also, here is the  
exception I get: [http://pastie.org/4279892](http://pastie.org/4279892) )

Any help would be much appreciated!

Thanks,  
Jack

---

<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:** [July 18, 2012, 8:54pm UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454/2 "2012-07-18T20:54:52Z")

</div>

The exists filter can't point to a json "object", it needs to be pointing  
to an actual field (that ends up being indexed). You can simply use the  
field you are faceting on.

On Wed, Jul 18, 2012 at 1:32 PM, Jack Markarian [markarianhj@gmail.com](mailto:markarianhj@gmail.com)wrote:

> Hey everyone,  
> I'm having a problem with the facet filter "exists"... My document design  
> looks like this: [http://pastie.org/4279850](http://pastie.org/4279850) ... I want to be able to do a  
> statistical facet for date.cpX to get an aggregation.. So, an example use  
> case is querying all users for docuements that had a session in a  
> particular date range.. Then, I would aggregate each checkpoint for every  
> date in that range.. However, not all documents will have a session on  
> every day.. That's where I hoped to apply my facet filter here:  
> [http://pastie.org/4279233](http://pastie.org/4279233)
> 
> As you can see in the query, I first want to match all, and then for all  
> docuemnts that have a field "2016-07-01", I want to add up the values for  
> "2016-07-01.cp1"... However, I get a "No mapping found for field"  
> exception.. I would think this shouldn't happen, because I am disregarding  
> documents that don't have a 2016-07-01 date stamp.. (also, here is the  
> exception I get: [http://pastie.org/4279892](http://pastie.org/4279892) )
> 
> Any help would be much appreciated!
> 
> Thanks,  
> Jack

---

<div class="post-metadata">

**Author:** ![Jack\_Markarian](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jack\_Markarian](https://discuss.elastic.co/u/Jack_Markarian)\
**Post date:** [July 18, 2012, 9:17pm UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454/3 "2012-07-18T21:17:58Z")

</div>

Thanks Shay! I apologize in advance if I'm slow with this, as it is pretty  
new (but super easy and powerful to use)..

So, I changed the query to look like this:  
curl -XGET '[http://localhost:9200/angrybirdsv3/user/\_search?pretty=true](http://localhost:9200/angrybirdsv3/user/_search?pretty=true)' -d  
'{"query" : {"match\_all" : { }},"facets" : {"stat1" : {"statistical" :  
{"fields" : ["2016-07-01.cp1"]}, "facet\_filter" : {"exists" : {"field" :  
"2016-07-01.cp1"}}}}}'

Now I am using exists on the field itself.. but I get the same exact  
error.. Is that what you meant by not using exists on the object but  
instead the field in the object? If so, then it still didn't work for me.

On Wednesday, July 18, 2012 1:54:52 PM UTC-7, kimchy wrote:

> The exists filter can't point to a json "object", it needs to be pointing  
> to an actual field (that ends up being indexed). You can simply use the  
> field you are faceting on.
> 
> On Wed, Jul 18, 2012 at 1:32 PM, Jack Markarian wrote:
> 
> > Hey everyone,  
> > I'm having a problem with the facet filter "exists"... My document design  
> > looks like this: [http://pastie.org/4279850](http://pastie.org/4279850) ... I want to be able to do a  
> > statistical facet for date.cpX to get an aggregation.. So, an example use  
> > case is querying all users for docuements that had a session in a  
> > particular date range.. Then, I would aggregate each checkpoint for every  
> > date in that range.. However, not all documents will have a session on  
> > every day.. That's where I hoped to apply my facet filter here:  
> > [http://pastie.org/4279233](http://pastie.org/4279233)
> > 
> > As you can see in the query, I first want to match all, and then for all  
> > docuemnts that have a field "2016-07-01", I want to add up the values for  
> > "2016-07-01.cp1"... However, I get a "No mapping found for field"  
> > exception.. I would think this shouldn't happen, because I am disregarding  
> > documents that don't have a 2016-07-01 date stamp.. (also, here is the  
> > exception I get: [http://pastie.org/4279892](http://pastie.org/4279892) )
> > 
> > Any help would be much appreciated!
> > 
> > Thanks,  
> > Jack

---

<div class="post-metadata">

**Author:** ![Jack\_Markarian](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jack\_Markarian](https://discuss.elastic.co/u/Jack_Markarian)\
**Post date:** [July 18, 2012, 9:20pm UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454/4 "2012-07-18T21:20:55Z")

</div>

Also, in case I didn't explain it well previously, neither of the documents  
have the object "2016-07-01", so I would expect the facet to return 0s (or  
NaNs or whatever) for the statistical fields becuase they were totally  
ignored in the faceting..

On Wednesday, July 18, 2012 2:17:58 PM UTC-7, jackM wrote:

> Thanks Shay! I apologize in advance if I'm slow with this, as it is  
> pretty new (but super easy and powerful to use)..
> 
> So, I changed the query to look like this:  
> curl -XGET '[http://localhost:9200/angrybirdsv3/user/\_search?pretty=true](http://localhost:9200/angrybirdsv3/user/_search?pretty=true)'  
> -d '{"query" : {"match\_all" : { }},"facets" : {"stat1" : {"statistical" :  
> {"fields" : ["2016-07-01.cp1"]}, "facet\_filter" : {"exists" : {"field" :  
> "2016-07-01.cp1"}}}}}'
> 
> Now I am using exists on the field itself.. but I get the same exact  
> error.. Is that what you meant by not using exists on the object but  
> instead the field in the object? If so, then it still didn't work for me.
> 
> On Wednesday, July 18, 2012 1:54:52 PM UTC-7, kimchy wrote:
> 
> > The exists filter can't point to a json "object", it needs to be pointing  
> > to an actual field (that ends up being indexed). You can simply use the  
> > field you are faceting on.
> > 
> > On Wed, Jul 18, 2012 at 1:32 PM, Jack Markarian wrote:
> > 
> > > Hey everyone,  
> > > I'm having a problem with the facet filter "exists"... My document  
> > > design looks like this: [http://pastie.org/4279850](http://pastie.org/4279850) ... I want to be able  
> > > to do a statistical facet for date.cpX to get an aggregation.. So, an  
> > > example use case is querying all users for docuements that had a session in  
> > > a particular date range.. Then, I would aggregate each checkpoint for every  
> > > date in that range.. However, not all documents will have a session on  
> > > every day.. That's where I hoped to apply my facet filter here:  
> > > [http://pastie.org/4279233](http://pastie.org/4279233)
> > > 
> > > As you can see in the query, I first want to match all, and then for all  
> > > docuemnts that have a field "2016-07-01", I want to add up the values for  
> > > "2016-07-01.cp1"... However, I get a "No mapping found for field"  
> > > exception.. I would think this shouldn't happen, because I am disregarding  
> > > documents that don't have a 2016-07-01 date stamp.. (also, here is the  
> > > exception I get: [http://pastie.org/4279892](http://pastie.org/4279892) )
> > > 
> > > Any help would be much appreciated!
> > > 
> > > Thanks,  
> > > Jack

---

<div class="post-metadata">

**Author:** ![Jack\_Markarian](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jack\_Markarian](https://discuss.elastic.co/u/Jack_Markarian)\
**Post date:** [July 19, 2012, 12:13am UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454/5 "2012-07-19T00:13:06Z")

</div>

Nevermind.. I figured out the problem.. I am using a dynamic mapping, so if  
I have a mapping in my query that doesn't match any documents, an exception  
is thrown (I assume the query is validated against the index/type mapping  
before being executed, and since no documents have that field, a mapping  
was never created in the dynamic mapping for the type).. so in conclusion,  
as long as I run the facet filter against a field that has been indexed at  
least once before, then I should be golden.. right?

Thanks for the help, Shay.. like I said, I'll prob run into a bunch  
of elementary problems until I get a hang of this, so please be patient! 🙂

Thanks,  
Jack

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [July 19, 2012, 8:00am UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454/6 "2012-07-19T08:00:15Z")

</div>

On Wed, 2012-07-18 at 13:32 -0700, Jack Markarian wrote:

> Hey everyone,  
> I'm having a problem with the facet filter "exists"... My document  
> design looks like this: [http://pastie.org/4279850](http://pastie.org/4279850) ... I want to be  
> able to do a statistical facet for date.cpX to get an aggregation..  
> So, an example use case is querying all users for docuements that had  
> a session in a particular date range.. Then, I would aggregate each  
> checkpoint for every date in that range.. However, not all documents  
> will have a session on every day.. That's where I hoped to apply my  
> facet filter here: [http://pastie.org/4279233](http://pastie.org/4279233)

An object/hash container is not indexed as a field - only its scalar (or  
array of scalars) contents. Try running the 'exists' filter on  
'2016-07-01.cp1' instead.

clint

> As you can see in the query, I first want to match all, and then for  
> all docuemnts that have a field "2016-07-01", I want to add up the  
> values for "2016-07-01.cp1"... However, I get a "No mapping found for  
> field" exception.. I would think this shouldn't happen, because I am  
> disregarding documents that don't have a 2016-07-01 date stamp..  
> (also, here is the exception I get: [http://pastie.org/4279892](http://pastie.org/4279892) )
> 
> Any help would be much appreciated!
> 
> Thanks,  
> Jack

---

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [December 2, 2012, 6:43am UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454/7 "2012-12-02T06:43:14Z")

</div>

I'm having similar problems for facets with dynamic fields.  
Is it possible to ignore 'mapping does not exist' issues and don't raise  
exceptions?

Le jeudi 19 juillet 2012 14:00:15 UTC+6, Clinton Gormley a écrit :

> On Wed, 2012-07-18 at 13:32 -0700, Jack Markarian wrote:
> 
> > Hey everyone,  
> > I'm having a problem with the facet filter "exists"... My document  
> > design looks like this: [http://pastie.org/4279850](http://pastie.org/4279850) ... I want to be  
> > able to do a statistical facet for date.cpX to get an aggregation..  
> > So, an example use case is querying all users for docuements that had  
> > a session in a particular date range.. Then, I would aggregate each  
> > checkpoint for every date in that range.. However, not all documents  
> > will have a session on every day.. That's where I hoped to apply my  
> > facet filter here: [http://pastie.org/4279233](http://pastie.org/4279233)
> 
> An object/hash container is not indexed as a field - only its scalar (or  
> array of scalars) contents. Try running the 'exists' filter on  
> '2016-07-01.cp1' instead.
> 
> clint
> 
> > As you can see in the query, I first want to match all, and then for  
> > all docuemnts that have a field "2016-07-01", I want to add up the  
> > values for "2016-07-01.cp1"... However, I get a "No mapping found for  
> > field" exception.. I would think this shouldn't happen, because I am  
> > disregarding documents that don't have a 2016-07-01 date stamp..  
> > (also, here is the exception I get: [http://pastie.org/4279892](http://pastie.org/4279892) )
> > 
> > Any help would be much appreciated!
> > 
> > Thanks,  
> > Jack

--

---

<div class="post-metadata">

**Author:** ![Jack\_Markarian](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jack\_Markarian](https://discuss.elastic.co/u/Jack_Markarian)\
**Post date:** [December 2, 2012, 6:05pm UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454/8 "2012-12-02T18:05:24Z")

</div>

Hi rauan, what I ended up doing is reading the mapping json into local cache periodically and when constructing the facet query, I would verify that the field I want to facet on is in the mapping.. If not in the mapping then I don't include it in the query.. The no mapping exception is some initial query validation that is run prior to your query executing so I don't think there is another way around it.

Sent from my iPhone

On Dec 1, 2012, at 10:43 PM, Rauan Maemirov [rauan1987@gmail.com](mailto:rauan1987@gmail.com) wrote:

> I'm having similar problems for facets with dynamic fields.  
> Is it possible to ignore 'mapping does not exist' issues and don't raise exceptions?
> 
> Le jeudi 19 juillet 2012 14:00:15 UTC+6, Clinton Gormley a écrit :
> 
> > On Wed, 2012-07-18 at 13:32 -0700, Jack Markarian wrote:
> > 
> > > Hey everyone,  
> > > I'm having a problem with the facet filter "exists"... My document  
> > > design looks like this: [http://pastie.org/4279850](http://pastie.org/4279850) ... I want to be  
> > > able to do a statistical facet for date.cpX to get an aggregation..  
> > > So, an example use case is querying all users for docuements that had  
> > > a session in a particular date range.. Then, I would aggregate each  
> > > checkpoint for every date in that range.. However, not all documents  
> > > will have a session on every day.. That's where I hoped to apply my  
> > > facet filter here: [http://pastie.org/4279233](http://pastie.org/4279233)
> > 
> > An object/hash container is not indexed as a field - only its scalar (or  
> > array of scalars) contents. Try running the 'exists' filter on  
> > '2016-07-01.cp1' instead.
> > 
> > clint
> > 
> > > As you can see in the query, I first want to match all, and then for  
> > > all docuemnts that have a field "2016-07-01", I want to add up the  
> > > values for "2016-07-01.cp1"... However, I get a "No mapping found for  
> > > field" exception.. I would think this shouldn't happen, because I am  
> > > disregarding documents that don't have a 2016-07-01 date stamp..  
> > > (also, here is the exception I get: [http://pastie.org/4279892](http://pastie.org/4279892) )
> > > 
> > > Any help would be much appreciated!
> > > 
> > > Thanks,  
> > > Jack
> 
> --

--

---

<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:01am UTC](https://discuss.elastic.co/t/are-facet-filters-applied-after-trying-to-map-an-element/8454/9 "2017-07-06T03:01:51Z")

</div>


