# Can't search with sort query

**URL:** <https://discuss.elastic.co/t/cant-search-with-sort-query/15845>\
**Category:** Elasticsearch\
**Created:** [February 17, 2014, 11:28am UTC](https://discuss.elastic.co/t/cant-search-with-sort-query/15845 "2014-02-17T11:28:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![porin\_poporin](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@porin\_poporin](https://discuss.elastic.co/u/porin_poporin)\
**Post date:** [February 17, 2014, 11:28am UTC](https://discuss.elastic.co/t/cant-search-with-sort-query/15845/1 "2014-02-17T11:28:47Z")

</div>

Hello,

We updated Elasticsearch from V0.19 to V1.0 this time.  
We used V0.19 data directory when we updated.

Throwing request of search with designation of sort after the update , 500  
error is returned.  
This error's reason is NullPointerException.

Is this problem bug ? or We are doing something wrong?

We would like to know reason of this problem.

Thank you for any help,  
-shouhei

■curl example

curl "[http://localhost:9200/u0\_sc-vsa/EntityType/\_search](http://localhost:9200/u0_sc-vsa/EntityType/_search)" -d '  
{  
"sort": [  
{  
"s.Name.untouched": {  
"order": "asc",  
"ignore\_unmapped": true  
}  
}  
],  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"c": "Y0SYndNaR7ujvhyS92nDag"  
}  
},  
{  
"term": {  
"b": "yOQ16mcGSr-59RgK4AmyBA"  
}  
},  
{  
"term": {  
"n": "abxoR9sbRtmf5jM8BdPuwA"  
}  
}  
]  
}  
},  
"filter": {  
},  
"size": 25,  
"version": true  
}  
' -k -i -s

HTTP/1.1 500 Internal Server Error  
Content-Type: application/json; charset=UTF-8  
Content-Length: 6310

{"error":"SearchPhaseExecutionException[Failed to execute phase [query],  
all shards failed; shardFailures  
{[jBhjWEptRC2rshVakpEpFg][u0\_sc-vsa][1]:  
RemoteTransportException[[pcs-perf-es112][inet[/172.20.35.13:9300  
]][search/phase/query]]; nested:  
QueryPhaseExecutionException[[u0\_sc-vsa][1]: query[filtered(+c:Y0SYndNaR7  
ujvhyS92nDag +b:yOQ16mcGSr-59RgK4AmyBA  
+n:abxoR9sbRtmf5jM8BdPuwA)-\>cache(\_type:EntityType)],from[0],size[2  
5],sort[\<custom:"s.Name.untouched":  
org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldCompa  
ratorSource@5e2036ee\>]: Query Failed [Failed to execute main query]];  
nested: ElasticsearchException[java.  
lang.NullPointerException]; nested:  
UncheckedExecutionException[java.lang.NullPointerException]; nested: N  
ullPointerException; }{[jBhjWEptRC2rshVakpEpFg][u0\_sc-vsa][2]:  
RemoteTransportException[[pcs-perf-es112][i net[/172.20.35.13:9300]][search/phase/query]]; nested:  
QueryPhaseExecutionException[[u0\_sc-vsa][2]: query[  
filtered(+c:Y0SYndNaR7ujvhyS92nDag +b:yOQ16mcGSr-59RgK4AmyBA  
+n:abxoR9sbRtmf5jM8BdPuwA)-\>cache(\_type:Entit  
yType)],from[0],size[25],sort[\<custom:"s.Name.untouched":  
org.elasticsearch.index.fielddata.fieldcompara  
tor.BytesRefFieldComparatorSource@7cc504da\>]: Query Failed [Failed to  
execute main query]]; nested: Elasti  
csearchException[java.lang.NullPointerException]; nested:  
UncheckedExecutionException[java.lang.NullPointe  
rException]; nested: NullPointerException;  
}{[ZVpRipO-TNS79hj4Cq6JdQ][u0\_sc-vsa][0]: QueryPhaseExecutionEx  
ception[[u0\_sc-vsa][0]: query[filtered(+c:Y0SYndNaR7ujvhyS92nDag  
+b:yOQ16mcGSr-59RgK4AmyBA +n:abxoR9sbRtmf  
5jM8BdPuwA)-\>cache(\_type:EntityType)],from[0],size[25],sort[\<custom:"s.Name.untouched":  
org.elasticsearc  
h.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource@665e6c29\>]:  
Query Failed [Failed to execut  
e main query]]; nested:  
ElasticsearchException[java.lang.NullPointerException]; nested:  
UncheckedExecution  
Exception[java.lang.NullPointerException]; nested: NullPointerException;  
}{[jBhjWEptRC2rshVakpEpFg][u0\_sc- vsa][9]:  
RemoteTransportException[[pcs-perf-es112][inet[/172.20.35.13:9300]][search/phase/query]];  
nested:  
QueryPhaseExecutionException[[u0\_sc-vsa][9]:  
query[filtered(+c:Y0SYndNaR7ujvhyS92nDag +b:yOQ16mcGSr-59RgK  
4AmyBA  
+n:abxoR9sbRtmf5jM8BdPuwA)-\>cache(\_type:EntityType)],from[0],size[25],sort[\<custom:"s.Name.untouc  
hed":  
org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource@4a23326d\>]:  
Query  
Failed [Failed to execute main query]]; nested:  
ElasticsearchException[java.lang.NullPointerException]; n  
ested: UncheckedExecutionException[java.lang.NullPointerException];  
nested: NullPointerException; }{[jBhj  
WEptRC2rshVakpEpFg][u0\_sc-vsa][7]:  
RemoteTransportException[[pcs-perf-es112][inet[/172.20.35.13:9300]][se  
arch/phase/query]]; nested: QueryPhaseExecutionException[[u0\_sc-vsa][7]:  
query[filtered(+c:Y0SYndNaR7ujvh  
yS92nDag +b:yOQ16mcGSr-59RgK4AmyBA  
+n:abxoR9sbRtmf5jM8BdPuwA)-\>cache(\_type:EntityType)],from[0],size[25],  
sort[\<custom:"s.Name.untouched":  
org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldCompara  
torSource@3483aac1\>]: Query Failed [Failed to execute main query]];  
nested: ElasticsearchException[java.l  
ang.NullPointerException]; nested:  
UncheckedExecutionException[java.lang.NullPointerException]; nested: N  
ullPointerException; }{[jBhjWEptRC2rshVakpEpFg][u0\_sc-vsa][8]:  
RemoteTransportException[[pcs-perf-es112][  
inet[/172.20.35.13:9300]][search/phase/query]]; nested:  
QueryPhaseExecutionException[[u0\_sc-vsa][8]: quer  
y[filtered(+c:Y0SYndNaR7ujvhyS92nDag +b:yOQ16mcGSr-59RgK4AmyBA  
+n:abxoR9sbRtmf5jM8BdPuwA)-\>cache(\_type:En  
tityType)],from[0],size[25],sort[\<custom:"s.Name.untouched":  
org.elasticsearch.index.fielddata.fieldcom  
parator.BytesRefFieldComparatorSource@6e4bc352\>]: Query Failed [Failed to  
execute main query]]; nested: E  
lasticsearchException[java.lang.NullPointerException]; nested:  
UncheckedExecutionException[java.lang.Null  
PointerException]; nested: NullPointerException;  
}{[jBhjWEptRC2rshVakpEpFg][u0\_sc-vsa][5]: RemoteTranspor  
tException[[pcs-perf-es112][inet[/172.20.35.13:9300]][search/phase/query]];  
nested: QueryPhaseExecutionEx  
ception[[u0\_sc-vsa][5]: query[filtered(+c:Y0SYndNaR7ujvhyS92nDag  
+b:yOQ16mcGSr-59RgK4AmyBA +n:abxoR9sbRtm  
f5jM8BdPuwA)-\>cache(\_type:EntityType)],from[0],size[25],sort[\<custom:"s.Name.untouched":  
org.elasticsea  
rch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource@36f2b3aa\>]:  
Query Failed [Failed to exe  
cute main query]]; nested:  
ElasticsearchException[java.lang.NullPointerException]; nested:  
UncheckedExecu  
tionException[java.lang.NullPointerException]; nested:  
NullPointerException; }{[ZVpRipO-TNS79hj4Cq6JdQ][u 0\_sc-vsa][6]: QueryPhaseExecutionException[[u0\_sc-vsa][6]:  
query[filtered(+c:Y0SYndNaR7ujvhyS92nDag +b:yO  
Q16mcGSr-59RgK4AmyBA  
+n:abxoR9sbRtmf5jM8BdPuwA)-\>cache(\_type:EntityType)],from[0],size[25],sort[\<custom:  
"s.Name.untouched":  
org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource@1088  
d932\>]: Query Failed [Failed to execute main query]]; nested:  
ElasticsearchException[java.lang.NullPointe  
rException]; nested:  
UncheckedExecutionException[java.lang.NullPointerException]; nested:  
NullPointerExce  
ption; }{[ZVpRipO-TNS79hj4Cq6JdQ][u0\_sc-vsa][3]:  
QueryPhaseExecutionException[[u0\_sc-vsa][3]: query[filte  
red(+c:Y0SYndNaR7ujvhyS92nDag +b:yOQ16mcGSr-59RgK4AmyBA  
+n:abxoR9sbRtmf5jM8BdPuwA)-\>cache(\_type:EntityTyp  
e)],from[0],size[25],sort[\<custom:"s.Name.untouched":  
org.elasticsearch.index.fielddata.fieldcomparator  
.BytesRefFieldComparatorSource@4a45312f\>]: Query Failed [Failed to execute  
main query]]; nested: Elastics  
earchException[java.lang.NullPointerException]; nested:  
UncheckedExecutionException[java.lang.NullPointer  
Exception]; nested: NullPointerException;  
}{[ZVpRipO-TNS79hj4Cq6JdQ][u0\_sc-vsa][4]: QueryPhaseExecutionEx  
ception[[u0\_sc-vsa][4]: query[filtered(+c:Y0SYndNaR7ujvhyS92nDag  
+b:yOQ16mcGSr-59RgK4AmyBA +n:abxoR9sbRtm  
f5jM8BdPuwA)-\>cache(\_type:EntityType)],from[0],size[25],sort[\<custom:"s.Name.untouched":  
org.elasticsea  
rch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource@417a3e18\>]:  
Query Failed [Failed to exe  
cute main query]]; nested:  
ElasticsearchException[java.lang.NullPointerException]; nested:  
UncheckedExecu  
tionException[java.lang.NullPointerException]; nested:  
NullPointerException; }]","status":500}

■Log of elasticserch

[2014-02-07 15:26:58,072][DEBUG][action.search.type] [XXXX] [u0\_sc- vsa][2], node[jBhjWEp  
tRC2rshVakpEpFg], [P], s[STARTED]: Failed to execute [org.elasticsearch.  
action.search.SearchRequest@12bda05a]  
org.elasticsearch.transport.RemoteTransportException: [pcs-perf-es112][inet  
[/172.20.35.13:9300]][search/phase/query]  
Caused by: org.elasticsearch.search.query.QueryPhaseExecutionException: [  
u0\_sc-vsa][2]: query[ConstantSc  
ore(cache(\_type:EntityType))],from[0],size[1],sort[\<custom:  
"s.Name.untouched": org.elasticsearch.index.f  
ielddata.fieldcomparator.BytesRefFieldComparatorSource@7f9b98a7\>]: Query  
Failed [Failed to execute main query]  
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java  
:126)  
at org.elasticsearch.search.SearchService.executeQueryPhase(  
SearchService.java:244)  
at org.elasticsearch.search.action.  
SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(  
SearchServiceTransportAction.java:623)  
at org.elasticsearch.search.action.  
SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(  
SearchServiceTransportAction.java:612)  
at org.elasticsearch.transport.netty.  
MessageChannelHandler$RequestHandler.run(MessageChannelHandler.java:270)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(  
ThreadPoolExecutor.java:1110)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(  
ThreadPoolExecutor.java:603)  
at java.lang.Thread.run(Thread.java:722)  
Caused by: org.elasticsearch.ElasticsearchException: java.lang.  
NullPointerException  
at org.elasticsearch.index.fielddata.AbstractIndexFieldData.load(  
AbstractIndexFieldData.java:75)  
at org.elasticsearch.index.fielddata.plain.  
AbstractBytesIndexFieldData.load(AbstractBytesIndexFieldData.java:41)  
at org.elasticsearch.index.fielddata.fieldcomparator.  
BytesRefOrdValComparator.setNextReader(BytesRefOrdValComparator.java:274)  
at org.elasticsearch.index.fielddata.fieldcomparator.  
BytesRefOrdValComparator$PerSegmentComparator.setNextReader(  
BytesRefOrdValComparator.java:157)  
at org.apache.lucene.search.  
TopFieldCollector$OneComparatorNonScoringCollector.setNextReader(  
TopFieldCollector.java:97)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:  
612)  
at org.elasticsearch.search.internal.ContextIndexSearcher.search(  
ContextIndexSearcher.java:173)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:  
581)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:  
533)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:  
510)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:  
345)  
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java  
:115)  
... 7 more  
Caused by: org.elasticsearch.common.util.concurrent.  
UncheckedExecutionException: java.lang.NullPointerException  
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:135)  
at org.elasticsearch.index.fielddata.AbstractIndexFieldData.load(  
AbstractIndexFieldData.java:69)  
... 18 more  
Caused by: java.lang.NullPointerException

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/bba1f709-c24a-4606-adeb-da11d9b6107f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bba1f709-c24a-4606-adeb-da11d9b6107f%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 18, 2014, 3:34pm UTC](https://discuss.elastic.co/t/cant-search-with-sort-query/15845/2 "2014-02-18T15:34:57Z")

</div>

Can you try this:

1. Backup your data dir

2. Run an optimize on your index (curl -XPOST '[http://localhost:9200/u0\_sc-vsa/\_optimize?max\_num\_segments=1](http://localhost:9200/u0_sc-vsa/_optimize?max_num_segments=1)')  
and wait until it is completed

3. Run your above query again

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/72ff3de4-0f71-4b40-b6da-acfa5fc96a6e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/72ff3de4-0f71-4b40-b6da-acfa5fc96a6e%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![porin\_poporin](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@porin\_poporin](https://discuss.elastic.co/u/porin_poporin)\
**Post date:** [February 19, 2014, 3:07am UTC](https://discuss.elastic.co/t/cant-search-with-sort-query/15845/3 "2014-02-19T03:07:07Z")

</div>

I tried and succeeded.  
The problem was solved.

thanks

2014年2月19日水曜日 0時34分57秒 UTC+9 Binh Ly:

> Can you try this:
> 
> 1. Backup your data dir
> 
> 2. Run an optimize on your index (curl -XPOST '  
> [http://localhost:9200/u0\_sc-vsa/\_optimize?max\_num\_segments=1](http://localhost:9200/u0_sc-vsa/_optimize?max_num_segments=1)') and wait  
> until it is completed
> 
> 3. Run your above query again

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5397d6ce-8269-41e6-823d-0d2c6dacf9e0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5397d6ce-8269-41e6-823d-0d2c6dacf9e0%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:49am UTC](https://discuss.elastic.co/t/cant-search-with-sort-query/15845/4 "2017-07-06T01:49:13Z")

</div>


