Elasticsearch で QueryPhaseExecutionException

症状
======

Elasticsearch を使っていたら見慣れないログが出力された。

```
[2014-04-12 10:56:19,488][DEBUG][action.search.type       ] [******] [index-name][2], node[******], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@3ad22707] lastShard [true]
org.elasticsearch.search.query.QueryPhaseExecutionException: [index-name][2]: query[ConstantScore(*:*)],from[0],size[0]: Query Failed [Failed to execute main query]
        at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:121)
        at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:239)
        at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:202)
        at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)
        at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216)
        at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:203)
        at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:186)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:701)
Caused by: org.elasticsearch.ElasticSearchException: java.lang.NumberFormatException: Invalid shift value in prefixCoded bytes (is encoded value really an INT?)
        at org.elasticsearch.index.fielddata.AbstractIndexFieldData.load(AbstractIndexFieldData.java:60)
        at org.elasticsearch.index.fielddata.plain.FloatArrayIndexFieldData.load(FloatArrayIndexFieldData.java:41)
        at org.elasticsearch.search.facet.datehistogram.ValueDateHistogramFacetExecutor$Collector.setNextReader(ValueDateHistogramFacetExecutor.java:92)
        at org.elasticsearch.common.lucene.search.FilteredCollector.setNextReader(FilteredCollector.java:68)
        at org.elasticsearch.common.lucene.MultiCollector.setNextReader(MultiCollector.java:68)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:612)
        at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:167)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:309)
        at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:105)
        ... 9 more
Caused by: org.elasticsearch.common.util.concurrent.UncheckedExecutionException: java.lang.NumberFormatException: Invalid shift value in prefixCoded bytes (is encoded value really an INT?)
        at org.elasticsearch.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
        at org.elasticsearch.common.cache.LocalCache.get(LocalCache.java:3934)
        at org.elasticsearch.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4736)
        at org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache$IndexFieldCache.load(IndicesFieldDataCache.java:146)
        at org.elasticsearch.index.fielddata.AbstractIndexFieldData.load(AbstractIndexFieldData.java:53)
        ... 17 more
Caused by: java.lang.NumberFormatException: Invalid shift value in prefixCoded bytes (is encoded value really an INT?)
        at org.apache.lucene.util.NumericUtils.getPrefixCodedIntShift(NumericUtils.java:210)
        at org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder$2.accept(OrdinalsBuilder.java:439)
        at org.apache.lucene.index.FilteredTermsEnum.next(FilteredTermsEnum.java:241)
        at org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder$3.next(OrdinalsBuilder.java:466)
        at org.elasticsearch.index.fielddata.plain.FloatArrayIndexFieldData.loadDirect(FloatArrayIndexFieldData.java:84)
        at org.elasticsearch.index.fielddata.plain.FloatArrayIndexFieldData.loadDirect(FloatArrayIndexFieldData.java:41)
        at org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache$IndexFieldCache$1.call(IndicesFieldDataCache.java:152)
        at org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache$IndexFieldCache$1.call(IndicesFieldDataCache.java:146)
        at org.elasticsearch.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4739)
        at org.elasticsearch.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
        at org.elasticsearch.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
        at org.elasticsearch.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
        at org.elasticsearch.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
        ... 21 more
```



原因
========

Elasticsearch では

- 同じ index 内の
- 異なる type での
- 同じ フィールド名
 
は制限されているらしい。



対策
========

- フィールドをリネーム
- 別 index にレコードを作成する



参考
=======

- [ElasticSearch Users - Fields with same name mapped differently in different types](http://elasticsearch-users.115913.n3.nabble.com/Fields-with-same-name-mapped-differently-in-different-types-td4051423.html)
- [Failed to add StatisticalFacet on a integer type field ( NumberFormatException: Invalid shift value in prefixCoded string (is encoded value really an INT?) ) - Google グループ](https://groups.google.com/forum/#!topic/elasticsearch/wXwzY_tTBj8)