title: Elasticsearch Last document of multiple term queries
body: <p>I need to get the last document of each interface, I have played around with different queries but I can get the desired result, below  is my las attempt.</p>
  <p>Can you help me to get the last document of each interface where the field throughput exist?</p>
  <p>Thanks</p>
  <pre><code>GET /interface-2021.11/_search
  {
    &quot;query&quot;: {
      &quot;bool&quot;: {
        &quot;should&quot;: [
          {
            &quot;term&quot;: {
              &quot;interface_name.keyword&quot;: {
                &quot;value&quot;: &quot;Gi0/0/2 on (EXT-01)&quot;
              }
            }
          },
          {
            &quot;term&quot;: {
              &quot;interface_name.keyword&quot;: {
                &quot;value&quot;: &quot;Gi0/0/1 on (EXT-02)&quot;
              }
            }
          },
          {
            &quot;term&quot;: {
              &quot;interface_name.keyword&quot;: {
                &quot;value&quot;: &quot;Ethernet1/61 on (DC-01)&quot;
              }
            }
          },
          {
            &quot;term&quot;: {
              &quot;interface_name.keyword&quot;: {
                &quot;value&quot;: &quot;Ethernet1/17 on (DC-02)&quot;
              }
            }
          }
        ],
        &quot;minimum_should_match&quot;: 1,
        &quot;filter&quot;: [
          {
            &quot;exists&quot;: {
              &quot;field&quot;: &quot;throughput&quot;
            }
          }
        ]
      }
    },
    &quot;aggs&quot;: {
      &quot;top_date&quot;: {
        &quot;top_hits&quot;: {
          &quot;sort&quot;: [
            {
              &quot;@timestamp&quot;: {
                &quot;order&quot;: &quot;desc&quot;
              }
            }
          ]
        }
      }
    }
  }
  </code></pre>