getName() public method

Returns the index name.
public getName ( ) : string
return string Index name
Example #1
0
 /**
  * Match a document to percolator queries
  *
  * @param  \Elastica\Document                                  $doc
  * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Not implemented yet
  * @return \Elastica\Response
  */
 public function matchDoc(Document $doc, $query = null)
 {
     $path = $this->_index->getName() . '/type/_percolate';
     $data = array('doc' => $doc->getData());
     $response = $this->getIndex()->getClient()->request($path, Request::GET, $data);
     $data = $response->getData();
     return $data['matches'];
 }
Example #2
0
 /**
  * Match a document to percolator queries
  *
  * @param  \Elastica\Document                                   $doc
  * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the percolator queries which
  *                                                                     are executed.
  * @param  string                                               $type
  * @return array With matching registered queries.
  */
 public function matchDoc(Document $doc, $query = null, $type = 'type')
 {
     $path = $this->_index->getName() . '/' . $type . '/_percolate';
     $data = array('doc' => $doc->getData());
     // Add query to filter the percolator queries which are executed.
     if ($query) {
         $query = Query::create($query);
         $data['query'] = $query->getQuery();
     }
     $response = $this->getIndex()->getClient()->request($path, Request::GET, $data);
     $data = $response->getData();
     return $data['matches'];
 }
 /**
  * Match a document to percolator queries
  *
  * @param  \Elastica\Document                                  $doc
  * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the data
  * @return \Elastica\Response
  */
 public function matchDoc(Document $doc, $query = null)
 {
     $path = $this->_index->getName() . '/type/_percolate';
     $data = array('doc' => $doc->getData());
     // Add query to filter results after percolation
     if ($query) {
         $query = Query::create($query);
         $data['query'] = $query->getQuery();
     }
     $response = $this->getIndex()->getClient()->request($path, Request::GET, $data);
     $data = $response->getData();
     return $data['matches'];
 }
Example #4
0
 /**
  * Percolating an existing document.
  *
  * @param string                                               $id
  * @param string                                               $type
  * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query  Query to filter the percolator queries which
  *                                                                     are executed.
  * @param array                                                $params Supports setting additional request body options to the percolate request.
  *                                                                     [ Percolator::EXTRA_FILTER,
  *                                                                     Percolator::EXTRA_QUERY,
  *                                                                     Percolator::EXTRA_SIZE,
  *                                                                     Percolator::EXTRA_TRACK_SCORES,
  *                                                                     Percolator::EXTRA_SORT,
  *                                                                     Percolator::EXTRA_FACETS,
  *                                                                     Percolator::EXTRA_AGGS,
  *                                                                     Percolator::EXTRA_HIGHLIGHT ]
  *
  * @return array With matching registered queries.
  */
 public function matchExistingDoc($id, $type, $query = null, $params = array())
 {
     $id = urlencode($id);
     $path = $this->_index->getName() . '/' . $type . '/' . $id . '/_percolate';
     $data = array();
     $this->_applyAdditionalRequestBodyOptions($params, $data);
     return $this->_percolate($path, $query, $data, $params);
 }
Example #5
0
 /**
  * @param \Elastica\Index $index
  * @param string $mappingName
  * @param array $mappingData
  *
  * @return void
  */
 protected function sendMapping(Index $index, $mappingName, array $mappingData)
 {
     $type = $index->getType($mappingName);
     $this->messenger->info(sprintf('Send mapping type "%s" (index: "%s")', $mappingName, $index->getName()));
     $mapping = new Mapping($type);
     foreach ($mappingData as $key => $value) {
         $mapping->setParam($key, $value);
     }
     $mapping->send();
 }
Example #6
0
 public function testIndicesFilter()
 {
     $filter = new Indices(new BoolNot(new Term(array("color" => "blue"))), array($this->_index1->getName()));
     $filter->setNoMatchFilter(new BoolNot(new Term(array("color" => "yellow"))));
     $query = new Query();
     $query->setPostFilter($filter);
     // search over the alias
     $index = $this->_getClient()->getIndex("indices_filter");
     $results = $index->search($query);
     // ensure that the proper docs have been filtered out for each index
     $this->assertEquals(5, $results->count());
     foreach ($results->getResults() as $result) {
         $data = $result->getData();
         $color = $data["color"];
         if ($result->getIndex() == $this->_index1->getName()) {
             $this->assertNotEquals("blue", $color);
         } else {
             $this->assertNotEquals("yellow", $color);
         }
     }
 }
 /**
  * @group functional
  */
 public function testSnapshotAndRestore()
 {
     $repositoryName = 'testrepo';
     $location = $this->_snapshotPath . 'backup2';
     // register the repository
     $response = $this->_snapshot->registerRepository($repositoryName, 'fs', array('location' => $location));
     $this->assertTrue($response->isOk());
     // create a snapshot of our test index
     $snapshotName = 'test_snapshot_1';
     $response = $this->_snapshot->createSnapshot($repositoryName, $snapshotName, array('indices' => $this->_index->getName()), true);
     // ensure that the snapshot was created properly
     $this->assertTrue($response->isOk());
     $this->assertArrayHasKey('snapshot', $response->getData());
     $data = $response->getData();
     $this->assertContains($this->_index->getName(), $data['snapshot']['indices']);
     $this->assertEquals(1, sizeof($data['snapshot']['indices']));
     // only the specified index should be present
     $this->assertEquals($snapshotName, $data['snapshot']['snapshot']);
     // retrieve data regarding the snapshot
     $response = $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
     $this->assertContains($this->_index->getName(), $response['indices']);
     // delete our test index
     $this->_index->delete();
     // restore the index from our snapshot
     $response = $this->_snapshot->restoreSnapshot($repositoryName, $snapshotName, array(), true);
     $this->assertTrue($response->isOk());
     $this->_index->refresh();
     $this->_index->optimize();
     // ensure that the index has been restored
     $count = $this->_index->getType('test')->count();
     $this->assertEquals(sizeof($this->_docs), $count);
     // delete the snapshot
     $response = $this->_snapshot->deleteSnapshot($repositoryName, $snapshotName);
     $this->assertTrue($response->isOk());
     // ensure that the snapshot has been deleted
     $this->setExpectedException('Elastica\\Exception\\NotFoundException');
     $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
 }
 public function testSnapshotAndRestore()
 {
     $repositoryName = "test_repository";
     $location = "/tmp/{$repositoryName}";
     // register the repository
     $response = $this->_snapshot->registerRepository($repositoryName, "fs", array("location" => $location));
     $this->assertTrue($response->isOk());
     // create a snapshot of our test index
     $snapshotName = "test_snapshot_1";
     $response = $this->_snapshot->createSnapshot($repositoryName, $snapshotName, array("indices" => $this->_index->getName()), true);
     // ensure that the snapshot was created properly
     $this->assertTrue($response->isOk());
     $this->assertArrayHasKey("snapshot", $response->getData());
     $data = $response->getData();
     $this->assertContains($this->_index->getName(), $data["snapshot"]["indices"]);
     $this->assertEquals(1, sizeof($data["snapshot"]["indices"]));
     // only the specified index should be present
     $this->assertEquals($snapshotName, $data["snapshot"]["snapshot"]);
     // retrieve data regarding the snapshot
     $response = $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
     $this->assertContains($this->_index->getName(), $response["indices"]);
     // delete our test index
     $this->_index->delete();
     // restore the index from our snapshot
     $response = $this->_snapshot->restoreSnapshot($repositoryName, $snapshotName, array(), true);
     $this->assertTrue($response->isOk());
     $this->_index->refresh();
     $this->_index->optimize();
     // ensure that the index has been restored
     $count = $this->_index->getType("test")->count();
     $this->assertEquals(sizeof($this->_docs), $count);
     // delete the snapshot
     $response = $this->_snapshot->deleteSnapshot($repositoryName, $snapshotName);
     $this->assertTrue($response->isOk());
     // ensure that the snapshot has been deleted
     $this->setExpectedException('Elastica\\Exception\\NotFoundException');
     $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
 }
Example #9
0
 /**
  * @group unit
  */
 public function testToArrayFromReference()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $type = new Type($index, 'helloworld');
     $field = 'image';
     $query = new Image();
     $query->setFieldFeature($field, 'CEDD');
     $query->setFieldHash($field, 'BIT_SAMPLING');
     $query->setFieldBoost($field, 100);
     $query->setImageByReference($field, $index->getName(), $type->getName(), 10);
     $jsonString = '{"image":{"image":{"feature":"CEDD","hash":"BIT_SAMPLING","boost":100,"index":"test","type":"helloworld","id":10,"path":"image"}}}';
     $this->assertEquals($jsonString, json_encode($query->toArray()));
 }
 /**
  * Get health information about the index
  * @return array Response data array
  */
 private function getHealth()
 {
     while (true) {
         $indexName = $this->index->getName();
         $path = "_cluster/health/{$indexName}";
         $response = $this->index->getClient()->request($path);
         if ($response->hasError()) {
             $this->error('Error fetching index health but going to retry.  Message: ' . $response->getError());
             sleep(1);
             continue;
         }
         return $response->getData();
     }
 }
 /**
  * @param Index $index
  * @param \ElasticaConnection $connection
  * @param Type[] $types
  * @param Type[] $oldTypes
  * @param int $shardCount
  * @param string $replicaCount
  * @param int $connectionTimeout
  * @param array $mergeSettings
  * @param array $mappingConfig
  * @param Maintenance $out
  */
 public function __construct(Index $index, \ElasticaConnection $connection, array $types, array $oldTypes, $shardCount, $replicaCount, $connectionTimeout, array $mergeSettings, array $mappingConfig, Maintenance $out = null)
 {
     // @todo: this constructor has too many arguments - refactor!
     $this->index = $index;
     $this->client = $this->index->getClient();
     $this->specificIndexName = $this->index->getName();
     $this->connection = $connection;
     $this->types = $types;
     $this->oldTypes = $oldTypes;
     $this->shardCount = $shardCount;
     $this->replicaCount = $replicaCount;
     $this->connectionTimeout = $connectionTimeout;
     $this->mergeSettings = $mergeSettings;
     $this->mappingConfig = $mappingConfig;
     $this->out = $out;
 }
Example #12
0
 protected function _waitForAllocation(Index $index)
 {
     do {
         $state = $index->getClient()->getCluster()->getState();
         $indexState = $state['routing_table']['indices'][$index->getName()];
         $allocated = true;
         foreach ($indexState['shards'] as $shard) {
             if ($shard[0]['state'] != 'STARTED') {
                 $allocated = false;
             }
         }
     } while (!$allocated);
 }
 /**
  * Constructor.
  *
  * @param array $indexesByName
  * @param Index $defaultIndex
  */
 public function __construct(array $indexesByName, Index $defaultIndex)
 {
     $this->indexesByName = $indexesByName;
     $this->defaultIndexName = $defaultIndex->getName();
 }
 /**
  * Percolating an existing document
  *
  * @param  string $id
  * @param  string $type
  * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the percolator queries which
  *                                                                     are executed.
  * @param  array  $params
  * @return array With matching registered queries.
  */
 public function matchExistingDoc($id, $type, $query = null, $params = array())
 {
     $id = urlencode($id);
     $path = $this->_index->getName() . '/' . $type . '/' . $id . '/_percolate';
     return $this->_percolate($path, $query, array(), $params);
 }