-
Notifications
You must be signed in to change notification settings - Fork 14
/
elasticput.php
44 lines (40 loc) · 1.36 KB
/
elasticput.php
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
<?php
// CONFIGURE BELOW
$esHostProtocol = 'http'; // could be https, but may require changes to CURL opts?
$esHost = 'localhost';
$esPort = '9200';
$indexName = 'comicbook';
$docType = 'superhero';
$documentId = 1;
// DO NOT EDIT BELOW THIS LINE!
$row = 1;
if (($handle = fopen('indexme.csv', "r")) !== FALSE) {
while (($data = fgetcsv($handle, 300, ",")) !== FALSE) {
$num = count($data);
$row++;
$hero = $data[0];
$summary = $data[1];
echo 'INDEXING ROW: ' . $row . ' HERO: ' . $hero . "\n";
$json_data = array(
"name" => $hero,
"summary" => $summary
);
$jsonData = json_encode($json_data);
$endPointURL = $esHostProtocol . '://' . $esHost . ':' . $esPort . '/' . $indexName . '/' . $docType . '/' . $documentId++;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endPointURL);
curl_setopt($ch, CURLOPT_PORT, $esPort);
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($ch);
echo 'RESPONSE: ' . $response . "\n\n";
if (!$response) {
return false;
}
}
fclose($handle);
}
?>