finish query function for bulk api