"; ?> ".$es_index." exists
"; $params = [ 'index' => $es_index, ]; try { $response = $client->indices()->delete($params); echo "Index ".$es_index." exists. It is deleted and created
"; } catch (Exception $e) { echo "Index ".$es_index." doesn't exist. ".$es_index." will be created
"; } // Create Index echo "Create index ".$es_index."
"; $params = [ 'index' => $es_index, 'body' => [ 'settings' => [ 'number_of_replicas' => 0 ], ], ]; $response = $client->indices()->create($params); // create document in index $row = 0; echo "
"; if (($handle = fopen($data_csv_file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 300, ";")) !== FALSE) { $row++; $firstname = $data[0]; $lastname = $data[1]; $email = $data[2]; echo 'Adding: '.$row .' '.$firstname.' '.$lastname.' ('.$email.')
'; $params = [ 'index' => $es_index, 'body' => [ 'id' => $row, 'firstname' => $firstname, 'lastname' => $lastname, 'email' => $email] ]; $response = $client->index($params); } fclose($handle); } ?>