public function testIndexMappingForParent() { $type = $this->getMockElasticaType(); $this->indexConfigsByName['parent']['index']->expects($this->once())->method('getType')->with('a')->will($this->returnValue($type)); $type->expects($this->once())->method('delete'); $mapping = Mapping::create($this->indexConfigsByName['parent']['config']['mappings']['a']['properties']); $mapping->setParam('_parent', array('type' => 'b')); $type->expects($this->once())->method('setMapping')->with($mapping); $resetter = new Resetter($this->indexConfigsByName); $resetter->resetIndexType('parent', 'a'); }
/** * create type mapping object * * @param array $indexConfig * @return Mapping */ protected function createMapping($indexConfig) { $mapping = Mapping::create($indexConfig['properties']); $mappingSpecialFields = array('_uid', '_id', '_source', '_all', '_analyzer', '_boost', '_routing', '_index', '_size', '_timestamp', '_ttl', 'dynamic_templates'); foreach ($mappingSpecialFields as $specialField) { if (isset($indexConfig[$specialField])) { $mapping->setParam($specialField, $indexConfig[$specialField]); } } if (isset($indexConfig['_parent'])) { $mapping->setParam('_parent', array('type' => $indexConfig['_parent']['type'])); } return $mapping; }
public function testExcludeFileSource() { $indexMapping = array('file' => array('type' => 'attachment', 'store' => 'yes'), 'text' => array('type' => 'string', 'store' => 'yes'), 'title' => array('type' => 'string', 'store' => 'yes')); $indexParams = array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)); $index = $this->_createIndex(); $type = new Type($index, 'content'); $mapping = Mapping::create($indexMapping); $mapping->setSource(array('excludes' => array('file'))); $mapping->setType($type); $index->create($indexParams, true); $type->setMapping($mapping); $docId = 1; $text = 'Basel World'; $title = 'No Title'; $doc1 = new Document($docId); $doc1->addFile('file', BASE_PATH . '/data/test.docx'); $doc1->set('text', $text); $doc1->set('title', $title); $type->addDocument($doc1); // Optimization necessary, as otherwise source still in realtime get $index->optimize(); $data = $type->getDocument($docId)->getData(); $this->assertEquals($data['title'], $title); $this->assertEquals($data['text'], $text); $this->assertFalse(isset($data['file'])); }
/** * Sets value type mapping for this type * * @param \Elastica\Type\Mapping|array $mapping Elastica\Type\MappingType object or property array with all mappings * @return \Elastica\Response */ public function setMapping($mapping) { $mapping = Mapping::create($mapping); $mapping->setType($this); return $mapping->send(); }
/** * Sets value type mapping for this type. * * @param \Elastica\Type\Mapping|array $mapping Elastica\Type\MappingType object or property array with all mappings * @param argArray = array('_timestamp' => array('enabled' => true, 'store' => 'yes'), '_ttl' => array('enabled' => true)); * * @return \Elastica\Response */ public function setMapping($mapping, $argArray = NULL) { $mapping = Mapping::create($mapping); $mapping->setType($this); if (isset($argArray) && is_array($argArray)) { foreach ($argArray as $key => $valueArr) { $mapping->setParam($key, $valueArr); } } return $mapping->send(); }