# statisticalFacet does now work properly with dynamic mapping

**URL:** <https://discuss.elastic.co/t/statisticalfacet-does-now-work-properly-with-dynamic-mapping/5669>\
**Category:** Elasticsearch\
**Created:** [October 24, 2011, 4:47pm UTC](https://discuss.elastic.co/t/statisticalfacet-does-now-work-properly-with-dynamic-mapping/5669 "2011-10-24T16:47:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gautam\_S](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@Gautam\_S](https://discuss.elastic.co/u/Gautam_S)\
**Post date:** [October 24, 2011, 4:47pm UTC](https://discuss.elastic.co/t/statisticalfacet-does-now-work-properly-with-dynamic-mapping/5669/1 "2011-10-24T16:47:33Z")

</div>

Hi,

Not been able make statisticalFacet work with dynamic mapping.  
_Here is the scenario_:

1. Initially mapped 2 fields (f1 and f2) using template. Indexed values  
("100", "200")
2. Then mapped another 2 (f3 and f4) using template. Indexed values ("300",  
"400")
3. When I execute statisticalFacet on f1 and f2 I get them correctly. But  
when I execute the same for f3 and f4 it throws an exception in the server  
and returns 0.0  
And the exception is --- Not sure why its a ClassCast Exception, especially  
it works for the fields that has been indexed initially but not with the  
ones indexed later.

Would appreciate your help/suggestion here.

[2011-10-24 16:41:59,749][DEBUG][action.search.type] [Crusader]  
[test-index-1][3], node[p\_Rh8yZYThiqcJGRPGgebA], [P], s[STARTED]: Failed to  
execute [org.elasticsearch.action.search.SearchRequest@45612e53]  
org.elasticsearch.search.query.QueryPhaseExecutionException:  
[test-index-1][3]: query[ConstantScore(_:_)],from[0],size[10]: Query Failed  
[Failed to execute main query]  
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:221)  
at  
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:234)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:134)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:204)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)  
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:637)  
Caused by: java.lang.ClassCastException:  
org.elasticsearch.index.field.data.strings.SingleValueStringFieldData cannot  
be cast to org.elasticsearch.index.field.data.NumericFieldData  
at  
org.elasticsearch.search.facet.statistical.StatisticalFacetCollector.doSetNextReader(StatisticalFacetCollector.java:72)  
at  
org.elasticsearch.search.facet.AbstractFacetCollector.setNextReader(AbstractFacetCollector.java:71)  
at  
org.elasticsearch.common.lucene.MultiCollector.setNextReader(MultiCollector.java:64)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:523)  
at  
org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:198)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:391)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:298)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:286)  
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:217)  
... 9 more

Thanks  
Gautam

---

<div class="post-metadata">

**Author:** ![Gautam\_S](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@Gautam\_S](https://discuss.elastic.co/u/Gautam_S)\
**Post date:** [October 24, 2011, 8:41pm UTC](https://discuss.elastic.co/t/statisticalfacet-does-now-work-properly-with-dynamic-mapping/5669/2 "2011-10-24T20:41:51Z")

</div>

Got the issue. Don't bother.

Thanks

On Mon, Oct 24, 2011 at 10:17 PM, Gautam Shyamantak [gautam@datarpm.com](mailto:gautam@datarpm.com)wrote:

> Hi,
> 
> Not been able make statisticalFacet work with dynamic mapping.  
> _Here is the scenario_:
> 
> 1. Initially mapped 2 fields (f1 and f2) using template. Indexed values  
> ("100", "200")
> 2. Then mapped another 2 (f3 and f4) using template. Indexed values ("300",  
> "400")
> 3. When I execute statisticalFacet on f1 and f2 I get them correctly. But  
> when I execute the same for f3 and f4 it throws an exception in the server  
> and returns 0.0  
> And the exception is --- Not sure why its a ClassCast Exception, especially  
> it works for the fields that has been indexed initially but not with the  
> ones indexed later.
> 
> Would appreciate your help/suggestion here.
> 
> [2011-10-24 16:41:59,749][DEBUG][action.search.type] [Crusader]  
> [test-index-1][3], node[p\_Rh8yZYThiqcJGRPGgebA], [P], s[STARTED]: Failed to  
> execute [org.elasticsearch.action.search.SearchRequest@45612e53]  
> org.elasticsearch.search.query.QueryPhaseExecutionException:  
> [test-index-1][3]: query[ConstantScore(_:_)],from[0],size[10]: Query Failed  
> [Failed to execute main query]  
> at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:221)  
> at  
> org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:234)  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:134)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:204)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)  
> 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:637)  
> Caused by: java.lang.ClassCastException:  
> org.elasticsearch.index.field.data.strings.SingleValueStringFieldData cannot  
> be cast to org.elasticsearch.index.field.data.NumericFieldData  
> at  
> org.elasticsearch.search.facet.statistical.StatisticalFacetCollector.doSetNextReader(StatisticalFacetCollector.java:72)  
> at  
> org.elasticsearch.search.facet.AbstractFacetCollector.setNextReader(AbstractFacetCollector.java:71)  
> at  
> org.elasticsearch.common.lucene.MultiCollector.setNextReader(MultiCollector.java:64)  
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:523)  
> at  
> org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:198)  
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:391)  
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:298)  
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:286)  
> at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:217)  
> ... 9 more
> 
> Thanks  
> Gautam

---

<div class="post-metadata">

**Author:** ![Pierre\_Durand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierre_durand/32/1895_2.png) [@Pierre\_Durand](https://discuss.elastic.co/u/Pierre_Durand)\
**Post date:** [June 12, 2012, 2:33pm UTC](https://discuss.elastic.co/t/statisticalfacet-does-now-work-properly-with-dynamic-mapping/5669/3 "2012-06-12T14:33:31Z")

</div>

How did you fix this problem?  
Thank you

On Monday, October 24, 2011 10:41:51 PM UTC+2, Gautam S wrote:

> Got the issue. Don't bother.
> 
> Thanks
> 
> On Mon, Oct 24, 2011 at 10:17 PM, Gautam Shyamantak [gautam@datarpm.com](mailto:gautam@datarpm.com)wrote:
> 
> > Hi,
> > 
> > Not been able make statisticalFacet work with dynamic mapping.  
> > _Here is the scenario_:
> > 
> > 1. Initially mapped 2 fields (f1 and f2) using template. Indexed values  
> > ("100", "200")
> > 2. Then mapped another 2 (f3 and f4) using template. Indexed values  
> > ("300", "400")
> > 3. When I execute statisticalFacet on f1 and f2 I get them correctly. But  
> > when I execute the same for f3 and f4 it throws an exception in the server  
> > and returns 0.0  
> > And the exception is --- Not sure why its a ClassCast Exception,  
> > especially it works for the fields that has been indexed initially but not  
> > with the ones indexed later.
> > 
> > Would appreciate your help/suggestion here.
> > 
> > [2011-10-24 16:41:59,749][DEBUG][action.search.type] [Crusader]  
> > [test-index-1][3], node[p\_Rh8yZYThiqcJGRPGgebA], [P], s[STARTED]: Failed to  
> > execute [org.elasticsearch.action.search.SearchRequest@45612e53]  
> > org.elasticsearch.search.query.QueryPhaseExecutionException:  
> > [test-index-1][3]: query[ConstantScore(_:_)],from[0],size[10]: Query Failed  
> > [Failed to execute main query]  
> > at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:221)  
> > at  
> > org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:234)  
> > at  
> > org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:134)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:204)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)  
> > 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:637)  
> > Caused by: java.lang.ClassCastException:  
> > org.elasticsearch.index.field.data.strings.SingleValueStringFieldData  
> > cannot be cast to org.elasticsearch.index.field.data.NumericFieldData  
> > at  
> > org.elasticsearch.search.facet.statistical.StatisticalFacetCollector.doSetNextReader(StatisticalFacetCollector.java:72)  
> > at  
> > org.elasticsearch.search.facet.AbstractFacetCollector.setNextReader(AbstractFacetCollector.java:71)  
> > at  
> > org.elasticsearch.common.lucene.MultiCollector.setNextReader(MultiCollector.java:64)  
> > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:523)  
> > at  
> > org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:198)  
> > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:391)  
> > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:298)  
> > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:286)  
> > at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:217)  
> > ... 9 more
> > 
> > Thanks  
> > Gautam

---

<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:24am UTC](https://discuss.elastic.co/t/statisticalfacet-does-now-work-properly-with-dynamic-mapping/5669/4 "2017-07-06T03:24:46Z")

</div>


