Elastica\Type::setMapping PHP Method

setMapping() public method

Sets value type mapping for this type.
public setMapping ( Mapping | array $mapping ) : Response
$mapping Elastica\Type\Mapping | array Elastica\Type\MappingType object or property array with all mappings
return Response
    public function setMapping($mapping)
    {
        $mapping = Mapping::create($mapping);
        $mapping->setType($this);
        return $mapping->send();
    }

Usage Example

 protected function setUp()
 {
     parent::setUp();
     $this->index = $this->_createIndex('test_functionscore');
     $this->type = $this->index->getType('test');
     $this->type->setMapping(array('name' => array('type' => 'string', 'index' => 'not_analyzed'), 'location' => array('type' => 'geo_point'), 'price' => array('type' => 'float')));
     $this->type->addDocument(new Document(1, array('name' => "Mr. Frostie's", 'location' => array('lat' => 32.799605, 'lon' => -117.243027), 'price' => 4.5)));
     $this->type->addDocument(new Document(2, array('name' => "Miller's Field", 'location' => array('lat' => 32.795964, 'lon' => -117.255028), 'price' => 9.5)));
     $this->index->refresh();
 }
All Usage Examples Of Elastica\Type::setMapping