Skip to content

The array structure of a batch index is confusing #1261

@RoRui

Description

@RoRui

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions