public function bulk($operation, $type, array $query)
    {
        if (!in_array($operation, ['index', 'create', 'update', 'delete'])) {
            throw new \InvalidArgumentException('Wrong bulk operation selected');
        }

        $this->eventDispatcher->dispatch(
            Events::BULK,
            new BulkEvent($operation, $type, $query)
        );

        $this->bulkQueries['body'][] = [
            $operation => array_filter(
                [
                    '_type' => $type,
                    '_id' => isset($query['_id']) ? $query['_id'] : null,
                    '_ttl' => isset($query['_ttl']) ? $query['_ttl'] : null,
                    '_routing' => isset($query['_routing']) ? $query['_routing'] : null,
                    '_parent' => isset($query['_parent']) ? $query['_parent'] : null,
                ]
            ),
        ];
        unset($query['_id'], $query['_ttl'], $query['_parent'], $query['_routing']);

        switch ($operation) {
            case 'index':
            case 'create':
            case 'update':
                $this->bulkQueries['body'][] = $query;
                break;
            case 'delete':
                // Body for delete operation is not needed to apply.
            default:
                // Do nothing.
                break;
        }

        // We are using counter because there is to difficult to resolve this from bulkQueries array.
        $this->bulkCount++;

        $response = null;

        if ($this->bulkCommitSize === $this->bulkCount) {
            $response = $this->commit();
        }

        return $response;
    }
public function bulk($operation, $type, array $query)
    {
        if (!in_array($operation, ['index', 'create', 'update', 'delete'])) {
            throw new \InvalidArgumentException('Wrong bulk operation selected');
        }

        $this->eventDispatcher->dispatch(
            Events::BULK,
            new BulkEvent($operation, $type, $query)
        );

        $this->bulkQueries['body'][] = [
            $operation => array_filter(
                [
                    '_type' => $type,
                    '_id' => isset($query['_id']) ? $query['_id'] : null,
                    '_ttl' => isset($query['_ttl']) ? $query['_ttl'] : null,
                    '_routing' => isset($query['_routing']) ? $query['_routing'] : null,
                    '_parent' => isset($query['_parent']) ? $query['_parent'] : null,
                ]
            ),
        ];
        unset($query['_id'], $query['_ttl'], $query['_parent'], $query['_routing']);

        switch ($operation) {
            case 'index':
            case 'create':
            case 'update':
                $this->bulkQueries['body'][] = $query;
                break;
            case 'delete':
                // Body for delete operation is not needed to apply.
            default:
                // Do nothing.
                break;
        }

        // We are using counter because there is to difficult to resolve this from bulkQueries array.
        $this->bulkCount++;

        $response = null;

        if ($this->bulkCommitSize === $this->bulkCount) {
            $response = $this->commit();
        }

        return $response;
    }
public function bulk ( $ operation , $ type , array $ query ) { if ( ! in_array ( $ operation , [ 'index' , 'create' , 'update' , 'delete' ] ) ) { throw new \ InvalidArgumentException ( 'Wrong bulk operation selected' ) ; } $ this -> eventDispatcher -> dispatch ( Events :: BULK , new BulkEvent ( $ operation , $ type , $ query ) ) ; $ this -> bulkQueries [ 'body' ] [ ] = [ $ operation => array_filter ( [ '_type' => $ type , '_id' => isset ( $ query [ '_id' ] ) ? $ query [ '_id' ] : null , '_ttl' => isset ( $ query [ '_ttl' ] ) ? $ query [ '_ttl' ] : null , '_routing' => isset ( $ query [ '_routing' ] ) ? $ query [ '_routing' ] : null , '_parent' => isset ( $ query [ '_parent' ] ) ? $ query [ '_parent' ] : null , ] ) , ] ; unset ( $ query [ '_id' ] , $ query [ '_ttl' ] , $ query [ '_parent' ] , $ query [ '_routing' ] ) ; switch ( $ operation ) { case 'index' : case 'create' : case 'update' : $ this -> bulkQueries [ 'body' ] [ ] = $ query ; break ; case 'delete' : // Body for delete operation is not needed to apply. default : // Do nothing. break ; } // We are using counter because there is to difficult to resolve this from bulkQueries array. $ this -> bulkCount ++ ; $ response = null ; if ( $ this -> bulkCommitSize === $ this -> bulkCount ) { $ response = $ this -> commit ( ) ; } return $ response ; }
Adds query to bulk queries container.

@param string       $operation One of: index, update, delete, create.
@param string|array $type      Elasticsearch type name.
@param array        $query     DSL to execute.

@throws \InvalidArgumentException

@return null|array
Adds query to bulk queries container .