Elastica\Aggregation\TopHits::setSource PHP Method

setSource() public method

Allows to control how the _source field is returned with every hit.
public setSource ( array | boolean $params )
$params array | boolean Fields to be returned or false to disable source
    public function setSource($params)
    {
        return $this->setParam('_source', $params);
    }

Usage Example

Example #1
0
 /**
  * @group functional
  */
 public function testAggregateWithLimitedSource()
 {
     $aggr = new TopHits('top_tag_hits');
     $aggr->setSource(array('title'));
     $resultDocs = array();
     $outerAggrResult = $this->getOuterAggregationResult($aggr);
     foreach ($outerAggrResult['buckets'] as $bucket) {
         foreach ($bucket['top_tag_hits']['hits']['hits'] as $doc) {
             $this->assertArrayHasKey('title', $doc['_source']);
             $this->assertArrayNotHasKey('tags', $doc['_source']);
             $this->assertArrayNotHasKey('last_activity_date', $doc['_source']);
         }
     }
 }