Разобрался сам в итоге. Вот рабочий пример:
use Elasticsearch\ClientBuilder;
require 'vendor/autoload.php';
$client = ClientBuilder::create()->build();
$params = [
'index' => 'my_index',
'body' => [
'mappings' => [
'my_type' => [
'properties' => [
'brand' => [
'type' => 'string',
],
'raw-brand' => [
'type' => 'string',
'index' => 'not_analyzed'
],
'color' => [
'type' => 'string',
],
'raw-color' => [
'type' => 'string',
'index' => 'not_analyzed'
],
'id' => [
'type' => 'integer',
]
]
]
]
]
];
$client->indices()->create($params);
$items = [
[
'id' => 1,
'category' => 'Jackets',
'brand' => 'Tommy Hilfiger',
'color' => 'Red'
],
[
'id' => 2,
'category' => 'Jeans',
'brand' => 'Tommy Jeans',
'color' => 'Navy'
],
[
'id' => 3,
'category' => 'Shirts',
'brand' => 'Tommy Hilfiger',
'color' => 'Maroon'
],
[
'id' => 4,
'category' => 'Trousers',
'brand' => 'Tommy Jeans',
'color' => 'Grey'
],
[
'id' => 5,
'category' => 'Shirts',
'brand' => 'Tommy Hilfiger',
'color' => 'Grey'
],
[
'id' => 6,
'category' => 'Sneakers',
'brand' => 'Tommy Jeans',
'color' => 'Grey'
],
[
'id' => 7,
'category' => 'Sneakers',
'brand' => 'Tommy Jeans',
'color' => 'Grey'
]
];
foreach ($items as $item) {
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => $item['id'],
'body' => [
'brand' => $item['brand'],
'raw-brand' => strtolower(str_replace(' ', '', $item['brand'])),
'color' => $item['color'],
'raw-color' => strtolower(str_replace(' ', '', $item['color'])),
'category' => $item['category'],
'raw-category' => strtolower(str_replace(' ', '', $item['category']))
]
];
$client->index($params);
}
$params = [
'index' => 'my_index',
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ 'brand' => 'tommy' ] ],
[ 'match' => [ 'color' => 'grey' ] ]
]
]
],
'aggs' => [
'brands' => [
'terms' => [
'field' => 'raw-brand',
],
],
'colors' => [
'terms' => [
'field' => 'raw-color',
]
],
'categories' => [
'terms' => [
'field' => 'raw-category',
]
]
]
]
];
$response = $client->search($params);
echo '<pre>';
print_r($response);