Skip to content

Commit ac049ea

Browse files
committed
Added integration test for search_mvt using vnd.mapbox-vector-tile
1 parent 995f6d4 commit ac049ea

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

tests/Elasticsearch/Tests/ClientIntegrationTest.php

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private function getClient(): Client
6060
->setLogger($this->logger);
6161

6262
if (getenv('TEST_SUITE') === 'platinum') {
63-
$client->setSSLVerification(__DIR__ . '/../../../.ci/certs/ca.crt');
63+
$client->setSSLVerification(false);
6464
}
6565
return $client->build();
6666
}
@@ -153,6 +153,98 @@ public function testIndexCannotBeArrayOfNullsForDelete()
153153
);
154154
}
155155

156+
/**
157+
* @see https://github.com/elastic/elasticsearch/blob/master/rest-api-spec/src/main/resources/rest-api-spec/api/search_mvt.json
158+
*/
159+
public function testSupportMapBoxVectorTiles()
160+
{
161+
$client = $this->getClient();
162+
163+
if (Utility::getVersion($client) < '7.15') {
164+
$this->markTestSkipped(sprintf(
165+
"The %s test requires Elasticsearch 7.15+",
166+
__FUNCTION__
167+
));
168+
}
169+
170+
// Create a museums index with a custom mappings
171+
$client->indices()->create([
172+
'index' => 'museums',
173+
'body' => [
174+
"mappings" => [
175+
"properties" => [
176+
"location" => ["type" => "geo_point"],
177+
"name" => ["type" => "keyword"],
178+
"price" => ["type" => "long"],
179+
"included" => ["type" => "boolean"]
180+
]
181+
]
182+
]
183+
]);
184+
185+
// Bulk some documents
186+
$body = [
187+
[ "index" => [ "_id" => "1" ]],
188+
[ "location" => "52.374081,4.912350", "name" => "NEMO Science Museum", "price" => 1750, "included" => true ],
189+
[ "index" => [ "_id" => "2" ]],
190+
[ "location" => "52.369219,4.901618", "name" => "Museum Het Rembrandthuis", "price" => 1500, "included" => false ],
191+
[ "index" => [ "_id" => "3" ]],
192+
[ "location" => "52.371667,4.914722", "name" => "Nederlands Scheepvaartmuseum", "price" => 1650, "included" => true ],
193+
[ "index" => [ "_id" => "4" ]],
194+
[ "location" => "52.371667,4.914722", "name" => "Amsterdam Centre for Architecture", "price" => 0, "included" => true ]
195+
];
196+
$client->bulk([
197+
'index' => 'museums',
198+
'refresh' => true,
199+
'body' => $body
200+
]);
201+
202+
$body = [
203+
"grid_precision" => 2,
204+
"fields" => ["name", "price"],
205+
"query" => [
206+
"term" => [
207+
"included" => true
208+
]
209+
],
210+
"aggs" => [
211+
"min_price" => [
212+
"min" => [
213+
"field" => "price"
214+
]
215+
],
216+
"max_price" => [
217+
"max" => [
218+
"field" => "price"
219+
]
220+
],
221+
"avg_price" => [
222+
"avg" => [
223+
"field" => "price"
224+
]
225+
]
226+
]
227+
];
228+
229+
// Searches a vector tile for geospatial values. Returns results as a binary Mapbox vector tile.
230+
$response = $client->searchMvt([
231+
'index' => 'museums',
232+
'field' => 'location',
233+
'zoom' => 13,
234+
'x' => 4207,
235+
'y' => 2692,
236+
'body' => $body
237+
]);
238+
239+
// Remove the index museums
240+
$client->indices()->delete([
241+
'index' => 'museums'
242+
]);
243+
244+
$this->assertIsString($response);
245+
$this->assertStringContainsString('NEMO Science Museum', $response);
246+
}
247+
156248
private function getLevelOutput(string $level, array $output): string
157249
{
158250
foreach ($output as $out) {

tests/Elasticsearch/Tests/Utility.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static function removeYamlXPackUsers(Client $client): void
8787
]);
8888
}
8989

90-
private static function getVersion(Client $client): string
90+
public static function getVersion(Client $client): string
9191
{
9292
if (!isset(self::$version)) {
9393
$result = $client->info();

0 commit comments

Comments
 (0)