def _simplify_doc(doc):
    """
    Limit a document to just the three fields we should upload.
    """
    # Mutate a copy of the document to fill in missing fields
    doc = dict(doc)
    if 'text' not in doc:
        raise ValueError("The document {!r} has no text field".format(doc))
    return {
        'text': doc['text'],
        'metadata': doc.get('metadata', []),
        'title': doc.get('title', '')
    }