Inconvenient Managed Properties: when strings are numbers
Recently I wrote a blog post on how standard Managed Properties are not enough for supporting particular scenarios. For example, when building content aggregations sorted on dates or numbers you would need a custom Managed Property. The reason for that is the fact that, although there are some Refinable and Sortable Managed Properties available out of the box with SharePoint, despite the type communicated in Search Schema, they return string data which makes them useless for sorting on numbers.
Recently I discussed this issue further with fellow SharePoint MVP and Search wizard Mikael Svenson. Eventually I’ve done one last test: ignoring the data type displayed in the Search REST API result I added sorting to the query. It turns out that sorting works just as expected after all! So even though the data type returned in the Search results is string, the sorting is performed using the integer data type.
So to recap: the standard RefinableXXXX Managed Properties display the correct data type in Search Schema, they return strings in search results, but when used for sorting they work just fine.