Exemplo n.º 1
0
 public function testBulkCreateTwice()
 {
     $this->createIndex();
     $doc1 = array('name' => 'test1' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000));
     $doc2 = array('name' => 'test2' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000));
     $doc3 = array('name' => 'test3' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000));
     $allDocs = [$doc1, $doc2, $doc3];
     $bulkIndexRequest = new BulkIndexRequest(ES_INDEX, self::TYPE, $this->getSerializer());
     $bulkIndexRequest->addDocument($doc1, 'doc1');
     $bulkIndexRequest->addDocument($doc2, 'doc2');
     $bulkIndexRequest->addDocument($doc3, 'doc3');
     /** @var BulkResponse $response */
     $response = $this->getClient()->send($bulkIndexRequest);
     $this->assertGreaterThanOrEqual(0, $response->took());
     $this->assertFalse($response->errors());
     $items = $response->getItems();
     $this->assertTrue(is_array($items));
     $this->assertCount(3, $items);
     foreach ($items as $key => $item) {
         $this->assertArrayHasKey(AbstractBulkIndexRequest::BULK_ACTION, $item);
         $this->assertSame(ES_INDEX, $item[AbstractBulkIndexRequest::BULK_ACTION]['_index']);
         $this->assertSame(self::TYPE, $item[AbstractBulkIndexRequest::BULK_ACTION]['_type']);
         $this->assertSame(1, $item[AbstractBulkIndexRequest::BULK_ACTION]['_version']);
         $this->assertSame(201, $item[AbstractBulkIndexRequest::BULK_ACTION]['status']);
         $doc = $this->getDocument(ES_INDEX, self::TYPE, $item[AbstractBulkIndexRequest::BULK_ACTION]['_id']);
         $this->assertEquals($allDocs[$key], $doc);
     }
 }
Exemplo n.º 2
0
 public function testAddAction()
 {
     $id = 'my-id';
     $doc = array('my' => 'doc');
     $serializedDoc = 'my-doc';
     $action = array(AbstractBulkIndexRequest::BULK_ACTION => array('_id' => $id, '_index' => self::INDEX, '_type' => self::TYPE));
     $this->serializer->expects($this->once())->method('serialize')->with($doc, array())->willReturn($serializedDoc);
     $this->request->addDocument($doc, $id);
     $expected = json_encode($action) . AbstractBulkIndexRequest::LINE_BREAK . $serializedDoc . AbstractBulkIndexRequest::LINE_BREAK;
     $result = $this->request->getBody();
     $this->assertSame($expected, $result);
 }