/**
  * 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());
 }
 /**
  * @param array $config
  *
  * @return Client
  */
 public function create(array $config)
 {
     if (class_exists('\\Elasticsearch\\ClientBuilder')) {
         return \Elasticsearch\ClientBuilder::fromConfig($config);
     }
     return new Client($config);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * @return Client
  */
 public static function build($hosts)
 {
     $params = [];
     if (isset($hosts)) {
         $params['hosts'] = $hosts;
     }
     return ClientBuilder::fromConfig($params);
 }
 /**
  * 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);
 }
 /**
  * @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);
 }
 /**
  * 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'));
     });
 }
 /**
  * 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;
     });
 }
 /**
  * @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'));
 }
Exemple #11
-1
 public function testFromConfigBadParamQuiet()
 {
     $params = ['hosts' => ['localhost:9200'], 'retries' => 2, 'imNotReal' => 5];
     $client = ClientBuilder::fromConfig($params, true);
 }
 /**
  * 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);
 }
Exemple #13
-1
 /**
  * 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());
 }
<?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);
}
 /**
  * Create a client instance from the ElasticSearch SDK.
  */
 public function createClient()
 {
     $client = ClientBuilder::fromConfig($this->environment->all());
     $this->setClient($client);
 }
 /**
  * Bind the Elasticsearch client to the container
  */
 protected function bindElasticsearch()
 {
     $this->app->singleton('Elasticsearch', function ($app) {
         $config = $app->make('Menthol\\Flexible\\Config')->get('elasticsearch.params', []);
         return ClientBuilder::fromConfig($config);
     });
 }
 /**
  * @param array $config
  */
 public function initClient(array $config)
 {
     $this->_client = ClientBuilder::fromConfig($config);
 }
Exemple #18
-1
 /**
  * {@inheritdoc}
  */
 public static function setUpBeforeClass()
 {
     static::$client = \Elasticsearch\ClientBuilder::fromConfig(['hosts' => ['localhost:9200']]);
     static::$indexManager = new IndexManager(static::$client);
 }
 /**
  * @return \ElasticSearch\Client
  */
 public function createElasticsearchDriver()
 {
     $config = $this->app['config']->get('broadway.read-model.elasticsearch');
     return ClientBuilder::fromConfig($config);
 }
 /**
  * @inheritdoc
  */
 public function _before()
 {
     $this->service = new \Nord\Lumen\Elasticsearch\ElasticsearchService(\Elasticsearch\ClientBuilder::fromConfig([]));
     $this->sortBuilder = $this->service->createSortBuilder();
 }
 /**
  * Create an elasticsearch client
  */
 private function _initializeClient()
 {
     $params = ['hosts' => [getenv('ELASTICSEARCH_PORT_9200_TCP_ADDR') . ':' . getenv('ELASTICSEARCH_PORT_9200_TCP_PORT')], 'retries' => 2, 'handler' => ClientBuilder::singleHandler()];
     $this->elasticsearch_client = ClientBuilder::fromConfig($params, true);
 }