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

The array structure of a batch index is confusing #1261

Closed
RoRui opened this issue Oct 25, 2022 · 2 comments
Closed

The array structure of a batch index is confusing #1261

RoRui opened this issue Oct 25, 2022 · 2 comments
Labels

Comments

@RoRui
Copy link

RoRui commented Oct 25, 2022

That's what the official document says:
Bulk indexing with PHP arrays.

for($i = 0; $i < 100; $i++) {
    $params['body'][] = [
        'index' => [
            '_index' => 'my_index',
	    ]
    ];

    $params['body'][] = [
        'my_field'     => 'my_value',
        'second_field' => 'some more values'
    ];
}

$responses = $client->bulk($params);

The above array structure is confusing, so why not do it:

for($i = 0; $i < 100; $i++) {
    $params[] = [
        'index' => [
            '_index' => 'my_index',
            '_id' => $i
	    ],
       'body' => [
        'my_field'     => 'my_value',
        'second_field' => 'some more values'
       ]
    ];
}

$responses = $client->bulk($params);
  • Operating System win10
  • PHP Version 8
  • ES-PHP client version lasted
  • Elasticsearch version 8
@ezimuel
Copy link
Contributor

ezimuel commented Nov 2, 2022

@rory5515 you cannot use your solution since we need to create an array of operations in the body field. Each operations has two rows, the first is the operation type (e.g. index) and the second is the document data. If you see the HTTP Bulk API specification here, you can see why we needed to do that.
Let me know if you need more help, thanks.

@murilolivorato
Copy link

murilolivorato commented Jun 28, 2023

I think that is confusint to the structure of arrays

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants