diff --git a/src/Query.php b/src/Query.php index 525203e..a04bf7f 100755 --- a/src/Query.php +++ b/src/Query.php @@ -875,12 +875,25 @@ public function response($scroll_id = NULL) } /** - * Get the count of results + * Get the count of result * @return mixed */ public function count() { - return $this->get()->total; + + $query = $this->query(); + + // Remove unsupported count query keys + + unset( + $query["size"], + $query["from"], + $query["body"]["_source"], + $query["body"]["sort"] + ); + + return $this->connection->count($query)["count"]; + } @@ -981,12 +994,15 @@ public function insert($data, $_id = NULL) } $parameters = [ - "index" => $this->getIndex(), "body" => $data, 'client' => ['ignore' => $this->ignores] ]; - if($type = $this->getType()){ + if ($index = $this->getIndex()) { + $parameters["index"] = $index; + } + + if ($type = $this->getType()) { $parameters["type"] = $type; } @@ -1054,13 +1070,16 @@ public function update($data, $_id = NULL) } $parameters = [ - "index" => $this->getIndex(), "id" => $this->_id, "body" => ['doc' => $data], 'client' => ['ignore' => $this->ignores] ]; - if($type = $this->getType()){ + if ($index = $this->getIndex()) { + $parameters["index"] = $index; + } + + if ($type = $this->getType()) { $parameters["type"] = $type; } @@ -1110,8 +1129,6 @@ public function script($script, $params = []) { $parameters = [ - "index" => $this->getIndex(), - "type" => $this->getType(), "id" => $this->_id, "body" => [ "script" => [ @@ -1122,6 +1139,14 @@ public function script($script, $params = []) 'client' => ['ignore' => $this->ignores] ]; + if ($index = $this->getIndex()) { + $parameters["index"] = $index; + } + + if ($type = $this->getType()) { + $parameters["type"] = $type; + } + return (object)$this->connection->update($parameters); } @@ -1139,12 +1164,18 @@ public function delete($_id = NULL) } $parameters = [ - "index" => $this->getIndex(), - "type" => $this->getType(), "id" => $this->_id, 'client' => ['ignore' => $this->ignores] ]; + if ($index = $this->getIndex()) { + $parameters["index"] = $index; + } + + if ($type = $this->getType()) { + $parameters["type"] = $type; + } + return (object)$this->connection->delete($parameters); }