Skip to content

Instantly share code, notes, and snippets.

@brianwhigham
Created June 22, 2016 03:29
Show Gist options
  • Save brianwhigham/bc3f7e8e6d252e8bbfaf1d6545a32ebb to your computer and use it in GitHub Desktop.
Save brianwhigham/bc3f7e8e6d252e8bbfaf1d6545a32ebb to your computer and use it in GitHub Desktop.
quick test of AWS elasticsearch with PHP
<?php
require 'vendor/autoload.php';
$hosts = [
'https://yourhostname.us-east-1.es.amazonaws.com:443'
];
$client = Elasticsearch\ClientBuilder::create() // Instantiate a new ClientBuilder
->setHosts($hosts) // Set the hosts
->build();
$params = [
'index' => 'brianwhigham_test_index',
'body' => [
'settings' => [
'number_of_shards' => 2,
'number_of_replicas' => 0
]
]
];
$response = $client->indices()->create($params);
print_r($response);
?>
@brianwhigham
Copy link
Author

I came up with this test, thanks to the ES docs, after I ran into this error trying to run a php artisan command:

ERROR: exception 'Elasticsearch\Common\Exceptions\NoNodesAvailableException' with message 'No alive nodes found in your cluster'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment