We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This is a proposal for adding a Response\Elasticsearch::mapTo($class = 'stdClass') for mapping an ES|QL response into an object of a class $class.
Response\Elasticsearch::mapTo($class = 'stdClass')
$class
Here an example:
class Employee { public string $name; public DateTime $birthdate; public float $avg_salary; public string $country; } $client = ClientBuilder::create() ->build(); $result = $client->esql()->query([ 'body' => [ 'query' => 'FROM employees | STATS avg_salary = AVG(salary) by country' ] ]); $employees = $result->mapTo(Employee::class); // array of Employee printf("Number of employees: %d\n", count($employees)); printf("First employee\n"); printf("Name: %s\n", $employees[0]->name); printf("Birthdate: %s\n", $employees[0]->birthday->format('Y-m-d')); printf("Avg salary: %.2f\n", $employees[0]->avg_salary); printf("Country: %s\n", $employees[0]->country);
If $class is not specified the default class is stdClass.
The text was updated successfully, but these errors were encountered:
Added mapTo feature, see #1398
3fef1a0
Added mapTo feature, see #1398 (#1399)
acade92
* Added mapTo feature, see #1398 * Fixed php-http/message-factory issue and extended memory to 256M for phpstan
Done in #1399
Sorry, something went wrong.
ezimuel
No branches or pull requests
This is a proposal for adding a
Response\Elasticsearch::mapTo($class = 'stdClass')
for mapping an ES|QL response into an object of a class$class
.Here an example:
If
$class
is not specified the default class is stdClass.The text was updated successfully, but these errors were encountered: