# Faceting search error

**URL:** <https://discuss.elastic.co/t/faceting-search-error/6976>\
**Category:** Elasticsearch\
**Created:** [March 13, 2012, 1:46pm UTC](https://discuss.elastic.co/t/faceting-search-error/6976 "2012-03-13T13:46:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christos\_Trochalakis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christos_trochalakis/32/2926_2.png) [@Christos\_Trochalakis](https://discuss.elastic.co/u/Christos_Trochalakis)\
**Post date:** [March 13, 2012, 1:46pm UTC](https://discuss.elastic.co/t/faceting-search-error/6976/1 "2012-03-13T13:46:24Z")

</div>

I am getting a weird exception[0] when doing a faceted search on an index  
alias. I couldn't come up with a script that reproduces this behaviour.  
This should be a cache invalidation issue because clearing the cache  
fixes the problem and everything works as expected, perhaps inserting a  
document on an aliased index (with a routing value) doesn't correctly  
expire caches.

The flow is something like this:

- do the query with zero matching docs
- add a doc
- redoing the query fails with the specified error
- empty caches
- query works

gist: [https://gist.github.com/d2a223467c9e266b0ce0](https://gist.github.com/d2a223467c9e266b0ce0)

[0] ClassCastException  
[org.elasticsearch.index.field.data.strings.SingleValueStringFieldData  
cannot be cast to  
org.elasticsearch.index.field.data.longs.LongFieldData]

---

<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:** [March 14, 2012, 12:09pm UTC](https://discuss.elastic.co/t/faceting-search-error/6976/2 "2012-03-14T12:09:15Z")

</div>

Is there a chance that you did the query against an index that has no document with the mentioned field (thus no mapping)? In this case, the type of the field will be guessed to be "string" (we need to do that before we execute the query), and then, when you index a document with a numeric type, you will get this failure (and clear cache will fix it).

On Tuesday, March 13, 2012 at 3:46 PM, Christos Trochalakis wrote:

> I am getting a weird exception[0] when doing a faceted search on an index  
> alias. I couldn't come up with a script that reproduces this behaviour.  
> This should be a cache invalidation issue because clearing the cache  
> fixes the problem and everything works as expected, perhaps inserting a  
> document on an aliased index (with a routing value) doesn't correctly  
> expire caches.
> 
> The flow is something like this:
> 
> - do the query with zero matching docs
> - add a doc
> - redoing the query fails with the specified error
> - empty caches
> - query works
> 
> gist: [elastic faceting issue · GitHub](https://gist.github.com/d2a223467c9e266b0ce0)
> 
> [0] ClassCastException  
> [org.elasticsearch.index.field.data.strings.SingleValueStringFieldData  
> cannot be cast to  
> org.elasticsearch.index.field.data.longs.LongFieldData]

---

<div class="post-metadata">

**Author:** ![Christos\_Trochalakis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christos_trochalakis/32/2926_2.png) [@Christos\_Trochalakis](https://discuss.elastic.co/u/Christos_Trochalakis)\
**Post date:** [March 15, 2012, 10:59am UTC](https://discuss.elastic.co/t/faceting-search-error/6976/3 "2012-03-15T10:59:50Z")

</div>

On Wed, Mar 14, 2012 at 02:09:15PM +0200, Shay Banon wrote:

> On Tuesday, March 13, 2012 at 3:46 PM, Christos Trochalakis wrote:
> 
> > I am getting a weird exception[0] when doing a faceted search on an index  
> > alias. I couldn't come up with a script that reproduces this behaviour.  
> > This should be a cache invalidation issue because clearing the cache  
> > fixes the problem and everything works as expected, perhaps inserting a  
> > document on an aliased index (with a routing value) doesn't correctly  
> > expire caches.
> > 
> > The flow is something like this:
> > 
> > - do the query with zero matching docs
> > - add a doc
> > - redoing the query fails with the specified error
> > - empty caches
> > - query works
> > 
> > gist: [elastic faceting issue · GitHub](https://gist.github.com/d2a223467c9e266b0ce0)
> > 
> > [0] ClassCastException  
> > [org.elasticsearch.index.field.data.strings.SingleValueStringFieldData  
> > cannot be cast to  
> > org.elasticsearch.index.field.data.longs.LongFieldData]
> 
> Is there a chance that you did the query against an index that has no document with the mentioned field (thus no mapping)? In this case, the type of the field will be guessed to be "string" (we need to do that before we execute the query), and then, when you index a document with a numeric type, you will get this failure (and clear cache will fix it).

Yes, this is exactly the case. I just created a bug report

> <https://github.com/elastic/elasticsearch/issues/1785>
>
> I am opening a bug report for the issue described here:
> 
> http://groups.google.co…m/group/elasticsearch/browse\_thread/thread/f666209e0095f6e1/cba28b4a143baf15

---

<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:36am UTC](https://discuss.elastic.co/t/faceting-search-error/6976/4 "2017-07-06T03:36:01Z")

</div>

Closed on July 6, 2017, 3:36am UTC


