title: Elasticsearch query - Most recent log for each user, for field logtype='x'
body: <p>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'</p>
  <p>if logtype='x' then get 1 log per userID where the date of this log is the most recent for each userID</p>
  <p>Example log:{&quot;logtype&quot;=&quot;x&quot;, &quot;number&quot;:232423, &quot;userID&quot;:123, &quot;time&quot;:&quot;2021-02-03T20:25:44.603045+05:30&quot;}</p>
  <p>How can I create this query?</p>