# SearchPhaseController - NullPointerException

**URL:** <https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594>\
**Category:** Elasticsearch\
**Created:** [October 13, 2011, 7:28pm UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594 "2011-10-13T19:28:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Gavarini](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sebastian\_Gavarini](https://discuss.elastic.co/u/Sebastian_Gavarini)\
**Post date:** [October 13, 2011, 7:28pm UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594/1 "2011-10-13T19:28:59Z")

</div>

Hi, I am seeing this Exception in ES 0.17.8:

org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
execute phase [query\_fetch], [reduce]  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:231)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:206)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:204)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:237)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:230)  
at  
org.elasticsearch.transport.netty.MessageChannelHandler.handleResponse(MessageChannelHandler.java:132)  
at  
org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:103)  
at  
org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
at  
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
at  
org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783)  
at  
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:302)  
at  
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)  
at  
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)  
at  
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)  
at  
org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
at  
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
at  
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)  
at  
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:274)  
at  
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:261)  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)  
at  
org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
at  
org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
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:662)  
Caused by: java.lang.NullPointerException  
at  
org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:292)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.moveToSecondPhase(TransportSearchQueryAndFetchAction.java:80)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:226)  
... 26 more

I am trying to reproduce it without luck so far, I was updating the index  
while I did the search. Anyway, the line in question is:

```
                    for (Facet facet1 :

```

queryResultProvider.queryResult().facets()) {

and I think it shouldn't throw NPE whatever I am doing wrong.

Any ideas?

Thanks,  
Sebastian.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Gavarini](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sebastian\_Gavarini](https://discuss.elastic.co/u/Sebastian_Gavarini)\
**Post date:** [October 14, 2011, 12:30am UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594/2 "2011-10-14T00:30:01Z")

</div>

Update: I still can't replicate with a "curl" command, but under controlled  
conditions I do see it all the time with the java API.

The query runs without problems as REST, the only thing I don't know how to  
specify in the REST API compared to java, is the Operation Threading, witch  
is THREAD\_PER\_SHARD, I don't know if this could be part of the problem.

What I see related to the facets iteration that SearchPhaseController is  
doing in line 292 is that I am querying 5 indices, and in one of them the  
value of the sort field is not mapped, so that index fails with:

{  
"took" : 6,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 4,  
"failed" : 1,  
"failures" : [ {  
"index" : "index-main-e1",  
"shard" : 0,  
"status" : 400,  
"reason" :  
"RemoteTransportException[[Tugun][inet[/127.0.0.1:5000]][search/phase/query+fetch]];  
nested: SearchParseException[[index-main-e1][0]: ;  
nested: SearchParseException[[index-main-e1][0]: query[(title:something^5.0  
| description:something| attrs:something^3.0)~0.1],from[0],size[10]: Parse  
Failure [No mapping found for [normalized\_price]]]; "  
} ]  
},  
"hits" : {

but all the other 4 are ok and the results are returned when in REST API and  
not in Java API. Could there be some problem when the facets are checked for  
merging and that index didn't run? any clue?

Thanks,  
Sebastian.

On Thu, Oct 13, 2011 at 4:28 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:

> Hi, I am seeing this Exception in ES 0.17.8:
> 
> org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> execute phase [query\_fetch], [reduce]  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:231)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:206)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:204)  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:237)  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:230)  
> at  
> org.elasticsearch.transport.netty.MessageChannelHandler.handleResponse(MessageChannelHandler.java:132)  
> at  
> org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:103)  
> at  
> org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> at  
> org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> at  
> org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783)  
> at  
> org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:302)  
> at  
> org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)  
> at  
> org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)  
> at  
> org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)  
> at  
> org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> at  
> org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> at  
> org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)  
> at  
> org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:274)  
> at  
> org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:261)  
> at  
> org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)  
> at  
> org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)  
> at  
> org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)  
> at  
> org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
> at  
> org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
> 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:662)  
> Caused by: java.lang.NullPointerException  
> at  
> org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:292)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.moveToSecondPhase(TransportSearchQueryAndFetchAction.java:80)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:226)  
> ... 26 more
> 
> I am trying to reproduce it without luck so far, I was updating the index  
> while I did the search. Anyway, the line in question is:
> 
> ```
> for (Facet facet1 :
> 
> ```
> 
> queryResultProvider.queryResult().facets()) {
> 
> and I think it shouldn't throw NPE whatever I am doing wrong.
> 
> Any ideas?
> 
> Thanks,  
> Sebastian.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Gavarini](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sebastian\_Gavarini](https://discuss.elastic.co/u/Sebastian_Gavarini)\
**Post date:** [October 14, 2011, 12:36am UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594/3 "2011-10-14T00:36:16Z")

</div>

Sorry for the spam, forgot to add that I can't see the exact Java query in  
my logs, because I am using:

String output = new  
String(builder.internalBuilder().buildAsBytes(XContentType.JSON));

And all the extra parameters like indices, types, threading, search type,  
timeout, (and I don't know if I am forgetting any other one) are not shown  
by that line, any ideas on how to get a REST reproducible log from the Java  
query?

Thanks,  
Sebastian.

On Thu, Oct 13, 2011 at 9:30 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:

> Update: I still can't replicate with a "curl" command, but under controlled  
> conditions I do see it all the time with the java API.
> 
> The query runs without problems as REST, the only thing I don't know how to  
> specify in the REST API compared to java, is the Operation Threading, witch  
> is THREAD\_PER\_SHARD, I don't know if this could be part of the problem.
> 
> What I see related to the facets iteration that SearchPhaseController is  
> doing in line 292 is that I am querying 5 indices, and in one of them the  
> value of the sort field is not mapped, so that index fails with:
> 
> {  
> "took" : 6,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 4,  
> "failed" : 1,  
> "failures" : [ {  
> "index" : "index-main-e1",  
> "shard" : 0,  
> "status" : 400,  
> "reason" : "RemoteTransportException[[Tugun][inet[/127.0.0.1:5000]][search/phase/query+fetch]];  
> nested: SearchParseException[[index-main-e1][0]: ;  
> nested: SearchParseException[[index-main-e1][0]: query[(title:something^5.0  
> | description:something| attrs:something^3.0)~0.1],from[0],size[10]: Parse  
> Failure [No mapping found for [normalized\_price]]]; "  
> } ]  
> },  
> "hits" : {
> 
> but all the other 4 are ok and the results are returned when in REST API  
> and not in Java API. Could there be some problem when the facets are checked  
> for merging and that index didn't run? any clue?
> 
> Thanks,  
> Sebastian.
> 
> On Thu, Oct 13, 2011 at 4:28 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:
> 
> > Hi, I am seeing this Exception in ES 0.17.8:
> > 
> > org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> > execute phase [query\_fetch], [reduce]  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:231)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:206)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:204)  
> > at  
> > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:237)  
> > at  
> > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:230)  
> > at  
> > org.elasticsearch.transport.netty.MessageChannelHandler.handleResponse(MessageChannelHandler.java:132)  
> > at  
> > org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:103)  
> > at  
> > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > at  
> > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > at  
> > org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783)  
> > at  
> > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:302)  
> > at  
> > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)  
> > at  
> > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)  
> > at  
> > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)  
> > at  
> > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > at  
> > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > at  
> > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)  
> > at  
> > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:274)  
> > at  
> > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:261)  
> > at  
> > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)  
> > at  
> > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)  
> > at  
> > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)  
> > at  
> > org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
> > at  
> > org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
> > 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:662)  
> > Caused by: java.lang.NullPointerException  
> > at  
> > org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:292)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.moveToSecondPhase(TransportSearchQueryAndFetchAction.java:80)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:226)  
> > ... 26 more
> > 
> > I am trying to reproduce it without luck so far, I was updating the index  
> > while I did the search. Anyway, the line in question is:
> > 
> > ```
> > for (Facet facet1 :
> > 
> > ```
> > 
> > queryResultProvider.queryResult().facets()) {
> > 
> > and I think it shouldn't throw NPE whatever I am doing wrong.
> > 
> > Any ideas?
> > 
> > Thanks,  
> > Sebastian.

---

<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:** [October 14, 2011, 12:33pm UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594/4 "2011-10-14T12:33:14Z")

</div>

Which version are you using? If you can create it using hte Java API, can  
you create a simple main program that starts a node, index sample data, and  
executes a search that recreates it? Thats the simplest / fastest way to fix  
it.

On Fri, Oct 14, 2011 at 2:36 AM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:

> Sorry for the spam, forgot to add that I can't see the exact Java query in  
> my logs, because I am using:
> 
> String output = new  
> String(builder.internalBuilder().buildAsBytes(XContentType.JSON));
> 
> And all the extra parameters like indices, types, threading, search type,  
> timeout, (and I don't know if I am forgetting any other one) are not shown  
> by that line, any ideas on how to get a REST reproducible log from the Java  
> query?
> 
> Thanks,  
> Sebastian.
> 
> On Thu, Oct 13, 2011 at 9:30 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:
> 
> > Update: I still can't replicate with a "curl" command, but under  
> > controlled conditions I do see it all the time with the java API.
> > 
> > The query runs without problems as REST, the only thing I don't know how  
> > to specify in the REST API compared to java, is the Operation Threading,  
> > witch is THREAD\_PER\_SHARD, I don't know if this could be part of the  
> > problem.
> > 
> > What I see related to the facets iteration that SearchPhaseController is  
> > doing in line 292 is that I am querying 5 indices, and in one of them the  
> > value of the sort field is not mapped, so that index fails with:
> > 
> > {  
> > "took" : 6,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 4,  
> > "failed" : 1,  
> > "failures" : [ {  
> > "index" : "index-main-e1",  
> > "shard" : 0,  
> > "status" : 400,  
> > "reason" : "RemoteTransportException[[Tugun][inet[/127.0.0.1:5000]][search/phase/query+fetch]];  
> > nested: SearchParseException[[index-main-e1][0]: ;  
> > nested: SearchParseException[[index-main-e1][0]: query[(title:something^5.0  
> > | description:something| attrs:something^3.0)~0.1],from[0],size[10]: Parse  
> > Failure [No mapping found for [normalized\_price]]]; "  
> > } ]  
> > },  
> > "hits" : {
> > 
> > but all the other 4 are ok and the results are returned when in REST API  
> > and not in Java API. Could there be some problem when the facets are checked  
> > for merging and that index didn't run? any clue?
> > 
> > Thanks,  
> > Sebastian.
> > 
> > On Thu, Oct 13, 2011 at 4:28 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:
> > 
> > > Hi, I am seeing this Exception in ES 0.17.8:
> > > 
> > > org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> > > execute phase [query\_fetch], [reduce]  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:231)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:206)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:204)  
> > > at  
> > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:237)  
> > > at  
> > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:230)  
> > > at  
> > > org.elasticsearch.transport.netty.MessageChannelHandler.handleResponse(MessageChannelHandler.java:132)  
> > > at  
> > > org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:103)  
> > > at  
> > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > at  
> > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > at  
> > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783)  
> > > at  
> > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:302)  
> > > at  
> > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)  
> > > at  
> > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)  
> > > at  
> > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)  
> > > at  
> > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > at  
> > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > at  
> > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)  
> > > at  
> > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:274)  
> > > at  
> > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:261)  
> > > at  
> > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)  
> > > at  
> > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)  
> > > at  
> > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)  
> > > at  
> > > org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
> > > at  
> > > org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
> > > 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:662)  
> > > Caused by: java.lang.NullPointerException  
> > > at  
> > > org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:292)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.moveToSecondPhase(TransportSearchQueryAndFetchAction.java:80)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:226)  
> > > ... 26 more
> > > 
> > > I am trying to reproduce it without luck so far, I was updating the index  
> > > while I did the search. Anyway, the line in question is:
> > > 
> > > ```
> > > for (Facet facet1 :
> > > 
> > > ```
> > > 
> > > queryResultProvider.queryResult().facets()) {
> > > 
> > > and I think it shouldn't throw NPE whatever I am doing wrong.
> > > 
> > > Any ideas?
> > > 
> > > Thanks,  
> > > Sebastian.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Gavarini](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sebastian\_Gavarini](https://discuss.elastic.co/u/Sebastian_Gavarini)\
**Post date:** [October 17, 2011, 6:48pm UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594/5 "2011-10-17T18:48:40Z")

</div>

Hi Shay,

I took a couple of days to try to replicate the problem in an isolated  
manner, previously it was possible to reproduce in our full java  
application.

The problem appears sporadically in my 2 cores PC (once in a couple of runs  
so pretty frequently anyway), so I would advice to run it a couple of times  
to make it work. It seems to be related to a couple of simultaneous  
conditions, two searches done in parallel, one search that is ok, and  
another one that of the two indices, only one contains the sort field  
requested.

In my example I create 3 indices, and run 2 searches, look at method  
"launch".

> <https://gist.github.com/sebaes/1293410>

IMPORTANT: The idea was to create in memory indices, but it isn't working, I  
don't know what am I messing in the settings part, but the solution I found  
was to delete everything in "/tmp/es/server" after each run.

Let me know if it doesn't work for you.

Thanks,  
Sebastian.

On Fri, Oct 14, 2011 at 9:33 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Which version are you using? If you can create it using hte Java API, can  
> you create a simple main program that starts a node, index sample data, and  
> executes a search that recreates it? Thats the simplest / fastest way to fix  
> it.
> 
> On Fri, Oct 14, 2011 at 2:36 AM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:
> 
> > Sorry for the spam, forgot to add that I can't see the exact Java query in  
> > my logs, because I am using:
> > 
> > String output = new  
> > String(builder.internalBuilder().buildAsBytes(XContentType.JSON));
> > 
> > And all the extra parameters like indices, types, threading, search type,  
> > timeout, (and I don't know if I am forgetting any other one) are not shown  
> > by that line, any ideas on how to get a REST reproducible log from the Java  
> > query?
> > 
> > Thanks,  
> > Sebastian.
> > 
> > On Thu, Oct 13, 2011 at 9:30 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:
> > 
> > > Update: I still can't replicate with a "curl" command, but under  
> > > controlled conditions I do see it all the time with the java API.
> > > 
> > > The query runs without problems as REST, the only thing I don't know how  
> > > to specify in the REST API compared to java, is the Operation Threading,  
> > > witch is THREAD\_PER\_SHARD, I don't know if this could be part of the  
> > > problem.
> > > 
> > > What I see related to the facets iteration that SearchPhaseController is  
> > > doing in line 292 is that I am querying 5 indices, and in one of them the  
> > > value of the sort field is not mapped, so that index fails with:
> > > 
> > > {  
> > > "took" : 6,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 4,  
> > > "failed" : 1,  
> > > "failures" : [ {  
> > > "index" : "index-main-e1",  
> > > "shard" : 0,  
> > > "status" : 400,  
> > > "reason" : "RemoteTransportException[[Tugun][inet[/127.0.0.1:5000]][search/phase/query+fetch]];  
> > > nested: SearchParseException[[index-main-e1][0]: ;  
> > > nested: SearchParseException[[index-main-e1][0]: query[(title:something^5.0  
> > > | description:something| attrs:something^3.0)~0.1],from[0],size[10]: Parse  
> > > Failure [No mapping found for [normalized\_price]]]; "  
> > > } ]  
> > > },  
> > > "hits" : {
> > > 
> > > but all the other 4 are ok and the results are returned when in REST API  
> > > and not in Java API. Could there be some problem when the facets are checked  
> > > for merging and that index didn't run? any clue?
> > > 
> > > Thanks,  
> > > Sebastian.
> > > 
> > > On Thu, Oct 13, 2011 at 4:28 PM, Sebastian Gavarini \<[sgavarini@gmail.com](mailto:sgavarini@gmail.com)
> > > 
> > > > wrote:
> > > 
> > > > Hi, I am seeing this Exception in ES 0.17.8:
> > > > 
> > > > org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> > > > execute phase [query\_fetch], [reduce]  
> > > > at  
> > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:231)  
> > > > at  
> > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:206)  
> > > > at  
> > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:204)  
> > > > at  
> > > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:237)  
> > > > at  
> > > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:230)  
> > > > at  
> > > > org.elasticsearch.transport.netty.MessageChannelHandler.handleResponse(MessageChannelHandler.java:132)  
> > > > at  
> > > > org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:103)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:302)  
> > > > at  
> > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)  
> > > > at  
> > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)  
> > > > at  
> > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:274)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:261)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)  
> > > > at  
> > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)  
> > > > at  
> > > > org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
> > > > at  
> > > > org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
> > > > 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:662)  
> > > > Caused by: java.lang.NullPointerException  
> > > > at  
> > > > org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:292)  
> > > > at  
> > > > org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.moveToSecondPhase(TransportSearchQueryAndFetchAction.java:80)  
> > > > at  
> > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:226)  
> > > > ... 26 more
> > > > 
> > > > I am trying to reproduce it without luck so far, I was updating the  
> > > > index while I did the search. Anyway, the line in question is:
> > > > 
> > > > ```
> > > > for (Facet facet1 :
> > > > 
> > > > ```
> > > > 
> > > > queryResultProvider.queryResult().facets()) {
> > > > 
> > > > and I think it shouldn't throw NPE whatever I am doing wrong.
> > > > 
> > > > Any ideas?
> > > > 
> > > > Thanks,  
> > > > Sebastian.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Gavarini](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sebastian\_Gavarini](https://discuss.elastic.co/u/Sebastian_Gavarini)\
**Post date:** [October 17, 2011, 6:55pm UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594/6 "2011-10-17T18:55:13Z")

</div>

Sorry, forgot to add, the version was stated on my first email, it's 0.17.8

On Mon, Oct 17, 2011 at 3:48 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:

> Hi Shay,
> 
> I took a couple of days to try to replicate the problem in an isolated  
> manner, previously it was possible to reproduce in our full java  
> application.
> 
> The problem appears sporadically in my 2 cores PC (once in a couple of runs  
> so pretty frequently anyway), so I would advice to run it a couple of times  
> to make it work. It seems to be related to a couple of simultaneous  
> conditions, two searches done in parallel, one search that is ok, and  
> another one that of the two indices, only one contains the sort field  
> requested.
> 
> In my example I create 3 indices, and run 2 searches, look at method  
> "launch".
> 
> [Exception case · GitHub](https://gist.github.com/1293410)
> 
> IMPORTANT: The idea was to create in memory indices, but it isn't working,  
> I don't know what am I messing in the settings part, but the solution I  
> found was to delete everything in "/tmp/es/server" after each run.
> 
> Let me know if it doesn't work for you.
> 
> Thanks,  
> Sebastian.
> 
> On Fri, Oct 14, 2011 at 9:33 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > Which version are you using? If you can create it using hte Java API, can  
> > you create a simple main program that starts a node, index sample data, and  
> > executes a search that recreates it? Thats the simplest / fastest way to fix  
> > it.
> > 
> > On Fri, Oct 14, 2011 at 2:36 AM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:
> > 
> > > Sorry for the spam, forgot to add that I can't see the exact Java query  
> > > in my logs, because I am using:
> > > 
> > > String output = new  
> > > String(builder.internalBuilder().buildAsBytes(XContentType.JSON));
> > > 
> > > And all the extra parameters like indices, types, threading, search type,  
> > > timeout, (and I don't know if I am forgetting any other one) are not shown  
> > > by that line, any ideas on how to get a REST reproducible log from the Java  
> > > query?
> > > 
> > > Thanks,  
> > > Sebastian.
> > > 
> > > On Thu, Oct 13, 2011 at 9:30 PM, Sebastian Gavarini \<[sgavarini@gmail.com](mailto:sgavarini@gmail.com)
> > > 
> > > > wrote:
> > > 
> > > > Update: I still can't replicate with a "curl" command, but under  
> > > > controlled conditions I do see it all the time with the java API.
> > > > 
> > > > The query runs without problems as REST, the only thing I don't know how  
> > > > to specify in the REST API compared to java, is the Operation Threading,  
> > > > witch is THREAD\_PER\_SHARD, I don't know if this could be part of the  
> > > > problem.
> > > > 
> > > > What I see related to the facets iteration that SearchPhaseController is  
> > > > doing in line 292 is that I am querying 5 indices, and in one of them the  
> > > > value of the sort field is not mapped, so that index fails with:
> > > > 
> > > > {  
> > > > "took" : 6,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 5,  
> > > > "successful" : 4,  
> > > > "failed" : 1,  
> > > > "failures" : [ {  
> > > > "index" : "index-main-e1",  
> > > > "shard" : 0,  
> > > > "status" : 400,  
> > > > "reason" : "RemoteTransportException[[Tugun][inet[/127.0.0.1:5000]][search/phase/query+fetch]];  
> > > > nested: SearchParseException[[index-main-e1][0]: ;  
> > > > nested: SearchParseException[[index-main-e1][0]: query[(title:something^5.0  
> > > > | description:something| attrs:something^3.0)~0.1],from[0],size[10]: Parse  
> > > > Failure [No mapping found for [normalized\_price]]]; "  
> > > > } ]  
> > > > },  
> > > > "hits" : {
> > > > 
> > > > but all the other 4 are ok and the results are returned when in REST API  
> > > > and not in Java API. Could there be some problem when the facets are checked  
> > > > for merging and that index didn't run? any clue?
> > > > 
> > > > Thanks,  
> > > > Sebastian.
> > > > 
> > > > On Thu, Oct 13, 2011 at 4:28 PM, Sebastian Gavarini \<  
> > > > [sgavarini@gmail.com](mailto:sgavarini@gmail.com)\> wrote:
> > > > 
> > > > > Hi, I am seeing this Exception in ES 0.17.8:
> > > > > 
> > > > > org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> > > > > execute phase [query\_fetch], [reduce]  
> > > > > at  
> > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:231)  
> > > > > at  
> > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:206)  
> > > > > at  
> > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:204)  
> > > > > at  
> > > > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:237)  
> > > > > at  
> > > > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:230)  
> > > > > at  
> > > > > org.elasticsearch.transport.netty.MessageChannelHandler.handleResponse(MessageChannelHandler.java:132)  
> > > > > at  
> > > > > org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:103)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:302)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:274)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:261)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
> > > > > at  
> > > > > org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
> > > > > 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:662)  
> > > > > Caused by: java.lang.NullPointerException  
> > > > > at  
> > > > > org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:292)  
> > > > > at  
> > > > > org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.moveToSecondPhase(TransportSearchQueryAndFetchAction.java:80)  
> > > > > at  
> > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:226)  
> > > > > ... 26 more
> > > > > 
> > > > > I am trying to reproduce it without luck so far, I was updating the  
> > > > > index while I did the search. Anyway, the line in question is:
> > > > > 
> > > > > ```
> > > > > for (Facet facet1 :
> > > > > 
> > > > > ```
> > > > > 
> > > > > queryResultProvider.queryResult().facets()) {
> > > > > 
> > > > > and I think it shouldn't throw NPE whatever I am doing wrong.
> > > > > 
> > > > > Any ideas?
> > > > > 
> > > > > Thanks,  
> > > > > Sebastian.

---

<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:** [October 18, 2011, 4:00am UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594/7 "2011-10-18T04:00:29Z")

</div>

Thanks for the recreation, managed to track down the problem and fix it:  
[Search: A failed search request might get overrun when trying another shard · Issue #1403 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1403).

On Mon, Oct 17, 2011 at 8:55 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:

> Sorry, forgot to add, the version was stated on my first email, it's 0.17.8
> 
> On Mon, Oct 17, 2011 at 3:48 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:
> 
> > Hi Shay,
> > 
> > I took a couple of days to try to replicate the problem in an isolated  
> > manner, previously it was possible to reproduce in our full java  
> > application.
> > 
> > The problem appears sporadically in my 2 cores PC (once in a couple of  
> > runs so pretty frequently anyway), so I would advice to run it a couple of  
> > times to make it work. It seems to be related to a couple of simultaneous  
> > conditions, two searches done in parallel, one search that is ok, and  
> > another one that of the two indices, only one contains the sort field  
> > requested.
> > 
> > In my example I create 3 indices, and run 2 searches, look at method  
> > "launch".
> > 
> > [Exception case · GitHub](https://gist.github.com/1293410)
> > 
> > IMPORTANT: The idea was to create in memory indices, but it isn't working,  
> > I don't know what am I messing in the settings part, but the solution I  
> > found was to delete everything in "/tmp/es/server" after each run.
> > 
> > Let me know if it doesn't work for you.
> > 
> > Thanks,  
> > Sebastian.
> > 
> > On Fri, Oct 14, 2011 at 9:33 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > 
> > > Which version are you using? If you can create it using hte Java API, can  
> > > you create a simple main program that starts a node, index sample data, and  
> > > executes a search that recreates it? Thats the simplest / fastest way to fix  
> > > it.
> > > 
> > > On Fri, Oct 14, 2011 at 2:36 AM, Sebastian Gavarini \<[sgavarini@gmail.com](mailto:sgavarini@gmail.com)
> > > 
> > > > wrote:
> > > 
> > > > Sorry for the spam, forgot to add that I can't see the exact Java query  
> > > > in my logs, because I am using:
> > > > 
> > > > String output = new  
> > > > String(builder.internalBuilder().buildAsBytes(XContentType.JSON));
> > > > 
> > > > And all the extra parameters like indices, types, threading, search  
> > > > type, timeout, (and I don't know if I am forgetting any other one) are not  
> > > > shown by that line, any ideas on how to get a REST reproducible log from the  
> > > > Java query?
> > > > 
> > > > Thanks,  
> > > > Sebastian.
> > > > 
> > > > On Thu, Oct 13, 2011 at 9:30 PM, Sebastian Gavarini \<  
> > > > [sgavarini@gmail.com](mailto:sgavarini@gmail.com)\> wrote:
> > > > 
> > > > > Update: I still can't replicate with a "curl" command, but under  
> > > > > controlled conditions I do see it all the time with the java API.
> > > > > 
> > > > > The query runs without problems as REST, the only thing I don't know  
> > > > > how to specify in the REST API compared to java, is the Operation Threading,  
> > > > > witch is THREAD\_PER\_SHARD, I don't know if this could be part of the  
> > > > > problem.
> > > > > 
> > > > > What I see related to the facets iteration that SearchPhaseController  
> > > > > is doing in line 292 is that I am querying 5 indices, and in one of them the  
> > > > > value of the sort field is not mapped, so that index fails with:
> > > > > 
> > > > > {  
> > > > > "took" : 6,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 5,  
> > > > > "successful" : 4,  
> > > > > "failed" : 1,  
> > > > > "failures" : [ {  
> > > > > "index" : "index-main-e1",  
> > > > > "shard" : 0,  
> > > > > "status" : 400,  
> > > > > "reason" : "RemoteTransportException[[Tugun][inet[/127.0.0.1:5000]][search/phase/query+fetch]];  
> > > > > nested: SearchParseException[[index-main-e1][0]: ;  
> > > > > nested: SearchParseException[[index-main-e1][0]: query[(title:something^5.0  
> > > > > | description:something| attrs:something^3.0)~0.1],from[0],size[10]: Parse  
> > > > > Failure [No mapping found for [normalized\_price]]]; "  
> > > > > } ]  
> > > > > },  
> > > > > "hits" : {
> > > > > 
> > > > > but all the other 4 are ok and the results are returned when in REST  
> > > > > API and not in Java API. Could there be some problem when the facets are  
> > > > > checked for merging and that index didn't run? any clue?
> > > > > 
> > > > > Thanks,  
> > > > > Sebastian.
> > > > > 
> > > > > On Thu, Oct 13, 2011 at 4:28 PM, Sebastian Gavarini \<  
> > > > > [sgavarini@gmail.com](mailto:sgavarini@gmail.com)\> wrote:
> > > > > 
> > > > > > Hi, I am seeing this Exception in ES 0.17.8:
> > > > > > 
> > > > > > org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> > > > > > execute phase [query\_fetch], [reduce]  
> > > > > > at  
> > > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:231)  
> > > > > > at  
> > > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:206)  
> > > > > > at  
> > > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:204)  
> > > > > > at  
> > > > > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:237)  
> > > > > > at  
> > > > > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:230)  
> > > > > > at  
> > > > > > org.elasticsearch.transport.netty.MessageChannelHandler.handleResponse(MessageChannelHandler.java:132)  
> > > > > > at  
> > > > > > org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:103)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:302)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:274)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:261)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
> > > > > > at  
> > > > > > org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
> > > > > > 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:662)  
> > > > > > Caused by: java.lang.NullPointerException  
> > > > > > at  
> > > > > > org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:292)  
> > > > > > at  
> > > > > > org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.moveToSecondPhase(TransportSearchQueryAndFetchAction.java:80)  
> > > > > > at  
> > > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:226)  
> > > > > > ... 26 more
> > > > > > 
> > > > > > I am trying to reproduce it without luck so far, I was updating the  
> > > > > > index while I did the search. Anyway, the line in question is:
> > > > > > 
> > > > > > ```
> > > > > > for (Facet facet1 :
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > queryResultProvider.queryResult().facets()) {
> > > > > > 
> > > > > > and I think it shouldn't throw NPE whatever I am doing wrong.
> > > > > > 
> > > > > > Any ideas?
> > > > > > 
> > > > > > Thanks,  
> > > > > > Sebastian.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Gavarini](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sebastian\_Gavarini](https://discuss.elastic.co/u/Sebastian_Gavarini)\
**Post date:** [October 18, 2011, 4:06am UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594/8 "2011-10-18T04:06:46Z")

</div>

Thanks for the quick fix!

On Tue, Oct 18, 2011 at 1:00 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Thanks for the recreation, managed to track down the problem and fix it:  
> [Search: A failed search request might get overrun when trying another shard · Issue #1403 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1403).
> 
> On Mon, Oct 17, 2011 at 8:55 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:
> 
> > Sorry, forgot to add, the version was stated on my first email, it's  
> > 0.17.8
> > 
> > On Mon, Oct 17, 2011 at 3:48 PM, Sebastian Gavarini [sgavarini@gmail.com](mailto:sgavarini@gmail.com)wrote:
> > 
> > > Hi Shay,
> > > 
> > > I took a couple of days to try to replicate the problem in an isolated  
> > > manner, previously it was possible to reproduce in our full java  
> > > application.
> > > 
> > > The problem appears sporadically in my 2 cores PC (once in a couple of  
> > > runs so pretty frequently anyway), so I would advice to run it a couple of  
> > > times to make it work. It seems to be related to a couple of simultaneous  
> > > conditions, two searches done in parallel, one search that is ok, and  
> > > another one that of the two indices, only one contains the sort field  
> > > requested.
> > > 
> > > In my example I create 3 indices, and run 2 searches, look at method  
> > > "launch".
> > > 
> > > [Exception case · GitHub](https://gist.github.com/1293410)
> > > 
> > > IMPORTANT: The idea was to create in memory indices, but it isn't  
> > > working, I don't know what am I messing in the settings part, but the  
> > > solution I found was to delete everything in "/tmp/es/server" after each  
> > > run.
> > > 
> > > Let me know if it doesn't work for you.
> > > 
> > > Thanks,  
> > > Sebastian.
> > > 
> > > On Fri, Oct 14, 2011 at 9:33 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > > 
> > > > Which version are you using? If you can create it using hte Java API,  
> > > > can you create a simple main program that starts a node, index sample data,  
> > > > and executes a search that recreates it? Thats the simplest / fastest way to  
> > > > fix it.
> > > > 
> > > > On Fri, Oct 14, 2011 at 2:36 AM, Sebastian Gavarini \<  
> > > > [sgavarini@gmail.com](mailto:sgavarini@gmail.com)\> wrote:
> > > > 
> > > > > Sorry for the spam, forgot to add that I can't see the exact Java query  
> > > > > in my logs, because I am using:
> > > > > 
> > > > > String output = new  
> > > > > String(builder.internalBuilder().buildAsBytes(XContentType.JSON));
> > > > > 
> > > > > And all the extra parameters like indices, types, threading, search  
> > > > > type, timeout, (and I don't know if I am forgetting any other one) are not  
> > > > > shown by that line, any ideas on how to get a REST reproducible log from the  
> > > > > Java query?
> > > > > 
> > > > > Thanks,  
> > > > > Sebastian.
> > > > > 
> > > > > On Thu, Oct 13, 2011 at 9:30 PM, Sebastian Gavarini \<  
> > > > > [sgavarini@gmail.com](mailto:sgavarini@gmail.com)\> wrote:
> > > > > 
> > > > > > Update: I still can't replicate with a "curl" command, but under  
> > > > > > controlled conditions I do see it all the time with the java API.
> > > > > > 
> > > > > > The query runs without problems as REST, the only thing I don't know  
> > > > > > how to specify in the REST API compared to java, is the Operation Threading,  
> > > > > > witch is THREAD\_PER\_SHARD, I don't know if this could be part of the  
> > > > > > problem.
> > > > > > 
> > > > > > What I see related to the facets iteration that SearchPhaseController  
> > > > > > is doing in line 292 is that I am querying 5 indices, and in one of them the  
> > > > > > value of the sort field is not mapped, so that index fails with:
> > > > > > 
> > > > > > {  
> > > > > > "took" : 6,  
> > > > > > "timed\_out" : false,  
> > > > > > "\_shards" : {  
> > > > > > "total" : 5,  
> > > > > > "successful" : 4,  
> > > > > > "failed" : 1,  
> > > > > > "failures" : [ {  
> > > > > > "index" : "index-main-e1",  
> > > > > > "shard" : 0,  
> > > > > > "status" : 400,  
> > > > > > "reason" :  
> > > > > > "RemoteTransportException[[Tugun][inet[/127.0.0.1:5000]][search/phase/query+fetch]];  
> > > > > > nested: SearchParseException[[index-main-e1][0]: ;  
> > > > > > nested: SearchParseException[[index-main-e1][0]: query[(title:something^5.0  
> > > > > > | description:something| attrs:something^3.0)~0.1],from[0],size[10]: Parse  
> > > > > > Failure [No mapping found for [normalized\_price]]]; "  
> > > > > > } ]  
> > > > > > },  
> > > > > > "hits" : {
> > > > > > 
> > > > > > but all the other 4 are ok and the results are returned when in REST  
> > > > > > API and not in Java API. Could there be some problem when the facets are  
> > > > > > checked for merging and that index didn't run? any clue?
> > > > > > 
> > > > > > Thanks,  
> > > > > > Sebastian.
> > > > > > 
> > > > > > On Thu, Oct 13, 2011 at 4:28 PM, Sebastian Gavarini \<  
> > > > > > [sgavarini@gmail.com](mailto:sgavarini@gmail.com)\> wrote:
> > > > > > 
> > > > > > > Hi, I am seeing this Exception in ES 0.17.8:
> > > > > > > 
> > > > > > > org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> > > > > > > execute phase [query\_fetch], [reduce]  
> > > > > > > at  
> > > > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:231)  
> > > > > > > at  
> > > > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:206)  
> > > > > > > at  
> > > > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onResult(TransportSearchTypeAction.java:204)  
> > > > > > > at  
> > > > > > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:237)  
> > > > > > > at  
> > > > > > > org.elasticsearch.search.action.SearchServiceTransportAction$5.handleResponse(SearchServiceTransportAction.java:230)  
> > > > > > > at  
> > > > > > > org.elasticsearch.transport.netty.MessageChannelHandler.handleResponse(MessageChannelHandler.java:132)  
> > > > > > > at  
> > > > > > > org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:103)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:302)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:274)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:261)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
> > > > > > > at  
> > > > > > > org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
> > > > > > > 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:662)  
> > > > > > > Caused by: java.lang.NullPointerException  
> > > > > > > at  
> > > > > > > org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:292)  
> > > > > > > at  
> > > > > > > org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.moveToSecondPhase(TransportSearchQueryAndFetchAction.java:80)  
> > > > > > > at  
> > > > > > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:226)  
> > > > > > > ... 26 more
> > > > > > > 
> > > > > > > I am trying to reproduce it without luck so far, I was updating the  
> > > > > > > index while I did the search. Anyway, the line in question is:
> > > > > > > 
> > > > > > > ```
> > > > > > > for (Facet facet1 :
> > > > > > > 
> > > > > > > ```
> > > > > > > 
> > > > > > > queryResultProvider.queryResult().facets()) {
> > > > > > > 
> > > > > > > and I think it shouldn't throw NPE whatever I am doing wrong.
> > > > > > > 
> > > > > > > Any ideas?
> > > > > > > 
> > > > > > > Thanks,  
> > > > > > > Sebastian.

---

<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:51am UTC](https://discuss.elastic.co/t/searchphasecontroller-nullpointerexception/5594/9 "2017-07-06T03:51:40Z")

</div>


