public function testGetOptions() { $document = new Document(); $document->setIndex('index'); $document->setOpType('create'); $document->setParent('2'); $document->setId(1); $options = $document->getOptions(array('index', 'type', 'id', 'parent')); $this->assertInternalType('array', $options); $this->assertEquals(3, count($options)); $this->assertArrayHasKey('index', $options); $this->assertArrayHasKey('id', $options); $this->assertArrayHasKey('parent', $options); $this->assertEquals('index', $options['index']); $this->assertEquals(1, $options['id']); $this->assertEquals('2', $options['parent']); $this->assertArrayNotHasKey('type', $options); $this->assertArrayNotHasKey('op_type', $options); $this->assertArrayNotHasKey('_index', $options); $this->assertArrayNotHasKey('_id', $options); $this->assertArrayNotHasKey('_parent', $options); $options = $document->getOptions(array('parent', 'op_type', 'percolate'), true); $this->assertInternalType('array', $options); $this->assertEquals(2, count($options)); $this->assertArrayHasKey('_parent', $options); $this->assertArrayHasKey('_op_type', $options); $this->assertEquals('2', $options['_parent']); $this->assertEquals('create', $options['_op_type']); $this->assertArrayNotHasKey('percolate', $options); $this->assertArrayNotHasKey('op_type', $options); $this->assertArrayNotHasKey('parent', $options); }
/** * 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; }
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; }
/** * ElasticaHelper constructor. * * @param string $gameVersion * @param string $indexName * @param int $magicNumber */ public function __construct($gameVersion, $indexName, $magicNumber = 500) { $docPrototype = new Document(); $docPrototype->setIndex($indexName)->setType('user:'******'/elastica.error'); }; }
protected function deleteDocuments() { dump(__METHOD__); require_once __DIR__ . '/UserProvider.php'; $userList = (new \UserProvider())->listUser(); $documents = array_map(function (User $user) { $document = new Document($user->snsid); $document->setIndex($this->getIndexName())->setType($this->getTypeName()); return $document; }, $userList); $responseSet = $this->getClient()->getIndex($this->getIndexName())->deleteDocuments($documents); foreach ($responseSet as $response) { $data = $response->getData(); $this->assertEquals(3, $data['_version']); $action = $response->getAction(); $this->assertEquals('delete', $action->getOpType()); } }
/** * Test bulk operations on Index. * * @group functional */ public function testBulkIndex() { $index = $this->_getClient()->getIndex('cryptocurrencies'); $anonCoin = new Document(1, array('name' => 'anoncoin'), 'altcoin'); $ixCoin = new Document(2, array('name' => 'ixcoin'), 'altcoin'); $index->addDocuments(array($anonCoin, $ixCoin)); $this->assertEquals('anoncoin', $index->getType('altcoin')->getDocument(1)->get('name')); $this->assertEquals('ixcoin', $index->getType('altcoin')->getDocument(2)->get('name')); $index->updateDocuments(array(new Document(1, array('name' => 'AnonCoin'), 'altcoin'), new Document(2, array('name' => 'iXcoin'), 'altcoin'))); $this->assertEquals('AnonCoin', $index->getType('altcoin')->getDocument(1)->get('name')); $this->assertEquals('iXcoin', $index->getType('altcoin')->getDocument(2)->get('name')); $ixCoin->setIndex(null); // Make sure the index gets set properly if missing $index->deleteDocuments(array($anonCoin, $ixCoin)); $this->setExpectedException('Elastica\\Exception\\NotFoundException'); $index->getType('altcoin')->getDocument(1); $index->getType('altcoin')->getDocument(2); }
/** * Factory constructor. */ public function __construct() { $docPrototype = new Document(); $docPrototype->setIndex(ELASTIC_SEARCH_INDEX)->setType('user:unknown'); $this->documentFactory = new DocumentFactory($docPrototype); }
/** * */ public static function setUpBeforeClass() { require_once __DIR__ . '/../ES/UserProvider.php'; self::$documentPrototype = new Document(); self::$documentPrototype->setIndex('farm')->setType('user:tw'); }