Skip to content

OpenSearch

OpenSearchContainer configures single-node mode and waits for startup logs.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php

declare(strict_types=1);

use Testcontainers\Modules\OpenSearchContainer;

$container = (new OpenSearchContainer())
    ->withDisabledSecurityPlugin()
    ->start();

try {
    $ch = curl_init();
    curl_setopt(
        $ch,
        CURLOPT_URL,
        sprintf('http://%s:%d', $container->getHost(), $container->getFirstMappedPort())
    );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = (string) curl_exec($ch);
    $data = json_decode($response, true, 512, JSON_THROW_ON_ERROR);

    echo (string) $data['cluster_name'];
} finally {
    $container->stop();
}