src/Model/Service/ElasticService.php
public function create($id)
    {
        $exists = false;
        try {
            // check if index exist
            $exists = $this->resource->indices()->exists(['index' => $this->schema->getName()]);
        } catch (\Throwable $e) {
            // return false if something went wrong
            return false;
        }

        // if index doesnt exist
        if (!$exists) {
            // do nothing
            return false;
        }
        
        // set schema to sql
        $this->sql->setSchema($this->schema);
        // get data from sql
        $body = $this->sql->get($this->schema->getPrimaryFieldName(), $id);
        
        if (!is_array($body) || empty($body)) {
            return false;
        }
        
        try {
            return $this->resource->index([
                'index' => $this->schema->getName(),
                'type' => static::INDEX_TYPE,
                'id' => $id,
                'body' => $body
            ]);
        } catch (NoNodesAvailableException $e) {
            return false;
        } catch (BadRequest400Exception $e) {
            return false;
        } catch (\Throwable $e) {
            // catch all throwable
            // if something went wrong, dont panic, just return false
            return false;
        }
    }
public function create($id)
    {
        $exists = false;
        try {
            // check if index exist
            $exists = $this->resource->indices()->exists(['index' => $this->schema->getName()]);
        } catch (\Throwable $e) {
            // return false if something went wrong
            return false;
        }

        // if index doesnt exist
        if (!$exists) {
            // do nothing
            return false;
        }
        
        // set schema to sql
        $this->sql->setSchema($this->schema);
        // get data from sql
        $body = $this->sql->get($this->schema->getPrimaryFieldName(), $id);
        
        if (!is_array($body) || empty($body)) {
            return false;
        }
        
        try {
            return $this->resource->index([
                'index' => $this->schema->getName(),
                'type' => static::INDEX_TYPE,
                'id' => $id,
                'body' => $body
            ]);
        } catch (NoNodesAvailableException $e) {
            return false;
        } catch (BadRequest400Exception $e) {
            return false;
        } catch (\Throwable $e) {
            // catch all throwable
            // if something went wrong, dont panic, just return false
            return false;
        }
    }
public function create ( $ id ) { $ exists = false ; try { // check if index exist $ exists = $ this -> resource -> indices ( ) -> exists ( [ 'index' => $ this -> schema -> getName ( ) ] ) ; } catch ( \ Throwable $ e ) { // return false if something went wrong return false ; } // if index doesnt exist if ( ! $ exists ) { // do nothing return false ; } // set schema to sql $ this -> sql -> setSchema ( $ this -> schema ) ; // get data from sql $ body = $ this -> sql -> get ( $ this -> schema -> getPrimaryFieldName ( ) , $ id ) ; if ( ! is_array ( $ body ) || empty ( $ body ) ) { return false ; } try { return $ this -> resource -> index ( [ 'index' => $ this -> schema -> getName ( ) , 'type' => static :: INDEX_TYPE , 'id' => $ id , 'body' => $ body ] ) ; } catch ( NoNodesAvailableException $ e ) { return false ; } catch ( BadRequest400Exception $ e ) { return false ; } catch ( \ Throwable $ e ) { // catch all throwable // if something went wrong, dont panic, just return false return false ; } }
Create in index

@param *int $id

@return array
Create in index