Created
May 28, 2019 09:58
-
-
Save skowron-line/c48704ebe850b0f7f34c7bac2b5d6ee6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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