code: def geolocation_sort(field_name, argument, unit, mode=None,
                       distance_type=None):
      def inner(asc):
          locations = request.values.getlist(argument, type=str)
          field = {
              '_geo_distance': {
                  field_name: locations,
                  'order': 'asc' if asc else 'desc',
                  'unit': unit,
              }
          }
          if mode:
              field['_geo_distance']['mode'] = mode
          if distance_type:
              field['_geo_distance']['distance_type'] = distance_type
          return field
      return inner