-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathes-cdr-insert.php.not
More file actions
61 lines (56 loc) · 1.72 KB
/
es-cdr-insert.php.not
File metadata and controls
61 lines (56 loc) · 1.72 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
*This should read json objects stored in
*/
$start = microtime(true);
$working_dir = 'working/json-xml-cdr';
$hosts = ['alison.athnex.com:9200'];
$esIndex = 'call_records.stage';
$esType = 'cdr';
$esTotalCnt = 0;
$esTotalFail = 0;
require 'vendor/autoload.php';
$client = Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
if (!is_dir($working_dir)){
echo "Unable to locate $working_dir as a valid working dir.\n";
exit;
}
// Lets start the directory read loop.
$dh = opendir($working_dir);
while ($entry = readdir($dh)) {
if(is_dir($entry)){
continue;
}
if($entry == '.' OR $entry == '..'){
continue;
}
$json_contents = file_get_contents($working_dir.'/'.$entry);
$uuid = str_replace('.cdr.json','',$entry);
$params = [
'index' => $esIndex,
'type' => $esType,
'id' => $uuid,
'body' => $json_contents
];
echo "Inserting $entry into elasticsearch\n";
$response = $client->index($params);
if ($response['result'] == 'updated' OR $response['result'] == 'created') {
echo "Done with $uuid!\n Entry version [". $response['_version']."]\n";
echo "Deleting file ". $working_dir.'/'.$entry ."\n"; // Kidding, not actually doing this.
unlink ($working_dir.'/'.$entry);
echo "Deleted ".$working_dir.'/'.$entry."\n";
$esTotalCnt++;
} else {
$esTotalFail++;
echo "Error processing ". $working_dir.'/'.$entry ."\n";
}
continue;
}
<<<<<<< HEAD
?>
=======
echo "Total inserted is ". $esTotalCnt ." and total Failures is ". $esTotalFail ."\n";
$timeElapsed = microtime(true) - $start;
echo "Total time taken $timeElapsed\n";
?>
>>>>>>> 3b0d63b8e1858f8e9bbe200080aa53bff0b89f4f