當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Client::request方法代碼示例

本文整理匯總了PHP中Elastica\Client::request方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::request方法的具體用法?PHP Client::request怎麽用?PHP Client::request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Elastica\Client的用法示例。


在下文中一共展示了Client::request方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: iterate

 /**
  * Iterate on index documents and perform $closure
  * Iteration uses ElasticSearch scroll scan methods
  * Note: Using setLimit(N) and setFrom(N) for query does not affect actual limit and offset (Limited by ES scan/scroll functionality, see Docs in link)
  *
  * See docs about $scroll in link:
  * @link http://www.elasticsearch.org/guide/reference/api/search/scroll.html
  *
  * @param Query|AbstractQuery $query
  * @param \Closure $closure Receives arguments: function(DataProviderDocument $doc, $i, $total); Return TRUE in $closure if you want to break and stop iteration
  * @param int $batchSize
  * @param string $scroll
  */
 public function iterate(Query $query, \Closure $closure, $batchSize = 100, $scroll = '5m')
 {
     $response = $this->index->request('_search', 'GET', $query->toArray(), array('search_type' => 'scan', 'scroll' => $scroll, 'size' => $batchSize, 'limit' => 1));
     $data = $response->getData();
     $scrollId = $data['_scroll_id'];
     $total = $data['hits']['total'];
     $i = 0;
     $response = $this->client->request('_search/scroll', 'GET', $scrollId, array('scroll' => $scroll));
     $data = $response->getData();
     while (count($data['hits']['hits']) > 0) {
         foreach ($data['hits']['hits'] as $item) {
             $itemData = $item['_source'];
             $doc = new DataProviderDocument($item['_id'], $item['_type'], $itemData);
             if ($break = $closure($doc, $i, $total)) {
                 break 2;
             }
             $i++;
         }
         $scrollId = $data['_scroll_id'];
         $response = $this->client->request('_search/scroll', 'GET', $scrollId, array('scroll' => $scroll));
         $data = $response->getData();
     }
 }
開發者ID:darklow,項目名稱:ff-elastica-manager,代碼行數:36,代碼來源:Iterator.php

示例2: execute

 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $table = new Console\Helper\TableHelper();
     $output->writeln('Cluster overview:');
     $output->writeln('');
     $output->writeln('Nodes:');
     $cluster = $this->elastica->getCluster();
     $table->setHeaders(['name', 'documents', 'node', 'ip', 'port', 'hostname', 'version', 'transport address', 'http address']);
     $nodes = $cluster->getNodes();
     foreach ($nodes as $node) {
         $name = $node->getName();
         $ip = $node->getInfo()->getIp();
         $data = $node->getInfo()->getData();
         $port = $node->getInfo()->getPort();
         $stats = $node->getStats()->get();
         //dump($stats->get());exit;
         $table->addRow([$data['name'], $stats['indices']['docs']['count'], $name, $ip, $port, $data['hostname'], $data['version'], $data['transport_address'], $data['http_address']]);
     }
     $table->render($output);
     $table->setRows([]);
     /* INFO */
     $info = $this->elastica->request('', 'GET')->getData();
     $table->setHeaders(['name', 'version', 'status', 'ok']);
     $table->addRow([$info['name'], $info['version']['number'], $info['status'], $info['ok']]);
     $table->render($output);
     $table->setRows([]);
     $output->writeln('');
 }
開發者ID:bazo,項目名稱:nette-elasticsearch-extension,代碼行數:28,代碼來源:ElasticSearchInfo.php

示例3: find

 /**
  * Find a document by id.
  *
  * @param $id
  * @param $type
  * @param $index
  *
  * @return bool|Document
  */
 public function find($id, $type, $index = 'activehire')
 {
     $path = $index . '/' . $type . '/' . $id;
     $response = $this->client->request($path);
     if ($response->isOk()) {
         $responseData = $response->getData();
         return $this->createDocument($responseData['_source'], $type, $index);
     }
     return false;
 }
開發者ID:phpfour,項目名稱:ah,代碼行數:19,代碼來源:Elastica.php

示例4: requestByType

 /**
  * Making a request by giving in raw json as the query
  * @param  jsonstring  $query       Raw json query
  * @return array                    An array containing the mapped entities.
  */
 public function requestByType($query, $type = 'organisation,vacancy,person', $requestType = Request::GET)
 {
     $client = new Client(array('host' => $this->es_host, 'port' => $this->es_port));
     $path = $this->getIndex() . '/' . $type . '/_search';
     $response = $client->request($path, $requestType, $query)->getData();
     return $this->esMapper->getEntities($response['hits']['hits']);
 }
開發者ID:howest-wsde,項目名稱:VrijwilligersTool,代碼行數:12,代碼來源:ElasticsearchQuery.php

示例5: scanAvailablePlugins

 /**
  * @param array $bannedPlugins
  * @return array
  */
 public function scanAvailablePlugins(array $bannedPlugins = array())
 {
     $this->outputIndented("Scanning available plugins...");
     $result = $this->client->request('_nodes');
     $result = $result->getData();
     $availablePlugins = array();
     $first = true;
     foreach (array_values($result['nodes']) as $node) {
         $plugins = array();
         foreach ($node['plugins'] as $plugin) {
             $plugins[] = $plugin['name'];
         }
         if ($first) {
             $availablePlugins = $plugins;
             $first = false;
         } else {
             $availablePlugins = array_intersect($availablePlugins, $plugins);
         }
     }
     if (count($availablePlugins) === 0) {
         $this->output('none');
     }
     $this->output("\n");
     if (count($bannedPlugins)) {
         $availablePlugins = array_diff($availablePlugins, $bannedPlugins);
     }
     foreach (array_chunk($availablePlugins, 5) as $pluginChunk) {
         $plugins = implode(', ', $pluginChunk);
         $this->outputIndented("\t{$plugins}\n");
     }
     return $availablePlugins;
 }
開發者ID:jamesmontalvo3,項目名稱:mediawiki-extensions-CirrusSearch,代碼行數:36,代碼來源:ConfigUtils.php

示例6: testSearchWithSynonyms

 public function testSearchWithSynonyms()
 {
     $indexSettings = json_decode(file_get_contents(__DIR__ . '/../_data/productIndex.json'), true);
     // custom synonyms
     $synonyms = [];
     $synonyms[] = "tai nghe,headphone";
     $synonyms[] = "chụp hình,chụp ảnh";
     $indexSettings['settings']['index']['analysis']['filter']['name_synonym_filter']['synonyms'] = $synonyms;
     $path = '/test/product/';
     // create index
     $this->client->request($path, Request::PUT, $indexSettings);
     // insert data test
     $productData = json_decode($this->sampleProductJson, true);
     $productNames = ["tai nghe abc", "headphone xyz", "headphone tai nghe", "tai abc nghe", "wrong name", "gậy chụp hình abc", "gậy chụp ảnh xyz", "chụp hình cho trẻ", "công việc chụp ảnh", "ảnh hình"];
     $i = 1;
     foreach ($productNames as $name) {
         $productData['searchable_name'] = $name;
         $this->client->request($path . $i++, Request::PUT, ['searchable_name' => $name, 'type' => 'sample', 'attribute' => 'any attribtue', 'value' => rand(1, 999)]);
     }
     // wait for index
     sleep(3);
     foreach ($synonyms as $syn) {
         $keywords = explode(',', $syn);
         // with unmarked field is using synonyms and not unmarked field not use
         $dataForFirstKeyword = $this->client->request($path . '_search', Request::GET, ['query' => ['match_phrase' => ['searchable_name.unmarked' => $keywords[0]]]])->getData();
         $dataForFirstKeywordNotUnmarked = $this->client->request($path . '_search', Request::GET, ['query' => ['match_phrase' => ['searchable_name' => $keywords[0]]]])->getData();
         // responses of search no synonym and search with synonyms are different
         $this->assertNotEquals($dataForFirstKeyword['hits'], $dataForFirstKeywordNotUnmarked['hits']);
         $dataForSecondKeyword = $this->client->request($path . '_search', Request::GET, ['query' => ['match_phrase' => ['searchable_name.unmarked' => $keywords[1]]]])->getData();
         // test responses of 2 synonym keywords are same
         $this->assertEquals($dataForFirstKeyword['hits'], $dataForSecondKeyword['hits']);
     }
 }
開發者ID:enjoy2000,項目名稱:demo-es,代碼行數:33,代碼來源:DemoESTest.php

示例7: send

 /**
  * @return \Elastica\Bulk\ResponseSet
  */
 public function send()
 {
     $path = $this->getPath();
     $data = $this->toString();
     $response = $this->_client->request($path, Request::POST, $data, $this->_requestParams);
     return $this->_processResponse($response);
 }
開發者ID:levijackson,項目名稱:Elastica,代碼行數:10,代碼來源:Bulk.php

示例8: getIndexHealth

 /**
  * Get index health
  * @param string $indexName
  * @return array the index health status
  */
 public function getIndexHealth($indexName)
 {
     $path = "_cluster/health/{$indexName}";
     $response = $this->client->request($path);
     if ($response->hasError()) {
         throw new \Exception("Error while fetching index health status: " . $response->getError());
     }
     return $response->getData();
 }
開發者ID:zoglun,項目名稱:mediawiki-extensions-CirrusSearch,代碼行數:14,代碼來源:ConfigUtils.php

示例9: request

 /**
  * {@inheritdoc}
  */
 public function request($path, $method = Request::GET, $data = [], array $query = [])
 {
     $start = microtime(true);
     $response = parent::request($path, $method, $data, $query);
     $time = microtime(true) - $start;
     if (!defined('DEBUG') || false === DEBUG) {
         $response->setQueryTime($time);
     }
     $this->logQuery($path, $method, $data, $query, $time);
     return $response;
 }
開發者ID:wikibusiness,項目名稱:elastica-bundle,代碼行數:14,代碼來源:ElasticaClient.php

示例10: request

 /**
  * {@inheritdoc}
  */
 public function request($path, $method = Request::GET, $data = array(), array $query = array())
 {
     $start = microtime(true);
     $response = parent::request($path, $method, $data, $query);
     if ($this->_logger and $this->_logger instanceof ElasticaLogger) {
         $time = microtime(true) - $start;
         $connection = $this->getLastRequest()->getConnection();
         $connection_array = array('host' => $connection->getHost(), 'port' => $connection->getPort(), 'transport' => $connection->getTransport(), 'headers' => $connection->hasConfig('headers') ? $connection->getConfig('headers') : array());
         $this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query);
     }
     return $response;
 }
開發者ID:benstinton,項目名稱:FOSElasticaBundle,代碼行數:15,代碼來源:Client.php

示例11: request

 /**
  * @param string $path
  * @param string $method
  * @param array $data
  * @param array $query
  * @throws \Exception
  * @return Elastica\Response
  */
 public function request($path, $method = Request::GET, $data = array(), array $query = array())
 {
     $begin = microtime(TRUE);
     try {
         $response = parent::request($path, $method, $data, $query);
         $this->onSuccess($this, $this->_lastRequest, $response, microtime(TRUE) - $begin);
         return $response;
     } catch (\Exception $e) {
         $this->onError($this, $this->_lastRequest, $e, microtime(TRUE) - $begin);
         throw $e;
     }
 }
開發者ID:EaredSeal,項目名稱:ElasticSearch,代碼行數:20,代碼來源:Client.php

示例12: request

 /**
  * @param string $path
  * @param string $method
  * @param array  $data
  * @param array  $query
  *
  * @return \Elastica\Response
  */
 public function request($path, $method = Request::GET, $data = array(), array $query = array())
 {
     $start = microtime(true);
     $response = parent::request($path, $method, $data, $query);
     $responseData = $response->getData();
     if (isset($responseData['took']) && isset($responseData['hits'])) {
         $this->logQuery($path, $method, $data, $query, $start, $response->getEngineTime(), $responseData['hits']['total']);
     } else {
         $this->logQuery($path, $method, $data, $query, $start, 0, 0);
     }
     return $response;
 }
開發者ID:gbprod,項目名稱:elastica-bundle,代碼行數:20,代碼來源:Client.php

示例13: _getIndices

 /**
  * Retrieves the indices available from ElasticSearch
  */
 protected function _getIndices()
 {
     if (null === static::$_indices) {
         $_indices = [];
         try {
             $_response = $this->_client->request('_aliases?pretty=1');
             foreach ($_response->getData() as $_index => $_aliases) {
                 //  No recent index
                 if (false === stripos($_index, '_recent') && '.kibana' !== $_index) {
                     $_indices[] = $_index;
                 }
             }
             if (!empty($_indices)) {
                 static::$_indices = $_indices;
             }
         } catch (\Exception $_ex) {
             Log::error($_ex);
             throw $_ex;
         }
     }
     return static::$_indices;
 }
開發者ID:rajeshpillai,項目名稱:dfe-common,代碼行數:25,代碼來源:ElkService.php

示例14: request

 /**
  * @param string $path
  * @param string $method
  * @param array  $data
  * @param array  $query
  *
  * @return \Elastica\Response
  */
 public function request($path, $method = Request::GET, $data = array(), array $query = array())
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('es_request', 'fos_elastica');
     }
     $start = microtime(true);
     $response = parent::request($path, $method, $data, $query);
     $this->logQuery($path, $method, $data, $query, $start);
     if ($this->stopwatch) {
         $this->stopwatch->stop('es_request');
     }
     return $response;
 }
開發者ID:anteros,項目名稱:FOSElasticaBundle,代碼行數:21,代碼來源:Client.php

示例15: getHealth

 private function getHealth()
 {
     while (true) {
         $indexName = $this->specificIndexName;
         $path = "_cluster/health/{$indexName}";
         $response = $this->client->request($path);
         if ($response->hasError()) {
             $this->error('Error fetching index health but going to retry.  Message: ' . $response->getError());
             sleep(1);
             continue;
         }
         return $response->getData();
     }
 }
開發者ID:jamesmontalvo3,項目名稱:mediawiki-extensions-CirrusSearch,代碼行數:14,代碼來源:Reindexer.php


注:本文中的Elastica\Client::request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。