I’m not sure I understand what you are trying to achieve, could you perhaps try to explain it in a different way?
In generel you have a high level of freedom in the map’ing function for the view to build the view for the needs you have. The main limitation is that you can not call anything out site the map’ing function. In your case this means that you should be able to retrieve the “documentid” from the document it self.
The view will always return json.