Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'vendor/autoload.php';
- use Elasticsearch\ClientBuilder;
- $esHost = [
- 'elasticsearch:9200'
- ];
- $client = ClientBuilder::create()->setHosts($esHost)->build();
- $indexName = 'mkp';
- $params = [
- 'index' => $indexName,
- 'body' => [
- 'mappings' => [
- 'properties' => [
- 'attributes' => [
- 'type' => 'nested'
- ],
- ],
- ],
- ]
- ];
- $client->indices()->create($params);
- $servername = "mariadb";
- $username = "root";
- $password = "root";
- $dbName = 'mykiot';
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbName);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT id, data FROM cache_products where store_id = 423677";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while ($row = $result->fetch_assoc()) {
- echo "id: " . $row["id"] . "\n";
- $data = json_decode($row['data'], true);
- $params = [
- 'index' => $indexName,
- 'id' => $row['id'],
- 'body' => $data
- ];
- $response = $client->index($params);
- }
- } else {
- echo "0 results";
- }
- $conn->close();
Add Comment
Please, Sign In to add comment