Beispiel #1
0
 public function testGet()
 {
     $o_mapping = new ElasticSearch\Mapping();
     $va_mapping = $o_mapping->get();
 }
Beispiel #2
0
 public function testAddTypeConstrainedMapping()
 {
     $mapping = new \ElasticSearch\Mapping(array('tweet' => array('type' => 'string')), array('type' => 'tweet'));
     $exported = $mapping->export();
     $this->assert->array($exported)->isNotEmpty()->hasKey('properties')->notHasKey('type');
 }
Beispiel #3
0
 /**
  * Refresh ElasticSearch mapping if necessary
  * @param bool $pb_force force refresh if set to true [default is false]
  */
 public function refreshMapping($pb_force = false)
 {
     $o_mapping = new ElasticSearch\Mapping();
     if ($o_mapping->needsRefresh() || $pb_force) {
         try {
             if (!$this->getClient()->indices()->exists(array('index' => $this->getIndexName()))) {
                 $this->getClient()->indices()->create(array('index' => $this->getIndexName()));
             }
             // if we don't refresh() after creating, ES throws a IndexPrimaryShardNotAllocatedException
             // @see https://groups.google.com/forum/#!msg/elasticsearch/hvMhx162E-A/on-3druwehwJ
             // -- seems to be fixed in 2.x
             //$this->getClient()->indices()->refresh(array('index' => $this->getIndexName()));
         } catch (Elasticsearch\Common\Exceptions\BadRequest400Exception $e) {
             // noop -- the exception happens when the index already exists, which is good
         }
         $this->setIndexSettings();
         foreach ($o_mapping->get() as $vs_table => $va_config) {
             $this->getClient()->indices()->putMapping(array('index' => $this->getIndexName(), 'type' => $vs_table, 'body' => array($vs_table => $va_config), 'update_all_types' => true));
         }
         // resets the mapping cache key so that needsRefresh() returns false for 24h
         $o_mapping->ping();
     }
 }