filter latest record for each user and aggregate on different field in elasticsearch


Need to filter the latest record for each user and aggregate the count on each vote type.
Still cannot able to figure out. any help pls?

{user:”sam”, vote: 20, “createdDate”: 1601285178238}

{user:”sam”, vote: 21, “createdDate”: 1601285178239}

{user:”harry”, vote: 30, “createdDate”: 1601285178238}