I'm using the Python API for arcgis and I'm trying to get information on all our items on arcgis online. However, when I use the gis.content.search() the sort_field option doesn't actually seem to sort the data no matter what I choose. I wrote a test to prove this, and sure enough when choosing to sort by numViews, an item with a lower view count comes before one with a higher view count in the array. Is is not supposed to work this way? Or did I do something wrong? My function looks like this:
I agree with you, the gis.content.search() using a sort_field (sort_order desc or asc) does not work as expected. On the API example page (scroll down to the "Searching for content in ArcGIS Online" section), it doesn’t even order it correctly.
I made a simple workaround that will order your result by the number of views as you can see in the screenshots below.
The standard search doesn't order the results:
After the workaround, the result is sorted by the number of views: