Answer the question
In order to leave comments, you need to log in
How to do double grouping in SQL query in ElasticSearch?
The bottom line is, I want to pick up clusters of points from ES Sql with a query.
The request is like this.
SELECT quadkey, MIN(id) AS id, COUNT(id) AS count, AVG(lng) AS lng, AVG(lat) AS lat FROM spots WHERE
quadkey BETWEEN 0 AND 4398046511103 GROUP BY quadkey & 3298534883328
Answer the question
In order to leave comments, you need to log in
In short, I solved the problem like this
$topLeftLat = $_POST['topLeftLat'];
$topLefiLng = $_POST['topLeftLng'];
$bottomRightLat = $_POST['bottomRightLat'];
$bottomRightLng = $_POST['bottomRightLng'];
$zoom = $_POST['zoom'];
$params['bool']['filter'][]['bool']['must']=
[
[
"exists" => [
"field" => "location"
]
],
[
"geo_bounding_box" => [
"location" => [
"top_left" => $topLeftLat.','.$topLefiLng,
"bottom_right" => $bottomRightLat.','.$bottomRightLng
]
]
]
];
$query = ElasticObj::find();
$p = ($zoom > 10 )? 10 : 8-(6-$zoom);
$query->addAggregate('gridSplit', [
'geotile_grid' => [
'bounds' => [
"top_left" => $topLeftLat.','.$topLefiLng,
"bottom_right" => $bottomRightLat.','.$bottomRightLng
],
"field" => "location",
"precision" => $p,
"size" => 65535,
"shard_size" => 65535
],
'aggs' => [
'gridCentroid' => [
'geo_centroid' => [
'field' => 'location'
]
]
]
]);
$query->query($params);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$aggregations = $dataProvider->getAggregations();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question