1<?php 2 3namespace Elastica\Aggregation; 4 5/** 6 * Class Percentiles. 7 * 8 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html 9 */ 10class Percentiles extends AbstractSimpleAggregation 11{ 12 /** 13 * @param string $name the name of this aggregation 14 * @param string $field the field on which to perform this aggregation 15 */ 16 public function __construct(string $name, string $field = null) 17 { 18 parent::__construct($name); 19 20 if (null !== $field) { 21 $this->setField($field); 22 } 23 } 24 25 /** 26 * Set compression parameter. 27 * 28 * @param float $value 29 * 30 * @return $this 31 */ 32 public function setCompression(float $value): self 33 { 34 $compression = ['compression' => $value]; 35 36 return $this->setParam('tdigest', $compression); 37 } 38 39 /** 40 * Set hdr parameter. 41 * 42 * @param string $key 43 * @param float $value 44 * 45 * @return $this 46 */ 47 public function setHdr(string $key, float $value): self 48 { 49 $compression = [$key => $value]; 50 51 return $this->setParam('hdr', $compression); 52 } 53 54 /** 55 * the keyed flag is set to true which associates a unique string 56 * key with each bucket and returns the ranges as a hash 57 * rather than an array. 58 * 59 * @param bool $keyed 60 * 61 * @return $this 62 */ 63 public function setKeyed(bool $keyed = true): self 64 { 65 return $this->setParam('keyed', $keyed); 66 } 67 68 /** 69 * Set which percents must be returned. 70 * 71 * @param float[] $percents 72 * 73 * @return $this 74 */ 75 public function setPercents(array $percents): self 76 { 77 return $this->setParam('percents', $percents); 78 } 79 80 /** 81 * Add yet another percent to result. 82 * 83 * @param float $percent 84 * 85 * @return $this 86 */ 87 public function addPercent(float $percent): self 88 { 89 return $this->addParam('percents', $percent); 90 } 91 92 /** 93 * Defines how documents that are missing a value should 94 * be treated. 95 * 96 * @param float $missing 97 * 98 * @return $this 99 */ 100 public function setMissing(float $missing): self 101 { 102 return $this->setParam('missing', $missing); 103 } 104} 105