title: Elastic search query nested object
body: <p>I am new to elastic search queries and trying to find a solution for the following scenario (see a simplified example of ES entry below).</p>
  <p>Query users where the latest purchase (of any item) lies within a certain date range (let's say between 2022-07-20 and 2022-07-30).</p>
  <p>If the lastest purchase does not lie within the specified range, then the user is not considered.</p>
  <p>Any help is appreciated. Thanks!</p>
  <p>Important: This is with ES version 6.8</p>
  <pre><code>{
  &quot;userId&quot;: &quot;xyz&quot;,
  &quot;purchases&quot;: {
    &quot;item1&quot;: [{
        &quot;timestamp&quot;: &quot;2022-07-28T09:38:52.069Z&quot;,
      }, {
        &quot;timestamp&quot;: &quot;2022-07-30T09:38:52.069Z&quot;,
      }],
    &quot;item2&quot;: [{
      &quot;timestamp&quot;: &quot;2022-07-15T15:12:20.892Z&quot;,
      }]
   }
  },
  </code></pre>