from datetime import datetime


def convert_es_timestamp_to_datetime(raw):
    """ Convert the ElasticSearch timestamp to a Python Datetime.

    Args:
        raw(string): The ElasticSearch timestamp, as a string.

    Returns:
        A datetime object (or None)
    """
    converted_date = None

    if not raw:
        return converted_date

    index = raw.rfind(".")
    if index != -1:
        formatted_date = raw[0:index]
    else:
        formatted_date = raw

    converted_date = datetime.strptime(
        formatted_date,
        "%Y-%m-%dT%H:%M:%S"
    )
    return converted_date