diff --git a/Aggregation/PercentilesAggregation.php b/Aggregation/PercentilesAggregation.php
index e73496acab8ca2b45bde51e1f32cc6f173d10b8c..8aa9e1e847bc910bc476267c91e2b7f73fb5a6fb 100644
--- a/Aggregation/PercentilesAggregation.php
+++ b/Aggregation/PercentilesAggregation.php
@@ -77,24 +77,32 @@ class PercentilesAggregation extends AbstractAggregation
      */
     public function getArray()
     {
-        $out = [];
+        $out = array_filter(
+            [
+                'compression' => $this->getCompression(),
+                'percents' => $this->getPercents(),
+                'field' => $this->getField(),
+                'script' => $this->getScript(),
+            ],
+            function ($val) {
+                return ($val || is_numeric($val));
+            }
+        );
+
+        $this->isRequiredParametersSet($out);
 
-        if ($this->getField()) {
-            $out['field'] = $this->getField();
-        } elseif ($this->getScript()) {
-            $out['script'] = $this->getScript();
-        } else {
-            throw new \LogicException('Percentiles aggregation must have field or script set.');
-        }
-
-        if ($this->getCompression()) {
-            $out['compression'] = $this->getCompression();
-        }
+        return $out;
+    }
 
-        if ($this->getPercents()) {
-            $out['percents'] = $this->getPercents();
+    /**
+     * @param array $a
+     *
+     * @throws \LogicException
+     */
+    private function isRequiredParametersSet($a)
+    {
+        if (!array_key_exists('field', $a) && !array_key_exists('script', $a)) {
+            throw new \LogicException('Percentiles aggregation must have field or script set.');
         }
-
-        return $out;
     }
 }