-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.php
More file actions
42 lines (32 loc) · 925 Bytes
/
insert.php
File metadata and controls
42 lines (32 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
require __DIR__ . '/start.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
$params = ['body' => []];
for ($i = 1; $i <= 123456; $i++) {
$params['body'][] = [
'index' => [
'_index' => 'user',
'_type' => 'user_type',
'_id' => $i
]
];
$params['body'][] = [
'name' => '连波'.$i,
'sex' => rand(0, 3),
'age' => rand(10, 20),
'motto' => '这是我的座右铭',
];
// Every 1000 documents stop and send the bulk request
if ($i % 1000 == 0) {
$responses = $client->bulk($params);
// erase the old bulk request
$params = ['body' => []];
// unset the bulk response when you are done to save memory
unset($responses);
}
}
// Send the last batch if it exists
if (!empty($params['body'])) {
$responses = $client->bulk($params);
}