src/Importing.php
/**
     * Convert a chunk (collection) of models into an Elasticsearch bulk API body.
     *
     * @param  \Illuminate\Support\Collection $chunk     Collection of models to be indexed.
     * @param  callable                       $transform Function which converts models to simplified bulk API format.
     * @return string
     */
Convert a chunk (collection) of models into an Elasticsearch bulk API body.
@param  \Illuminate\Support\Collection $chunk     Collection of models to be indexed.
@param  callable                       $transform Function which converts models to simplified bulk API format.
@return string
Convert a chunk ( collection ) of models into an Elasticsearch bulk API body . @param \ Illuminate \ Support \ Collection $chunk Collection of models to be indexed . @param callable $transform Function which converts models to simplified bulk API format . @return string
protected function chunkToBulk($chunk, callable $transform)
    {
        $bulk = $chunk
            ->map($transform)
            ->reduce(function ($bulk, $item) {
                foreach ($item as $action => $meta) {
                    $data = array_pull($meta, 'data');
                    $bulk[] = [$action => $meta];
                    $bulk[] = $data;
                }
                return $bulk;
            }, Collection::make())
            ->map(function ($row) {
                return json_encode($row);
            })
            ->implode("\n")."\n";
        return $bulk;
    }
protected function chunkToBulk ( $ chunk , callable $ transform ) { $ bulk = $ chunk -> map ( $ transform ) -> reduce ( function ( $ bulk , $ item ) { foreach ( $ item as $ action => $ meta ) { $ data = array_pull ( $ meta , 'data' ) ; $ bulk [ ] = [ $ action => $ meta ] ; $ bulk [ ] = $ data ; } return $ bulk ; } , Collection :: make ( ) ) -> map ( function ( $ row ) { return json_encode ( $ row ) ; } ) -> implode ( " \n " ) . " \n " ; return $ bulk ; }
Convert a chunk (collection) of models into an Elasticsearch bulk API body.
Convert a chunk ( collection ) of models into an Elasticsearch bulk API body .