I am using `postgreSQL` and I'm trying to bring power of `Elasticsearch` to our system. I am using this algorithm to bulk insert data (each time **1000 rows** of data) into Elasticsearch. The problem is it is very very slow and took about **15 hours** for just **280 000** rows of data.

From my estimate it is going to take about **26 days** non stop to complete indexing just this table (**with ~12M records**).

Is it possible to somehow optimize this approach and create a faster one? this is what I'm doing so far:

```
public function run()
    {
        $es_client = new \Elastica\Client();
        $es_index = $es_client->getIndex("vehicle");
        $es_type = $es_index->getType("_doc");

        $vehicle_ins = new Vehicle;

        $step = 1000;
        $min_vehicle_id = $vehicle_ins->query()->min('id');
        $max_vehicle_id = $vehicle_ins->query()->max('id');

        $insert_counter = 1;

        $docs = [];

        for ($i = $min_vehicle_id ; $i <= $max_vehicle_id ; $i += $step) {
            $x = $i;
            $y = $i + $step;

            $vehicles = $vehicle_ins->query()
                ->where('id', '>=', $x)
                ->where('id', '<', $y)
                ->get();

            foreach ($vehicles as $vehicle) {

                $docs[] = new \Elastica\Document(
                    $vehicle->id,
                    [
                        // implementing my columns (91 columns)
                    ]);

                echo ".";

                if ($insert_counter % $step == 0) {
                    $es_type->addDocuments($docs);
                    $es_type->getIndex()->refresh();
                    $docs = [];
                    echo "\n";
                    echo $step . " rows inserted!";
                    echo "\n";
                }

                $insert_counter++;

            }
        }
        if (!empty($docs)) {
            $es_type->addDocuments($docs);
            $es_type->getIndex()->refresh();
            $docs = [];
        }
    }

```

P.S: I am using `elastica` for working with `Elasticsearch` and the application is in `Laravel 5.7` with `postgreSQL` as the main DB.

P.S: This approach was also suggested in [**ElasticSearch website**](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_indexing_documents.html#_bulk_indexing), but it's still too slow for the amount of data I'm working with.