Elastica\QueryBuilder\DSL\Aggregation::date_histogram PHP 메소드

date_histogram() 공개 메소드

date histogram aggregation.
public date_histogram ( string $name, string $field, integer $interval ) : DateHistogram
$name string the name of this aggregation
$field string the name of the field on which to perform the aggregation
$interval integer the interval by which documents will be bucketed
리턴 Elastica\Aggregation\DateHistogram
    public function date_histogram($name, $field, $interval)
    {
        return new DateHistogram($name, $field, $interval);
    }

Usage Example

예제 #1
0
 /**
  * @param string $term
  * @param string $value
  * @param int    $size
  *
  * @return \Elastica\ResultSet
  */
 public function termQuery($term, $value, $size = 30)
 {
     $_agg = new Aggregation();
     $_facet = $_agg->date_histogram('occurred_on', '@timestamp', ElkIntervals::DAY);
     //        $_facet = new DateHistogram('occurred_on');
     //        $_facet->setField('@timestamp');
     //        $_facet->setInterval('day');
     $_query = new Query();
     $_query->setSize($size);
     $_query->setSort(['@timestamp']);
     //	Filter for term
     $_filter = new Prefix($term, $value);
     $_and = new Bool();
     $_and->addMust($_filter);
     $_query->setPostFilter($_and);
     $_query->addAggregation($_facet);
     $_results = $this->_doSearch($_query);
     return $_results;
 }