Closed
Description
When used script based sorting on an index with mora than 1 shard, I get:
{"error":"ReduceSearchPhaseException[Failed to execute phase [query], [reduce] ]; nested: ClassCastException[java.lang.String cannot be cast to org.apache.lucene.util.BytesRef]; ","status":500}
Eg:
curl -XPOST http://localhost:9200/script -d '{"settings": { "index.number_of_replicas": 0, "index.number_of_shards": 2}}'
curl -XPUT http://localhost:9200/script/test/_mapping -d '{"profile":{"dynamic":"strict","properties":{"id":{"type":"integer","index":"not_analyzed","store":"yes"},"groups_code":{"properties":{"id":{"type":"integer","index":"not_analyzed"},"date":{"type":"date","index":"not_analyzed","format":"date_time_no_millis"}}}}}}'
curl -XPUT http://localhost:9200/script/test/1 -d '{"groups_code":[{"id":47642,"date":"2010-08-12T07:54:55Z"}]}'
curl -XPUT http://localhost:9200/script/test/2 -d '{"groups_code":[{"id":47642,"date":"2010-05-04T12:10:54Z"}]}'
curl -XGET http://localhost:9200/script/test/_search -d '{"query":{"match_all":{}},"fields":"","sort":[{"_script":{"script":"if ( ! _source.groups_code.empty ) { result = ($.date in _source.groups_code if $.id == id); if ( ! result.empty ) { result[0] } else { '' } }","type":"string","reverse":true,"params":{"id":47642}}}]}'