serializer = $serializer; } public function getURI(): string { $index = $this->index ?? null; $type = $this->type ?? null; if (isset($type)) { @trigger_error('Specifying types in urls has been deprecated', E_USER_DEPRECATED); } if (isset($index) && isset($type)) { return "/$index/$type/_msearch/template"; } if (isset($index)) { return "/$index/_msearch/template"; } return "/_msearch/template"; } public function getParamWhitelist(): array { return [ 'search_type', 'typed_keys', 'max_concurrent_searches', 'rest_total_hits_as_int', 'ccs_minimize_roundtrips' ]; } public function getMethod(): string { return isset($this->body) ? 'POST' : 'GET'; } public function setBody($body): MsearchTemplate { if (isset($body) !== true) { return $this; } if (is_array($body) === true || $body instanceof Traversable) { foreach ($body as $item) { $this->body .= $this->serializer->serialize($item) . "\n"; } } elseif (is_string($body)) { $this->body = $body; if (substr($body, -1) != "\n") { $this->body .= "\n"; } } else { throw new InvalidArgumentException("Body must be an array, traversable object or string"); } return $this; } }