diff --git a/src/Query/AbstractQuery.php b/src/Query/AbstractQuery.php index d594687846..ab8a7af829 100644 --- a/src/Query/AbstractQuery.php +++ b/src/Query/AbstractQuery.php @@ -19,4 +19,13 @@ protected function _getBaseName() return Util::toSnakeCase($shortName); } + + public function isNotAssociativeArray(array $arr) + { + if ([] === $arr) { + return true; + } + + return \array_keys($arr) === \range(0, \count($arr) - 1); + } } diff --git a/src/Query/BoolQuery.php b/src/Query/BoolQuery.php index a7d56e28a6..010db25053 100644 --- a/src/Query/BoolQuery.php +++ b/src/Query/BoolQuery.php @@ -111,6 +111,10 @@ protected function _addQuery(string $type, $args): self throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery'); } + if (\is_array($args) && $this->isNotAssociativeArray($args)) { + throw new InvalidException('Invalid parameter. The array must be an associative array.'); + } + return $this->addParam($type, $args); } }