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

[BUG]bulk api → Request size exceeded 10485760 bytes #284

Closed
ichige opened this issue Feb 5, 2025 · 5 comments
Closed

[BUG]bulk api → Request size exceeded 10485760 bytes #284

ichige opened this issue Feb 5, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@ichige
Copy link

ichige commented Feb 5, 2025

What is the bug?

After upgrading from 2.3.1 to 2.4 the other day, I started getting the following exception in the bulk api.

OpenSearch\Common\Exceptions\BadRequest400Exception: {"Message":"Request size exceeded 10485760 bytes"}

How can one reproduce the bug?

Simply execute the bulk method on the same Client.

What is the expected behavior?

In previous implementations, an instance of endpoint was created with each call.

        if (is_null($this->endpoint)) {
            $serializer = $this->serializer;

            $this->endpoint = function ($class) use ($serializer) {
                $fullPath = '\\OpenSearch\\Endpoints\\' . $class;

                $reflection = new ReflectionClass($fullPath);
                $constructor = $reflection->getConstructor();

                if ($constructor && $constructor->getParameters()) {
                    return new $fullPath($serializer);
                } else {
                    return new $fullPath();
                }
            };
        }

The new version returns the same instance, so body is inherited.

    public function getEndpoint(string $class): AbstractEndpoint
    {
        if (!isset($this->endpoints[$class])) {
            $this->endpoints[$class] = $this->createEndpoint($class);
        }

        return $this->endpoints[$class];
    }

I hope it comes across as a translation from Japanese to English in deepl.

@ichige ichige added bug Something isn't working untriaged labels Feb 5, 2025
@shyim
Copy link
Collaborator

shyim commented Feb 5, 2025

The new version returns the same instance, so body is inherited.

About which body we are talking. There is no internal state where the body is buffered 🤔

@dblock
Copy link
Member

dblock commented Feb 5, 2025

@ichige do you have a repro? try to turn this into a failing unit test?

@dblock dblock removed the untriaged label Feb 5, 2025
@ichige
Copy link
Author

ichige commented Feb 6, 2025

@shyim

We use Laravel.
Here is a simple way to reproduce it.

        /** @var OpenSearchClient $client */
        $client = App::make(OpenSearchClient::class);
        $client->bulk([
            'body' => [
                ['index' => ['_index' => 'example', '_id' => 'id-01']],
                ['data' => Str::random(10)]
            ]
        ]);
        $client->bulk([
            'body' => [
                ['index' => ['_index' => 'example', '_id' => 'id-02']],
                ['data' => Str::random(10)]
            ]
        ]);

Use Laravel's dump function to check the body of the Bullk Endpoint.

    public function bulk(array $params = [])
    {
        $index = $this->extractArgument($params, 'index');
        $body = $this->extractArgument($params, 'body');

        $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Bulk::class);
        $endpoint->setParams($params);
        $endpoint->setIndex($index);
        $endpoint->setBody($body);
        // check the body
        dump($endpoint->getBody());

        return $this->performRequest($endpoint);
    }

This is the result.

Image

thanks.

@dblock
Copy link
Member

dblock commented Feb 6, 2025

@ichige Turn it into a unit test and maybe a fix?

@ichige
Copy link
Author

ichige commented Feb 6, 2025

@dblock

Turn it into a unit test and maybe a fix?

I am sorry, but I am not in the habit of creating Unit Tests, so I am afraid I cannot help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants