Elasticsearch query - Most recent log for each user, for field logtype='x'

I am trying to query elasticsearch to get the most recent log for all userIDs where we only include one log per user with field logtype='x'

if logtype='x' then get 1 log per userID where the date of this log is the most recent for each userID

How can I create this query?