Elastica\Index::addAlias PHP Method

addAlias() public method

Adds an alias to the current index.
public addAlias ( string $name, boolean $replace = false ) : Response
$name string Alias name
$replace boolean OPTIONAL If set, an existing alias will be replaced
return Response Response
    public function addAlias($name, $replace = false)
    {
        $path = '_aliases';
        $data = ['actions' => []];
        if ($replace) {
            $status = new Status($this->getClient());
            foreach ($status->getIndicesWithAlias($name) as $index) {
                $data['actions'][] = ['remove' => ['index' => $index->getName(), 'alias' => $name]];
            }
        }
        $data['actions'][] = ['add' => ['index' => $this->getName(), 'alias' => $name]];
        return $this->getClient()->request($path, Request::POST, $data);
    }

Usage Example

Example #1
0
 protected function setUp()
 {
     parent::setUp();
     $this->_index1 = $this->_createIndex('indices_filter_1');
     $this->_index2 = $this->_createIndex('indices_filter_2');
     $this->_index1->addAlias("indices_filter");
     $this->_index2->addAlias("indices_filter");
     $docs = array(new Document("1", array("color" => "blue")), new Document("2", array("color" => "green")), new Document("3", array("color" => "blue")), new Document("4", array("color" => "yellow")));
     $this->_index1->getType("test")->addDocuments($docs);
     $this->_index2->getType("test")->addDocuments($docs);
     $this->_index1->refresh();
     $this->_index2->refresh();
 }
All Usage Examples Of Elastica\Index::addAlias