def exists(es, index, referenceNumber):
    """Checks if a document exists within an elasticsearch index
    Returns boolean"""
    if '.json' in referenceNumber:
        raise ValueError(f'{referenceNumber} is wrong format: contains ".json"')

    result = es.exists(index, doc_type='_doc', id=referenceNumber)
    return result