// This file is autogenerated, DO NOT EDIT
// Use `node scripts/generate-docs-examples.js` to generate the docs examples

[source, js]
----
const response = await client.search({
  index: "sales",
  query: {
    term: {
      tags: "car",
    },
  },
  aggs: {
    by_sale: {
      nested: {
        path: "comments",
      },
      aggs: {
        by_user: {
          terms: {
            field: "comments.username",
            size: 1,
          },
          aggs: {
            by_nested: {
              top_hits: {},
            },
          },
        },
      },
    },
  },
});
console.log(response);
----
