本文整理汇总了PHP中Elasticsearch\ClientBuilder::fromConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientBuilder::fromConfig方法的具体用法?PHP ClientBuilder::fromConfig怎么用?PHP ClientBuilder::fromConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elasticsearch\ClientBuilder
的用法示例。
在下文中一共展示了ClientBuilder::fromConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerElasticsearchClient
/**
* Register the Elasticsearch Client.
*
* @param array $config
* @return void
*/
protected function registerElasticsearchClient(array $config = [])
{
$this->app->bind(ElasticsearchClient::class, function () use($config) {
return ElasticsearchClientBuilder::fromConfig($config);
}, isset($config['singleton']) && $config['singleton']);
$this->app->alias(ElasticsearchClient::class, $this->prefix());
}
示例2: create
/**
* @param array $config
*
* @return Client
*/
public function create(array $config)
{
if (class_exists('\\Elasticsearch\\ClientBuilder')) {
return \Elasticsearch\ClientBuilder::fromConfig($config);
}
return new Client($config);
}
示例3: getElasticSearchClient
/**
* Get ElasticSearch Client
*
* @return \Elasticsearch\Client
*/
public function getElasticSearchClient()
{
$config = array();
if (config()->has('elasticquent.config')) {
$config = config()->get('elasticquent.config');
}
return \Elasticsearch\ClientBuilder::fromConfig($config);
}
示例4: getElasticSearchClient
/**
* Get ElasticSearch Client
*
* @return \Elasticsearch\Client
*/
public function getElasticSearchClient()
{
$config = array();
if (\Config::has('elasticquent.config')) {
$config = \Config::get('elasticquent.config');
}
return \Elasticsearch\ClientBuilder::fromConfig($config, true);
}
示例5: build
/**
* @return Client
*/
public static function build($hosts)
{
$params = [];
if (isset($hosts)) {
$params['hosts'] = $hosts;
}
return ClientBuilder::fromConfig($params);
}
示例6: getElasticSearchClient
/**
* Get ElasticSearch Client
*
* @return \Elasticsearch\Client
*/
public function getElasticSearchClient()
{
$config = $this->getElasticConfig();
// elasticsearch v2.0 using builder
if (class_exists('\\Elasticsearch\\ClientBuilder')) {
return \Elasticsearch\ClientBuilder::fromConfig($config);
}
// elasticsearch v1
return new \Elasticsearch\Client($config);
}
示例7: getDriver
/**
* @return object
*/
public function getDriver()
{
$config = $this->config->get('broadway.read-model-connections.elasticsearch.config');
// elasticsearch v2.0 using builder
if (class_exists(\Elasticsearch\ClientBuilder::class)) {
return \Elasticsearch\ClientBuilder::fromConfig($config);
}
// elasticsearch v1
return new \Elasticsearch\Client($config);
}
示例8: register
/**
* Register the Catalogue module service provider.
*
* This service provider is a convenient place to register your modules
* services in the IoC container. If you wish, you may make additional
* methods or service providers to keep the code more focused and granular.
*
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
*
* @return void
*/
public function register()
{
App::register('ChingShop\\Modules\\Catalogue\\Providers\\RouteServiceProvider');
/* @noinspection RealpathOnRelativePathsInspection */
View::addNamespace('catalogue', app_path('Modules/Catalogue/Resources/Views'));
// Bind the Elasticsearch client to the container.
$this->app->bind(Client::class, function () {
return ElasticsearchBuilder::fromConfig(config('scout.elasticsearch.config'));
});
}
示例9: registerBindings
/**
* Register bindings.
*/
protected function registerBindings()
{
/** @noinspection PhpUndefinedMethodInspection */
$config = $this->app['config']->get('elasticsearch', []);
$this->app->singleton(ElasticsearchServiceContract::class, function () use($config) {
$elasticsearchService = new ElasticsearchService(ClientBuilder::fromConfig($config));
if (isset($config[self::CONFIG_KEY]['settings'])) {
$elasticsearchService->setSettings($config[self::CONFIG_KEY]['settings']);
}
return $elasticsearchService;
});
}
示例10: _before
/**
* @inheritdoc
*/
public function _before()
{
$service = new \Nord\Lumen\Elasticsearch\ElasticsearchService(\Elasticsearch\ClientBuilder::fromConfig([]));
$queryBuilder = $service->createQueryBuilder();
$this->search = $service->createSearch();
$this->query = $queryBuilder->createBoolQuery();
$this->query->addMust($queryBuilder->createTermQuery()->setField('field1')->setValue('value1'));
$sortBuilder = $service->createSortBuilder();
$this->sort = $service->createSort();
$this->sort->addSort($sortBuilder->createScoreSort());
$aggregationBuilder = $service->createAggregationBuilder();
$this->aggregation = $aggregationBuilder->createGlobalAggregation();
$this->aggregation->setName('global_name');
$this->aggregation->addAggregation($aggregationBuilder->createMinAggregation()->setField('field_name')->setName('min_name'));
$this->aggregation->addAggregation($aggregationBuilder->createMaxAggregation()->setField('field_name')->setName('max_name'));
}
示例11: testFromConfigBadParamQuiet
public function testFromConfigBadParamQuiet()
{
$params = ['hosts' => ['localhost:9200'], 'retries' => 2, 'imNotReal' => 5];
$client = ClientBuilder::fromConfig($params, true);
}
示例12: createClient
/**
* Create a new ElasticSearch client instance.
*
* @param array $config
* @return \Elasticsearch\Client
*/
protected function createClient($config)
{
// Use the Elasticsearch ClientBuilder helper to create the search client
$config = $this->createLoggerConfig($config);
return \Elasticsearch\ClientBuilder::fromConfig($config);
}
示例13: newClient
/**
* Create a new elastica client.
*
* @return Client
*/
protected function newClient()
{
$config = config('elasticquent')['config'];
if (class_exists('\\Elasticsearch\\ClientBuilder')) {
return \Elasticsearch\ClientBuilder::fromConfig($config);
}
return new Client($this->connection());
}
示例14: error_reporting
<?php
error_reporting(E_ALL | E_STRICT);
// Set the default timezone. While this doesn't cause any tests to fail, PHP
// complains if it is not set in 'date.timezone' of php.ini.
date_default_timezone_set('UTC');
// Ensure that composer has installed all dependencies
if (!file_exists(dirname(__DIR__) . '/composer.lock')) {
die("Dependencies must be installed using composer:\n\nphp composer.phar install --dev\n\n" . "See http://getcomposer.org for help with installing composer\n");
}
// Include the composer autoloader
$autoloader = (require_once dirname(__DIR__) . '/vendor/autoload.php');
$client = \Elasticsearch\ClientBuilder::fromConfig(['hosts' => [$_SERVER['ES_TEST_HOST']]]);
$count = 0;
while (!$client->ping()) {
$count += 1;
if ($count > 15) {
throw new \Exception("Live cluster could not be found in 15s!");
}
sleep(1);
}
示例15: createClient
/**
* Create a client instance from the ElasticSearch SDK.
*/
public function createClient()
{
$client = ClientBuilder::fromConfig($this->environment->all());
$this->setClient($client);
}