// getting-started.asciidoc:665

[source, php]
----
$params = [
    'index' => 'bank',
    'body' => [
        'size' => 0,
        'aggs' => [
            'group_by_state' => [
                'terms' => [
                    'field' => 'state.keyword',
                ],
                'aggs' => [
                    'average_balance' => [
                        'avg' => [
                            'field' => 'balance',
                        ],
                    ],
                ],
            ],
        ],
    ],
];
$response = $client->search($params);
----
