addRange() public method

Add a range to this aggregation.
public addRange ( integer | float $fromValue = null, integer | float $toValue = null, string $key = null )
$fromValue integer | float low end of this range, exclusive (greater than or equal to)
$toValue integer | float high end of this range, exclusive (less than)
$key string customized key value
 /**
  * @group unit
  */
 public function testRangeAggregationWithKey()
 {
     $agg = new Range('range');
     $agg->setField('price');
     $agg->addRange(null, 50, 'cheap');
     $agg->addRange(50, 100, 'average');
     $agg->addRange(100, null, 'expensive');
     $expected = array('range' => array('field' => 'price', 'ranges' => array(array('to' => 50, 'key' => 'cheap'), array('from' => 50, 'to' => 100, 'key' => 'average'), array('from' => 100, 'key' => 'expensive'))));
     $this->assertEquals($expected, $agg->toArray());
 }
 public function testRangeAggregation()
 {
     $agg = new Range("range");
     $agg->setField("price");
     $agg->addRange(1.5, 5);
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_index->search($query)->getAggregation("range");
     $this->assertEquals(2, $results['buckets'][0]['doc_count']);
 }