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)); }
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); } }
function __construct() { $this->hosts = array(ES_HOST . ":" . ES_PORT); $this->clientBuilder = \Elasticsearch\ClientBuilder::create(); $this->clientBuilder->setHosts($this->hosts); $this->client = $this->clientBuilder->build(); }
public function __construct($hostUrl, $index) { $hosts = array($hostUrl); $this->esClient = ClientBuilder::create()->setHosts($hosts)->setRetries(2)->build(); $this->index = $index; $this->jobs = ['body' => []]; }
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]); } } }
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); }
/** * 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(); }
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')); }
/** * 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(); }
/** * 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(); }
/** * 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.'); }
public function __construct($host) { $builder = Elasticsearch\ClientBuilder::create(); $builder->setHosts(array($host)); $this->client = $builder->build(); $this->logger = new NullLogger(); }
public function client() { if (empty($this->clientConnection)) { $this->clientConnection = ClientBuilder::create()->setHosts($this->hosts())->build(); } return $this->clientConnection; }
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'); }
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(); }
/** * 构造函数,初始化基本的链接es客户端 * * @Author tianyunzi * @DateTime 2016-05-26T14:26:49+0800 * @param [type] $hosts [description] */ public function __construct($hosts) { if (empty($hosts)) { throw new Exception("please give really es config!"); } $this->client = ClientBuilder::create()->setHosts($hosts)->build(); }
/** * Register the service provider. * * @return void */ public function register() { $this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'bouncy'); $this->app->singleton('elastic', function ($app) { //return new ElasticSearch($app['config']->get('elasticsearch')); return ClientBuilder::create()->build(); }); }
private function savePodcasts($podcastList) { $client = ClientBuilder::create()->build(); foreach ($podcastList as $id => $podcast) { echo "Adding podcast number: {$id}\n"; $client->index($this->build($id, $podcast)); } }
/** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); $this->bench = new Ubench(); $this->esClient = ClientBuilder::create()->setHosts(config('elasticsearch.hosts'))->build(); $this->versionedIndex = $this->indexName . '_' . time(); $this->ipUtils = new IpUtils(); }
/** * Register Elasticsearch client. */ protected function registerDuctibleClient() { $this->app->singleton(['Elasticsearch\\Client' => 'ductible.client'], function ($app) { $config = $app->make('config')->get('ductible'); $client = ClientBuilder::create()->setHosts(explode('|', $config['hosts']))->setRetries($config['retries'])->setLogger($app->make('ductible.client.logger'))->setHandler($app->make('ductible.client.handler'))->setConnectionPool($config['pool'])->setSelector($config['selector'])->setSerializer($config['serializer'])->build(); return $client; }); }
/** * Register the application services. * * @return void */ public function register() { $this->app->singleton('elastic', function () { $clientBuilder = ClientBuilder::create(); $clientBuilder->setHosts(config('eswrapper.hosts'), ['localhost:9200']); return $clientBuilder->build(); }); }
public static function all() { $elasticSearch = ClientBuilder::create()->build(); $searchParams['body']['query']['match_all'] = []; $searchParams['body']['size'] = 10000; $searchParams['body']['sort'] = ['_uid' => 'desc']; $hits = $elasticSearch->search($searchParams)['hits']; return Podcasts::sortPodcastsByPodcastId($hits); }
function es() { $es = getenv('ELASTICSEARCH'); if ($es == null) { $es = 'http://elasticsearch:9200'; } $client = \Elasticsearch\ClientBuilder::create()->setHosts([$es])->build(); return $client; }
/** * Register any application services. * * @return void */ public function register() { $this->app->singleton('elasticsearch', function ($app) { $es = new ClientBuilder(); $client = $es->create()->setHosts(config('elasticsearch.hosts', ['localhost']))->build(); $this->app->instance('elasticsearch', $client); return $client; }); }
/** */ public static function setUpBeforeClass() { if (!class_exists('Elasticsearch\\Client') || self::skipTest()) { self::markTestSkipped("ElasticSearch library not found."); } self::$index = uniqid('test_'); self::$type = uniqid(); self::$client = ClientBuilder::create()->build(); }
/** * Execute the job. * * @return void */ public function handle() { $client = \Elasticsearch\ClientBuilder::create()->build(); $indexParams['index'] = 'properties'; if ($client->indices()->exists($indexParams) != false) { $client->indices()->delete($indexParams); } return; }
/** * 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 SSL if (isset($config['sslVerification']) && $config['sslVerification'] !== null) { $clientBuilder->setSSLVerification($config['sslVerification']); } // Configure logging if (isset($config['logging']) && $config['logging']) { if (isset($config['logObject']) && $config['logObject'] instanceof LoggerInterface) { $clientBuilder->setLogger($config['logObject']); } else { if (isset($config['logPath']) && isset($config['logLevel'])) { $path = $config['logPath']; $level = $config['logLevel']; $logger = ClientBuilder::defaultLogger($path, $level); $clientBuilder->setLogger($logger); } } } // Configure Sniff-on-Start if (isset($config['sniffOnStart']) && $config['sniffOnStart'] !== null) { $clientBuilder->setSniffOnStart($config['sniffOnStart']); } // Configure Retries if (isset($config['retries']) && $config['retries'] !== null) { $clientBuilder->setRetries($config['retries']); } // Configure HTTP Handler if (isset($config['httpHandler']) && $config['httpHandler'] !== null) { $clientBuilder->setHandler($config['httpHandler']); } // Configure Connection Pool if (isset($config['connectionPool']) && $config['connectionPool'] !== null) { $clientBuilder->setConnectionPool($config['connectionPool']); } // Configure Connection Selector if (isset($config['connectionSelector']) && $config['connectionSelector'] !== null) { $clientBuilder->setSelector($config['connectionSelector']); } // Configure Serializer if (isset($config['serializer']) && $config['serializer'] !== null) { $clientBuilder->setSerializer($config['serializer']); } // Configure Connection Factory if (isset($config['connectionFactory']) && $config['connectionFactory'] !== null) { $clientBuilder->setConnectionFactory($config['connectionFactory']); } // Configure Endpoint if (isset($config['endpoint']) && $config['endpoint'] !== null) { $clientBuilder->setEndpoint($config['endpoint']); } // Build and return the client return $clientBuilder->build(); }
public function indexAction($name, \Symfony\Component\HttpFoundation\Request $request) { $client = \Elasticsearch\ClientBuilder::create()->build(); $par = array('index' => 'mi2s', 'type' => 'dataset', 'from' => 0, 'size' => 10, 'body' => array('query' => array('bool' => array('should' => array(array('match' => array('licence' => 'GNU')), array('match' => array('type' => 'instrument')), array('match' => array('type' => 'TRACE'))))))); $response = $client->search($par); $count = sizeof($response['hits']['hits']); $r1 = $client->search($par); print $count; return $this->render('AcmeMainBundle:Default:index.html.twig', array('name' => $name, 'r1' => $r1['hits']['hits'], 'name' => $response['hits']['hits'], 'count' => $count)); }
/** * Register the service provider. * * @return void */ public function register() { // 將config/config.php裡的設定跟原有的結合起來 $this->mergeConfigFrom(__DIR__ . '/config/config.php', 'es_config'); // 登入elasticsearch $this->app->singleton('Elasticsearch\\Client', function ($app) { return ClientBuilder::create()->build(config('es_config')); }); $this->app->instance('qelastic', new Qelastic($this->app)); }
protected function registerService() { $this->app[Config::class] = new Config(config('search')); $this->app['Modules\\Search\\SearchService'] = $this->app->share(function ($app) { $config = $app[Config::class]; $client = ClientBuilder::create()->setHosts(config('search.hosts'))->build(); $service = new SearchService($app, $client, $config); return $service; }); }