require_once __DIR__ . "/vendor/autoload.php";
use Elasticsearch\ClientBuilder;
$hosts = [[
'host' => '今回はGCPで作った.us-west1.gcp.cloud.es.io',
'port' => '9243',
'scheme' => 'https',
'user' => 'elastic',
'pass' => 'elastic cloudで作成時もしくはSecurityから再発行'
]];
$client = ClientBuilder::create()->setHosts( $hosts )->build();
$params = [
'index' => 'test_index'
];
$response = $client->indices()->create( $params );
var_dump( $response );
$php elasticphp.php
array(3) {
["acknowledged"]=>
bool(true)
["shards_acknowledged"]=>
bool(true)
["index"]=>
string(14) "test_index"
}
ブラウザからアクセス
$https://****.us-west1.gcp.cloud.es.io:9243/test_index
{
"test_index": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"creation_date": "1539144639943",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "emZtlTPUsssexa-hgfIr7w",
"version": {
"created": "6040299"
},
"provided_name": "test_index"
}
}
}
}