// 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: {
    match: {
      body: "elections",
    },
  },
  aggs: {
    top_sites: {
      terms: {
        field: "domain",
        order: {
          top_hit: "desc",
        },
      },
      aggs: {
        top_tags_hits: {
          top_hits: {},
        },
        top_hit: {
          max: {
            script: {
              source: "_score",
            },
          },
        },
      },
    },
  },
});
console.log(response);
----
