Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save skowron-line/c48704ebe850b0f7f34c7bac2b5d6ee6 to your computer and use it in GitHub Desktop.
Save skowron-line/c48704ebe850b0f7f34c7bac2b5d6ee6 to your computer and use it in GitHub Desktop.
public function byId(string $id)
{
$query = [
'source' => [
'query' => [
'query_string' => [
'fields' => ['id'],
'query' => $id,
],
],
],
];
$body = $this->performSearch($query);
$hits = new Hits($body['hits']);
if ($hits->isEmpty()) {
return null;
}
}
private function performSearch(array $query): array
{
$response = $this->client->request('POST', '_search/template', [
'json' => $query
]);
return json_decode($response->getBody()->getContents(), true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment