// 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",
  size: 0,
  aggs: {
    top_tags: {
      terms: {
        field: "type",
        size: 3,
      },
      aggs: {
        top_sales_hits: {
          top_hits: {
            sort: [
              {
                date: {
                  order: "desc",
                },
              },
            ],
            _source: {
              includes: ["date", "price"],
            },
            size: 1,
          },
        },
        "having.top_salary": {
          bucket_selector: {
            buckets_path: {
              tp: "top_sales_hits[_source.price]",
            },
            script: "params.tp < 180",
          },
        },
      },
    },
  },
});
console.log(response);
----
