Skip to content
New issue

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

Fix extractArgument iterable casting to array #983

Merged
merged 1 commit into from
Dec 19, 2019

Conversation

rtyshyk
Copy link
Contributor

@rtyshyk rtyshyk commented Dec 17, 2019

Bulk API suports data as itarable, see \Elasticsearch\Endpoints\Bulk::setBody.

It has been broken during refactoring, see #56163ff.

@rtyshyk
Copy link
Contributor Author

rtyshyk commented Dec 17, 2019

I signed, but not sure if / how to update CLA status in checks.

@elasticcla
Copy link

Hi @rtyshyk, we have found your signature in our records, but it seems like you have signed with a different e-mail than the one used in your Git commit. Can you please add both of these e-mails into your Github profile (they can be hidden), so we can match your e-mails to your Github profile?

@ezimuel
Copy link
Contributor

ezimuel commented Dec 18, 2019

@rtyshyk what is the issue that you are trying to solve? The Bulk endpoint supports Traversable (and also Iterator that extends Traversable) using this code.
The fact that Client::extractArgument() converts always an object into an array I don't think is an issue for the endpoint, even because this function is used also by other endpoints and not just Bulk. The Traversable support in Bulk endpoint has been added in #351.

@ezimuel
Copy link
Contributor

ezimuel commented Dec 19, 2019

I signed, but not sure if / how to update CLA status in checks.

The CLA signature is ok now.

@rtyshyk
Copy link
Contributor Author

rtyshyk commented Dec 19, 2019

@ezimuel Yes, bulk endpoint supports Traversable, but the issue here is it is not possible to pass Traversable to it :)

I use \Elasticsearch\Client to consume bulk endpoint and pass there Iterator that returns right meta/data to build a body as well as reduce memory usage.

to make it simple

$client = new \Elasticsearch\Client()
$result = $client->bulk([
    'body' => new \IteratorIterator(new \ArrayIterator([1, 2, 3])),
]);

\Elasticsearch\Client::bulk uses extractArgument for the body parameter where is extractArgument do a cast any object to array.

Traversable cannot be cast to an array, as a result, there is an empty data argument.

https://3v4l.org/Ocq8P

@ezimuel
Copy link
Contributor

ezimuel commented Dec 19, 2019

@rtyshyk I see what you mean, I wrongly supposed that casting IteratorIterator into array was working fine. I'll merge this PR soon.
Thanks for your contribution!

@ezimuel ezimuel merged commit 1a73abd into elastic:master Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants