# What is the correct way to convert SearchHit.getSortValues/SortValues object to String

**URL:** <https://discuss.elastic.co/t/what-is-the-correct-way-to-convert-searchhit-getsortvalues-sortvalues-object-to-string/18671>\
**Category:** Elasticsearch\
**Created:** [July 15, 2014, 8:04am UTC](https://discuss.elastic.co/t/what-is-the-correct-way-to-convert-searchhit-getsortvalues-sortvalues-object-to-string/18671 "2014-07-15T08:04:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![navneet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/navneet/32/44881_2.png) [@navneet](https://discuss.elastic.co/u/navneet)\
**Post date:** [July 15, 2014, 8:04am UTC](https://discuss.elastic.co/t/what-is-the-correct-way-to-convert-searchhit-getsortvalues-sortvalues-object-to-string/18671/1 "2014-07-15T08:04:15Z")

</div>

Following code returns garbage for some values:

for (SearchHit result : output) {  
for (Object value : result.getSortValues()) { // result.getSortValues() returns object array  
System.out.println(value.toString());  
}  
}

---

<div class="post-metadata">

**Author:** ![navneet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/navneet/32/44881_2.png) [@navneet](https://discuss.elastic.co/u/navneet)\
**Post date:** [July 15, 2014, 7:17pm UTC](https://discuss.elastic.co/t/what-is-the-correct-way-to-convert-searchhit-getsortvalues-sortvalues-object-to-string/18671/2 "2014-07-15T19:17:24Z")

</div>

Has anyone used getSortValues()/ SortValues() Java APIs before ? Return type of this API is an object array and converting these objects to string doesn't always work.

Take this use case for example - If you have applied "filtered" sorting in your query and someone of the results don't satisfy the filter criteria, the value of sroted values should be null. Instead of null, getSortValues()/ SortValues() API is returning some junk value.

Also, if I check the "type" of object returned by this API, it is of type - org.elasticsearch.common.text.StringAndBytesText.

My question is, why this API returns object array and not String array ?

---

<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:15am UTC](https://discuss.elastic.co/t/what-is-the-correct-way-to-convert-searchhit-getsortvalues-sortvalues-object-to-string/18671/3 "2017-07-06T01:15:38Z")

</div>


