Esempio n. 1
0
 /**
  * Convert a log message into an Elastica Document
  *
  * @param  array $record Log message
  * @return Document
  */
 protected function getDocument($record)
 {
     $document = new Document();
     $document->setData($record);
     $document->setType($this->type);
     $document->setIndex($this->index);
     return $document;
 }
Esempio n. 2
0
 public function getDocument($record)
 {
     $user = $this->token->getToken()->getUser();
     $record['extra']['user'] = $user->getId();
     $document = new Document();
     $document->setData($record);
     $document->setType($this->type);
     $document->setIndex($this->index);
     return $document;
 }
Esempio n. 3
0
 /**
  * @group unit
  */
 public function testSetIndex()
 {
     $document = new Document();
     $document->setIndex('index2');
     $document->setType('type2');
     $this->assertEquals('index2', $document->getIndex());
     $this->assertEquals('type2', $document->getType());
     $index = new Index($this->_getClient(), 'index');
     $document->setIndex($index);
     $this->assertEquals('index', $document->getIndex());
     $this->assertEquals('type2', $document->getType());
 }
 /**
  * {@inheritdoc}
  * @see \Silex\ServiceProviderInterface::register()
  */
 public function register(Application $app)
 {
     $app['elastic.client'] = $app->share(function () use($app) {
         $config = $app['config']('elastic.connection', array());
         $client = new Client($config);
         return $client;
     });
     $app['elastic.bulk'] = $app->protect(function ($index) use($app) {
         $bulk = new Bulk($app['elastic.client']);
         $bulk->setIndex($index);
         return $bulk;
     });
     $app['elastic.document'] = $app->protect(function ($type, array $data) {
         $document = new Document();
         $document->setType($type);
         $document->setData($data);
         return $document;
     });
 }
Esempio n. 5
0
 /**
  * @param string $id
  * @param array|string $data
  * @return Document
  */
 public function createDocument($id = '', $data = array())
 {
     $document = new Document($id, $data);
     $document->setType($this);
     return $document;
 }
Esempio n. 6
0
 /**
  * Test bulk operations on Type.
  *
  * @group functional
  */
 public function testBulkType()
 {
     $type = $this->_getClient()->getIndex('cryptocurrencies')->getType('altcoin');
     $liteCoin = new Document(1, array('name' => 'litecoin'));
     $nameCoin = new Document(2, array('name' => 'namecoin'));
     $type->addDocuments(array($liteCoin, $nameCoin));
     $this->assertEquals('litecoin', $type->getDocument(1)->get('name'));
     $this->assertEquals('namecoin', $type->getDocument(2)->get('name'));
     $type->updateDocuments(array(new Document(1, array('name' => 'LiteCoin')), new Document(2, array('name' => 'NameCoin'))));
     $this->assertEquals('LiteCoin', $type->getDocument(1)->get('name'));
     $this->assertEquals('NameCoin', $type->getDocument(2)->get('name'));
     $nameCoin->setType(null);
     // Make sure the type gets set properly if missing
     $type->deleteDocuments(array($liteCoin, $nameCoin));
     $this->setExpectedException('Elastica\\Exception\\NotFoundException');
     $type->getDocument(1);
     $type->getDocument(2);
 }