我正在编写Elasticsearch聚合查询以查找可用的总数:
GET zap/_search
{
"aggregations": {
"Brand_Name_Count": {
"terms": {"field": "brand_name", "size" : 0}
},
"Stock_Status_Count" : {
"terms" : { "field" : "stock_status", "size" : 50}
},
"Category_Id_Count" : {
"terms" : { "field" : "category_id", "size" : 50}
}
}
}
我正在得到正确的计数.
我如何在PHP代码中编写这些类型的查询?
由于我是弹性搜索的新手,任何帮助都会有所帮助
提前致谢
解决方法:
从github采取想法.
agg(和搜索)PHP语法遵循JSON API 1:1.所以你可以把你的聚合上面的内容转换成PHP数组,如下所示:
$myQuery = []; // Your query goes here
$params = [
'index' => 'zap',
'body' => [
'aggs' => [
'Brand_Name_Count' => [
'terms' => [
'field' => 'brand_name',
'size' => 0
]
],
'Stock_Status_Count' => [
'terms' => [
'field' => 'stock_status',
'size' => 50
]
],
'Category_Id_Count' => [
'terms' => [
'field' => 'category_id',
'size' => 50
]
]
],
'query' => $myQuery
]
];
$results = $client - > search($params);