PHP code example of neelkanthk / esloader

1. Go to this page and download the library: Download neelkanthk/esloader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neelkanthk / esloader example snippets




use Neelkanthk\EsLoader\Core\EsLoader;

//1. Specify the path of file to be indexed.
$filePath = __DIR__ . "/data.csv";
//2. Load array of configurations.
$config = [
    "index" => "esloader",
    "doc_id_key" => NULL,
    "connection" => "local",
    "local" => [
        'host' => "localhost",
        'port' => "9200"
    ],
    "aws" => [
        'host' => "",
        'region' => "",
        'access_key' => "",
        'secret_key' => ""
    ],
    "mappings" => [
        "_doc" => [
            '_source' => [
                'enabled' => true
            ],
            "properties" => [
                "id" => ['type' => 'keyword'],
                "first_name" => ['type' => 'text'],
                "last_name" => ['type' => 'text'],
                "email" => ['type' => 'keyword'],
                "gender" => ['type' => 'keyword'],
                "points" => ['type' => 'integer']
            ]
        ],
    ],
    "settings" => [
        'number_of_shards' => 2,
        'number_of_replicas' => 0
    ],
    "batch_size" => 100
];
//3. Pass the file and configuration to the `EsLoader::load` method.
EsLoader::load($filePath, $config);




/**
 * index : Name of the Elasticsearch index
 * doc_id_key : The field in your dataset which you want to keep as Es document id. NULL assigns a Es auto generated id
 * connection : Set it `local` if you have a self managed Es cluster. For AWS hosted Es set it to `aws`
 * local : Es configuration for your self managed Es
 * aws : Es configuration for your AWS managed Es
 * mappings : Define Es mappings as per your dataset
 * settings : Define Es settings as per your true
            ],
            "properties" => [
                "id" => ['type' => 'keyword'],
                "first_name" => ['type' => 'text'],
                "last_name" => ['type' => 'text'],
                "email" => ['type' => 'keyword'],
                "gender" => ['type' => 'keyword'],
                "points" => ['type' => 'integer']
            ]
        ],
    ],
    "settings" => [
        'number_of_shards' => 2,
        'number_of_replicas' => 0
    ],
    "batch_size" => 100
];