diff --git a/src/Elasticsearch/Endpoints/TermVectors.php b/src/Elasticsearch/Endpoints/TermVectors.php index 5ac9569e3..199491d1a 100644 --- a/src/Elasticsearch/Endpoints/TermVectors.php +++ b/src/Elasticsearch/Endpoints/TermVectors.php @@ -39,27 +39,31 @@ public function setBody($body) public function getURI() { if (isset($this->index) !== true) { - throw new Exceptions\RuntimeException( - 'index is required for TermVectors' - ); - } - if (isset($this->type) !== true) { - throw new Exceptions\RuntimeException( - 'type is required for TermVectors' - ); - } - if (isset($this->id) !== true) { - throw new Exceptions\RuntimeException( - 'id is required for TermVectors' - ); - } + throw new Exceptions\RuntimeException( + 'index is required for TermVectors' + ); + } + if (isset($this->type) !== true) { + throw new Exceptions\RuntimeException( + 'type is required for TermVectors' + ); + } + if (isset($this->id) !== true && isset($this->body['doc']) !== true) { + throw new Exceptions\RuntimeException( + 'id or doc is required for TermVectors' + ); + } + + $index = $this->index; + $type = $this->type; + $id = $this->id; + $uri = "/$index/$type/_termvectors"; - $index = $this->index; - $type = $this->type; - $id = $this->id; - $uri = "/$index/$type/$id/_termvectors"; + if ($id !== null) { + $uri = "/$index/$type/$id/_termvectors"; + } - return $uri; + return $uri; } /**