本文整理汇总了PHP中Elasticsearch\ClientBuilder::create方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientBuilder::create方法的具体用法?PHP ClientBuilder::create怎么用?PHP ClientBuilder::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elasticsearch\ClientBuilder
的用法示例。
在下文中一共展示了ClientBuilder::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postSearch
public function postSearch()
{
$enabled = Config::get("search.enabled");
if (!$enabled) {
App::abort(404);
return;
}
$term = isset($_POST["term"]) ? $_POST["term"] : "";
$client = Elasticsearch\ClientBuilder::create()->setHosts(Config::get("search.hosts"))->build();
$params = ['index' => 'website', 'type' => 'mediaItem', 'body' => ['query' => ['dis_max' => ['tie_breaker' => 0.3, 'queries' => [['dis_max' => ['tie_breaker' => 0.3, 'queries' => [['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['name^10', 'name.std'], 'boost' => 13]], ['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['description^10', 'description.std'], 'boost' => 11]]]]], ['nested' => ['path' => 'playlists.playlist', 'query' => ['dis_max' => ['tie_breaker' => 0.3, 'queries' => [['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['playlists.playlist.name^10', 'playlists.playlist.name.std'], 'boost' => 8]], ['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['playlists.playlist.description^10', 'playlists.playlist.description.std'], 'boost' => 6]]]]]]], ['nested' => ['path' => 'playlists.playlist.show', 'query' => ['dis_max' => ['tie_breaker' => 0.3, 'queries' => [['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['playlists.playlist.show.name^10', 'playlists.playlist.show.name.std'], 'boost' => 3]], ['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['playlists.playlist.show.description^10', 'playlists.playlist.show.description.std'], 'boost' => 1]]]]]]]]]]]];
$result = $client->search($params);
if ($result["timed_out"]) {
App::abort(500);
// server error
return;
}
$results = array();
if ($result["hits"]["total"] > 0) {
foreach ($result["hits"]["hits"] as $hit) {
$source = $hit["_source"];
$result = array("title" => $source["name"], "description" => $source["description"], "thumbnailUri" => $source["playlists"][0]["coverArtUri"], "url" => $source["playlists"][0]["url"]);
$results[] = $result;
}
}
return Response::json(array("results" => $results));
}
示例2: removeFromIndex
public static function removeFromIndex($b)
{
if (defined('ELIB_BLOG_ELASTIC') && ELIB_BLOG_ELASTIC) {
$params = ['index' => 'elib_blog', 'type' => 'blog', 'id' => $b->id];
$client = ClientBuilder::create()->build();
$response = $client->delete($params);
}
}
示例3: __construct
function __construct()
{
$this->hosts = array(ES_HOST . ":" . ES_PORT);
$this->clientBuilder = \Elasticsearch\ClientBuilder::create();
$this->clientBuilder->setHosts($this->hosts);
$this->client = $this->clientBuilder->build();
}
示例4: __construct
public function __construct($hostUrl, $index)
{
$hosts = array($hostUrl);
$this->esClient = ClientBuilder::create()->setHosts($hosts)->setRetries(2)->build();
$this->index = $index;
$this->jobs = ['body' => []];
}
示例5: hotSwapIndices
private function hotSwapIndices($versionedIndex, $entityIndexName)
{
$client = ClientBuilder::create()->setHosts(config('elasticquent.config.hosts'))->build();
$indexExists = $client->indices()->exists(['index' => $entityIndexName]);
$previousIndexName = null;
$indices = $client->indices()->getAliases();
foreach ($indices as $indexName => $indexData) {
if (array_key_exists('aliases', $indexData) && isset($indexData['aliases'][$entityIndexName])) {
$previousIndexName = $indexName;
break;
}
}
if ($indexExists === true && $previousIndexName === null) {
$client->indices()->delete(['index' => $entityIndexName]);
$client->indices()->putAlias(['name' => $entityIndexName, 'index' => $versionedIndex]);
} else {
if ($previousIndexName !== null) {
$client->indices()->deleteAlias(['name' => $entityIndexName, 'index' => $previousIndexName]);
}
$client->indices()->putAlias(['name' => $entityIndexName, 'index' => $versionedIndex]);
if ($previousIndexName !== null) {
$client->indices()->delete(['index' => $previousIndexName]);
}
}
}
示例6: testCustomQueryParams
public function testCustomQueryParams()
{
$params = array();
$client = Elasticsearch\ClientBuilder::create()->setHosts([$_SERVER['ES_TEST_HOST']])->build();
$getParams = array('index' => 'test', 'type' => 'test', 'id' => 1, 'parent' => 'abc', 'custom' => array('customToken' => 'abc', 'otherToken' => 123));
$exists = $client->exists($getParams);
}
示例7: __construct
/**
* Create a new command instance.
*/
public function __construct(CLImate $cli, IpUtils $ipUtils)
{
parent::__construct();
$this->cli = $cli;
$this->ipUtils = $ipUtils;
$this->esClient = ClientBuilder::create()->setHosts(config('elasticsearch.hosts'))->build();
}
示例8: testConstructor
public function testConstructor()
{
$elasticsearchClient = \Elasticsearch\ClientBuilder::create()->build();
$cmClient = new CM_Elasticsearch_Client($elasticsearchClient);
$this->assertInstanceOf('CM_Elasticsearch_Client', $cmClient);
$this->assertEquals($elasticsearchClient, CMTest_TH::callProtectedMethod($cmClient, '_getClient'));
}
示例9: buildClient
/**
* Build and configure an Elasticsearch client.
*
* @param array $config
* @return \Elasticsearch\Client
*/
protected function buildClient(array $config)
{
$clientBuilder = ClientBuilder::create();
// Configure hosts
$clientBuilder->setHosts($config['hosts']);
// Configure logging
if (array_get($config, 'logging')) {
$logObject = array_get($config, 'logObject');
$logPath = array_get($config, 'logPath');
$logLevel = array_get($config, 'logLevel');
if ($logObject && $logObject instanceof LoggerInterface) {
$clientBuilder->setLogger($logObject);
} else {
if ($logPath && $logLevel) {
$logObject = ClientBuilder::defaultLogger($logPath, $logLevel);
$clientBuilder->setLogger($logObject);
}
}
}
// Set additional client configuration
foreach ($this->configMappings as $key => $method) {
$value = array_get($config, $key);
if ($value !== null) {
call_user_func([$clientBuilder, $method], $value);
}
}
// Build and return the client
return $clientBuilder->build();
}
示例10: __construct
/**
* Create a new command instance.
*/
public function __construct(Ubench $bench, IpUtils $ipUtils)
{
parent::__construct();
$this->bench = $bench;
$this->ipUtils = $ipUtils;
$this->esClient = ClientBuilder::create()->setHosts(config('elasticsearch.hosts'))->build();
}
示例11: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$this->info('Creating search index.');
// (re)set all version numbers in the database to make sure everything gets indexed
$data = ["pending_search_index_version" => 1, "current_search_index_version" => 0];
DB::table("media_items")->update($data);
DB::table("playlists")->update($data);
DB::table("shows")->update($data);
$esClient = Elasticsearch\ClientBuilder::create()->setHosts(Config::get("search.hosts"))->build();
$showProperties = ['id' => ['type' => 'integer', 'index' => 'no'], 'name' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'description' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'url' => ['type' => 'string', 'index' => 'no']];
$playlistProperties = ['id' => ['type' => 'integer', 'index' => 'no'], 'name' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'description' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'scheduledPublishTime' => ['type' => 'date'], 'coverArtUri' => ['type' => 'string', 'index' => 'no'], 'seriesNo' => ['type' => 'integer', 'index' => 'no'], 'url' => ['type' => 'string', 'index' => 'no'], 'show' => ['type' => 'nested', 'properties' => $showProperties]];
$mediaItemProperties = ['id' => ['type' => 'integer', 'index' => 'no'], 'name' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'description' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'scheduledPublishTime' => ['type' => 'date'], 'playlists' => ['type' => 'nested', 'properties' => ['generatedName' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'coverArtUri' => ['type' => 'string', 'index' => 'no'], 'url' => ['type' => 'string', 'index' => 'no'], 'playlist' => ['type' => 'nested', 'properties' => $playlistProperties]]]];
// creating 3 indexes "mediaItem", "playlist" and "show".
// the "mediaItem" index contains copies of data in "playlist" and "show" and
// the "playlist" index contains copies of data in "show"
// this duplication is more optimum for searching according to https://www.elastic.co/guide/en/elasticsearch/guide/current/denormalization.html
// https://www.elastic.co/guide/en/elasticsearch/guide/current/root-object.html
$params = ['index' => 'website', 'body' => ['mappings' => ['_default_' => ['dynamic' => "strict", 'include_in_all' => false], 'mediaItem' => ['properties' => $mediaItemProperties], 'playlist' => ['properties' => $playlistProperties], 'show' => ['properties' => $showProperties]]]];
$response = $esClient->indices()->create($params);
if ($response['acknowledged']) {
$this->info("Index created!");
} else {
$this->error("Something went wrong.");
}
$this->info('Done.');
}
示例12: __construct
public function __construct($host)
{
$builder = Elasticsearch\ClientBuilder::create();
$builder->setHosts(array($host));
$this->client = $builder->build();
$this->logger = new NullLogger();
}
示例13: client
public function client()
{
if (empty($this->clientConnection)) {
$this->clientConnection = ClientBuilder::create()->setHosts($this->hosts())->build();
}
return $this->clientConnection;
}
示例14: setUp
protected function setUp()
{
$config = ['db_name' => 'test', 'hosts' => ['127.0.0.1:9200']];
$client = ClientBuilder::create()->setHosts($config['hosts'])->build();
$this->client = new ElasticSearch($config, $client);
$this->client->drop('test');
}
示例15: __construct
public function __construct()
{
global $argv;
$this->colors = new Colors();
if (file_exists('resume.lock') && $argv[1] != 'resume') {
$this->resume();
}
if (isset($argv[1]) && $argv[1] == 'resume') {
echo PHP_EOL . 'Resuming from previous state' . PHP_EOL;
if (file_exists('resume.lock')) {
$this->offset = (int) file_get_contents('resume.lock');
} else {
echo PHP_EOL . 'resume.lock file does not exist. Exiting...';
die(PHP_EOL);
}
}
if (strlen(DB_TABLE) == 0) {
echo PHP_EOL . $this->colors->getColoredString("Database table is not defined. Please check the Config.php file.", 'red') . PHP_EOL;
die;
}
try {
$this->database = new medoo(['database_type' => 'mysql', 'database_name' => DB_NAME, 'server' => DB_HOST, 'username' => DB_USER, 'password' => DB_PASS, 'charset' => 'utf8', 'port' => DB_PORT]);
} catch (Exception $e) {
echo PHP_EOL . $this->colors->getColoredString("Error While Connection to mySQL Database,\nPlease check your Database connection settings in config.php", 'red') . PHP_EOL;
die;
}
if (USE_DB_COLUMN == TRUE) {
$this->idCol = DB_COL;
}
global $ES_HOST;
$this->logger = \Elasticsearch\ClientBuilder::defaultLogger('mySQLtoes.log');
$this->elasticSearch = \Elasticsearch\ClientBuilder::create()->setLogger($this->logger)->setHosts($ES_HOST)->build();
}