当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::index方法代码示例

本文整理汇总了PHP中Elasticsearch\Client::index方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::index方法的具体用法?PHP Client::index怎么用?PHP Client::index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elasticsearch\Client的用法示例。


在下文中一共展示了Client::index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addObject

 /**
  * add an object to the elasticsearch index
  *
  * @param $object
  * @param $objectId
  * @return string
  */
 public function addObject($object, $objectId)
 {
     $objectId = sha1($objectId);
     $params = array_replace($this->defaultParams, array('id' => $objectId, 'body' => $object));
     $this->client->index($params);
     return $objectId;
 }
开发者ID:mia3,项目名称:saku,代码行数:14,代码来源:ElasticSearchAdapter.php

示例2: create

 /**
  * @param JobInterface $job
  * @return string jobId
  */
 public function create(JobInterface $job)
 {
     $job->validate();
     $jobData = ['index' => $this->index->getIndexNameCurrent(), 'type' => 'jobs', 'id' => $job->getId(), 'body' => $this->fillEmptyKeys($job->getData())];
     $response = null;
     $i = 0;
     while ($i < 5) {
         try {
             $response = $this->client->index($jobData);
             break;
         } catch (ServerErrorResponseException $e) {
             // ES server error, try again
             $this->log('error', 'Elastic server error response', ['attemptNo' => $i, 'jobId' => $job->getId(), 'exception' => $e]);
         }
         sleep(1 + intval(pow(2, $i) / 2));
         $i++;
     }
     if (!isset($response['created'])) {
         throw new ApplicationException("Unable to index job", null, ['job' => $jobData, 'elasticResponse' => $response]);
     }
     //@todo: remove sleep in next (major) release
     sleep(1);
     $i = 0;
     while ($i < 5) {
         $resJob = $this->get($job->getId());
         if ($resJob != null) {
             return $response['_id'];
         }
         sleep(1 + intval(pow(2, $i) / 2));
         $i++;
     }
     throw new ApplicationException("Unable to find job in index after creation", null, ['job' => $job->getData(), 'elasticResponse' => $response]);
 }
开发者ID:ErikZigo,项目名称:syrup,代码行数:37,代码来源:JobMapper.php

示例3: indexAll

 /**
  * Index all products
  *
  * @return number
  */
 public function indexAll()
 {
     $products = $this->database->table('product')->fetchAll();
     foreach ($products as $product) {
         $this->es->index(['index' => $this->indexName, 'type' => 'product', 'id' => $product['id'], 'body' => $product->toArray()]);
     }
     return count($products);
 }
开发者ID:kalwar,项目名称:elasticshop,代码行数:13,代码来源:ProductIndexer.php

示例4: testIndexDocument2

 public function testIndexDocument2()
 {
     /** @var \Iwai\Elasticsearch\FutureData $future */
     $future = $this->client->index(['index' => 'my_index', 'type' => 'my_type', 'id' => 'my_id2', 'body' => ['testField' => 'abc']]);
     $future->then(function ($response) {
         $this->assertEquals(1, $response['created']);
     });
     $response = $future->wait();
 }
开发者ID:iwai,项目名称:elasticsearch-guzzle5connection,代码行数:9,代码来源:ESClientWithRingPHPIntegrationTest.php

示例5: set

 /**
  * {@inheritdoc}
  */
 public function set($user, $imageIdentifier, array $imageData)
 {
     $params = $this->prepareParams($imageIdentifier, $imageData);
     try {
         return (bool) $this->client->index($params);
     } catch (Exception $e) {
         trigger_error('Elasticsearch metadata indexing failed for image: ' . $imageIdentifier, E_USER_WARNING);
         return false;
     }
 }
开发者ID:sgulseth,项目名称:imbo-metadata-search,代码行数:13,代码来源:ElasticSearch.php

示例6: addDocumentToIndex

 /**
  * @param Model $model
  *
  * @throws DocumentMissingException
  */
 public function addDocumentToIndex(Model $model)
 {
     if (!$model->exists) {
         throw new DocumentMissingException('Document does not exist.');
     }
     $params = $this->getConfigurator()->getParams($model);
     // Get our document body data.
     $params['body'] = $this->getConfigurator()->getDocumentData($model);
     $this->client->index($params);
 }
开发者ID:kodicomponents,项目名称:searcher,代码行数:15,代码来源:ElasticSearch.php

示例7: persist

 /**
  * @param SavableModelInterface $model
  * @throws CouldNotPersistException
  */
 public function persist(SavableModelInterface $model)
 {
     $params = ['index' => $this->index, 'type' => $this->type];
     if ($model->getId()) {
         $params['body'] = ['doc' => $model->toArray()];
         $params['id'] = $model->getId();
         $this->client->update($params);
         $model->markAsStored();
         return;
     }
     $params['body'] = $model->toArray();
     $response = $this->client->index($params);
     $model->id = $response['_id'];
     $model->markAsStored();
 }
开发者ID:systream,项目名称:repository,代码行数:19,代码来源:ElasticSearchStorage.php

示例8: saveDocument

 /**
  * {@inheritdoc}
  */
 public function saveDocument(Searchable $model)
 {
     $document = $this->constructDocument($model);
     if (!$this->indexIsNested($model->getSearchIndex())) {
         $this->client->index($document);
         return;
     }
     list($index, $type) = $this->retrieveNestedIndex($model->getSearchIndex());
     $class = $this->retrieveParentClass($model->getSearchIndex());
     $parent = $model->belongsTo($class, null, null, class_basename($class))->getResults();
     $parentData = $this->client->get(['id' => $parent->getKey(), 'type' => $parent->getSearchType(), 'index' => $parent->getSearchIndex()])['_source'];
     if (!isset($parentData[$type])) {
         $parentData[$type] = [];
     }
     $children = Collection::make($parentData[$type]);
     if ($child = $children->first(function ($child) use($model) {
         return $child[$model->getKeyName()] == $model->getKey();
     })) {
         $newChildren = $children->map(function ($child) use($model) {
             if ($child[$model->getKeyName()] == $model->getKey()) {
                 $child = $model->documentToArray();
                 if (!isset($document[$model->getKeyName()])) {
                     $child[$model->getKeyName()] = $model->getKey();
                 }
             }
             return $child;
         });
     } else {
         $newChildren = $children->push($model->documentToArray());
     }
     $this->client->update(['id' => $parent->getKey(), 'type' => $parent->getSearchType(), 'index' => $parent->getSearchIndex(), 'body' => ['doc' => [$type => $newChildren]]]);
 }
开发者ID:phroggyy,项目名称:discover,代码行数:35,代码来源:ElasticSearchService.php

示例9: asyncLarge

 /**
  * @iterations 1000
  * @group large
  */
 public function asyncLarge()
 {
     $asyncDoc = $this->largeDocument;
     $asyncDoc['client']['future'] = 'lazy';
     $response = $this->client->index($asyncDoc);
     $response = $response['body']['created'];
 }
开发者ID:hazaveh,项目名称:mySQLtoes,代码行数:11,代码来源:SequentialIndexingEvent.php

示例10: addDocuments

 public static function addDocuments(\ElasticSearch\Client $client, $num = 3, $tag = 'cool')
 {
     $options = array('refresh' => true);
     while ($num-- > 0) {
         $doc = array('title' => "One cool document {$tag}", 'rank' => rand(1, 10));
         $client->index($doc, $num + 1, $options);
     }
     return $client;
 }
开发者ID:linbaoling,项目名称:elasticsearch-1,代码行数:9,代码来源:Helper.php

示例11: executeByElasticClient

 /**
  * Execute the request by elasticsearch client
  *
  * @param Client $client
  * @return ResponseInterface
  */
 public function executeByElasticClient(Client $client)
 {
     $responseClass = $this->getResponseClassOfRequest();
     /** @var IndexResponseInterface $response */
     $response = new $responseClass();
     $rawResult = RawResponse::build($client->index($this->toElasticClient()));
     $response = $response->build($rawResult);
     $this->getDocument()->setId($response->id());
     return $response;
 }
开发者ID:ra3oul,项目名称:Pelastic,代码行数:16,代码来源:IndexRequest.php

示例12: asyncLarge

 /**
  * @iterations 10
  * @group large
  */
 public function asyncLarge()
 {
     $responses = [];
     $asyncDoc = $this->largeDocument;
     $asyncDoc['client']['future'] = 'lazy';
     for ($i = 0; $i < 1000; $i++) {
         $responses[] = $this->client->index($asyncDoc);
     }
     $responses[999]->wait();
 }
开发者ID:hazaveh,项目名称:mySQLtoes,代码行数:14,代码来源:AsyncVsSyncIndexingEvent.php

示例13: handleMessage

 public function handleMessage(Change $change, Message $message, Channel $channel)
 {
     if (!$change->getProduct()) {
         throw new \InvalidArgumentException("Badly routed message '{$message->content}' with routing key '{$message->routingKey}'.");
     }
     $product = $change->getProduct();
     /** @var Eshop $eshop */
     $eshop = $this->eshopRepository->getOneById($product->getEshopId());
     $product->setEshop($eshop);
     $categoryIds = $product->getCategoryIds();
     if (!empty($categoryIds)) {
         $product->setCategories($this->categoryRepository->find(["_id" => ['$in' => $product->getCategoryIds()]]));
     }
     if (!$this->elasticsearch->indices()->existsAlias(["name" => $this->catalogIndexAliasName])) {
         $this->initIndex();
     }
     $response = $this->elasticsearch->index(["index" => $this->catalogIndexAliasName, "type" => ProductMeta::SHORT_NAME, "id" => (string) $product->getId(), "version" => $product->getV(), "version_type" => "external_gte", "body" => ProductMeta::toObject($product, "json:")]);
     $this->log->info("Indexed Product#{$product->getId()} (v={$product->getV()}, created=" . json_encode($response["created"]) . ").");
     $channel->ack($message);
 }
开发者ID:skrz,项目名称:cc15-mongo-es-redis-rabbitmq,代码行数:20,代码来源:ElasticsearchCatalogConsumer.php

示例14: doIndex

 /**
  * Index a single document
  *
  * @param Posts $post
  */
 protected function doIndex(Posts $post)
 {
     $params = [];
     $karma = $post->number_views + ($post->votes_up - $post->votes_down) * 10 + $post->number_replies;
     if ($karma > 0) {
         $params['body'] = ['id' => $post->id, 'title' => $post->title, 'category' => $post->categories_id, 'content' => $post->content, 'karma' => $karma];
         $params['index'] = $this->config->get('index', 'phosphorum');
         $params['type'] = 'post';
         $params['id'] = 'post-' . $post->id;
         $this->client->index($params);
     }
 }
开发者ID:phalcon,项目名称:forum,代码行数:17,代码来源:Indexer.php

示例15: handle

 public function handle()
 {
     $params = array();
     $params['hosts'] = array('http://10.0.2.2:9200');
     $es = new Client($params);
     $models = Winwin::all();
     foreach ($models as $model) {
         $es->index(['index' => 'winwins', 'type' => 'winwins', 'id' => $model->id, 'body' => $model->toArray()]);
     }
     Log::info('Bancame indexed');
     $models = Group::all();
     foreach ($models as $model) {
         $es->index(['index' => 'winwins', 'type' => 'groups', 'id' => $model->id, 'body' => $model->toArray()]);
     }
     Log::info('Groups indexed');
     $models = UserDetail::all();
     foreach ($models as $model) {
         $es->index(['index' => 'winwins', 'type' => 'users', 'id' => $model->id, 'body' => $model->toArray()]);
     }
     Log::info('Users indexed');
 }
开发者ID:centaurustech,项目名称:Bankame,代码行数:21,代码来源:ESIndexAllCommand.php


注:本文中的Elasticsearch\Client::index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。