def cmd_rename(old_docid, new_docid):
    """
    Arguments: <current document_id> <new document_id>

    Change the ID of a document.

    Note that the document id are also their date.
    Using an ID that is not a date may have side effects
    (the main one being the document won't be sorted correctly).

    Possible JSON replies:
        --
        {
            "status": "error", "exception": "yyy",
            "reason": "xxxx", "args": "(xxxx, )"
        }
        --
        {
            "status": "ok",
            "old_docid": "xxxx",
            "new_docid": "yyyy",
        }
    """
    dsearch = get_docsearch()
    doc = dsearch.get(old_docid)
    if doc is None:
        raise Exception(
            "Document {} not found. Cannot remove label from it".format(
                old_docid
            )
        )

    index_updater = dsearch.get_index_updater(optimize=False)

    # just clone the in-memory data, not the on-disk content
    clone = doc.clone()

    # so we can change the ID safely
    doc.docid = new_docid

    index_updater.del_doc(clone)
    index_updater.add_doc(doc)
    index_updater.commit()

    verbose("Document {} renamed into {}".format(old_docid, new_docid))
    reply({
        "old_docid": old_docid,
        "new_docid": new_docid
    })