Skip to content

Instantly share code, notes, and snippets.

@phillro
Created August 15, 2011 17:23
Show Gist options
  • Save phillro/1147250 to your computer and use it in GitHub Desktop.
Save phillro/1147250 to your computer and use it in GitHub Desktop.
Elastica search example
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/Elastica/lib'));
function elasticsearch_autoload($class) {
$file = str_replace('_', '/', $class) . '.php';
require_once $file;
}
spl_autoload_register('elasticsearch_autoload');
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
$config = array(
'host' => 'esh01.elasticsearchhq.com',
'port' => '80',
);
$client = new Elastica_Client($config);
$index = $client->getIndex(YOUR_INDEX_NAME);
$resultSet = $index->search('some search term or query');
echo var_export($resultSet, true);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment