| @@ 21-34 (lines=14) @@ | ||
| 18 | * |
|
| 19 | * @return $this |
|
| 20 | */ |
|
| 21 | public function setValue(string $field, $missing = null) |
|
| 22 | { |
|
| 23 | if ($this->hasParam('value') && isset($this->getParam('value')['script'])) { |
|
| 24 | throw new InvalidException('Weighted Average aggregation with a value mixing field and script is not possible.'); |
|
| 25 | } |
|
| 26 | ||
| 27 | $value = ['field' => $field]; |
|
| 28 | ||
| 29 | if (null !== $missing) { |
|
| 30 | $value['missing'] = $missing; |
|
| 31 | } |
|
| 32 | ||
| 33 | return $this->setParam('value', $value); |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Set the value as a script for this aggregation. |
|
| @@ 57-70 (lines=14) @@ | ||
| 54 | * |
|
| 55 | * @return $this |
|
| 56 | */ |
|
| 57 | public function setWeight(string $field, $missing = null) |
|
| 58 | { |
|
| 59 | if ($this->hasParam('weight') && isset($this->getParam('weight')['script'])) { |
|
| 60 | throw new InvalidException('Weighted Average aggregation with a weight mixing field and script is not possible.'); |
|
| 61 | } |
|
| 62 | ||
| 63 | $weight = ['field' => $field]; |
|
| 64 | ||
| 65 | if (null !== $missing) { |
|
| 66 | $weight['missing'] = $missing; |
|
| 67 | } |
|
| 68 | ||
| 69 | return $this->setParam('weight', $weight); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * Set the weight as a script for this aggregation. |
|