setRouting() публичный Метод

public setRouting ( string $routing )
$routing string
Пример #1
0
 /**
  * @group unit
  */
 public function testAction()
 {
     $action = new Action();
     $this->assertEquals('index', $action->getOpType());
     $this->assertFalse($action->hasSource());
     $expected = '{"index":{}}' . "\n";
     $this->assertEquals($expected, $action->toString());
     $action->setIndex('index');
     $expected = '{"index":{"_index":"index"}}' . "\n";
     $this->assertEquals($expected, $action->toString());
     $action->setType('type');
     $expected = '{"index":{"_index":"index","_type":"type"}}' . "\n";
     $this->assertEquals($expected, $action->toString());
     $action->setId(1);
     $expected = '{"index":{"_index":"index","_type":"type","_id":1}}' . "\n";
     $this->assertEquals($expected, $action->toString());
     $action->setRouting(1);
     $expected = '{"index":{"_index":"index","_type":"type","_id":1,"_routing":1}}' . "\n";
     $this->assertEquals($expected, $action->toString());
     $client = $this->_getClient();
     $index = new Index($client, 'index2');
     $type = new Type($index, 'type2');
     $action->setIndex($index);
     $expected = '{"index":{"_index":"index2","_type":"type","_id":1,"_routing":1}}' . "\n";
     $this->assertEquals($expected, $action->toString());
     $action->setType($type);
     $expected = '{"index":{"_index":"index2","_type":"type2","_id":1,"_routing":1}}' . "\n";
     $this->assertEquals($expected, $action->toString());
     $action->setSource(array('user' => 'name'));
     $expected = '{"index":{"_index":"index2","_type":"type2","_id":1,"_routing":1}}' . "\n";
     $expected .= '{"user":"******"}' . "\n";
     $this->assertEquals($expected, $action->toString());
     $this->assertTrue($action->hasSource());
     $this->assertFalse(Action::isValidOpType('foo'));
     $this->assertTrue(Action::isValidOpType('delete'));
 }
Пример #2
0
 /**
  * Deletes documents with the given ids, index, type from the index
  *
  * @throws \Elastica\Exception\InvalidException
  * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
  *
  * @param  array                      $ids     Document ids
  * @param  string|\Elastica\Index     $index   Index name
  * @param  string|\Elastica\Type      $type    Type of documents
  * @param  string|false               $routing Optional routing key for all ids
  * @return \Elastica\Bulk\ResponseSet Response  object
  */
 public function deleteIds(array $ids, $index, $type, $routing = false)
 {
     if (empty($ids)) {
         throw new InvalidException('Array has to consist of at least one id');
     }
     $bulk = new Bulk($this);
     $bulk->setIndex($index);
     $bulk->setType($type);
     foreach ($ids as $id) {
         $action = new Action(Action::OP_TYPE_DELETE);
         $action->setId($id);
         if (!empty($routing)) {
             $action->setRouting($routing);
         }
         $bulk->addAction($action);
     }
     return $bulk->send();
 }