Elastica\Type\Mapping::setParent PHP Method

setParent() public method

Set parent type.
public setParent ( string $type )
$type string Parent type
    public function setParent($type)
    {
        return $this->setParam('_parent', ['type' => $type]);
    }

Usage Example

 /**
  * @group functional
  */
 public function testHasParent()
 {
     $index = $this->_createIndex();
     $shopType = $index->getType('shop');
     $productType = $index->getType('product');
     $mapping = new Mapping();
     $mapping->setParent('shop');
     $productType->setMapping($mapping);
     $shopType->addDocuments(array(new Document('zurich', array('brand' => 'google')), new Document('london', array('brand' => 'apple'))));
     $doc1 = new Document(1, array('device' => 'chromebook'));
     $doc1->setParent('zurich');
     $doc2 = new Document(2, array('device' => 'macmini'));
     $doc2->setParent('london');
     $productType->addDocument($doc1);
     $productType->addDocument($doc2);
     $index->refresh();
     // All documents
     $parentQuery = new HasParent(new MatchAll(), $shopType->getName());
     $search = new Search($index->getClient());
     $results = $search->search($parentQuery);
     $this->assertEquals(2, $results->count());
     $match = new Match();
     $match->setField('brand', 'google');
     $parentQuery = new HasParent($match, $shopType->getName());
     $search = new Search($index->getClient());
     $results = $search->search($parentQuery);
     $this->assertEquals(1, $results->count());
     $result = $results->current();
     $data = $result->getData();
     $this->assertEquals($data['device'], 'chromebook');
 }
All Usage Examples Of Elastica\Type\Mapping::setParent