protected function bulkAttachmentUpsert(array $nodes)
    {
        $nids = [];
        $params = [];

        $this->totalSizeBytes = 0;  // Don't forgot to reset it!!
        foreach ($nodes as $node) {

            // First of all, try to get encoded files.
            try {
                $attachments = $this->getEncodedAttachments($node);
            } catch (MaxSizeAttachmentExceedException $e) {
                // Log any nodes which are no more indexed.
                watchdog(
                  'ucms_search_attachment',
                  '!nid attachments not indexed because max file size is exceed',
                  ['!nid' => $node->nid],
                  WATCHDOG_NOTICE
                );
                continue;
            }

            // Even if there is no attachment, mark it as treated.
            $nids[] = $node->id();

            if ($attachments) {
                $params['body'][] = [
                  'index' => [
                    '_index' => $this->indexRealname,
                    '_id' => $node->id(),
                    '_type' => 'node',
                  ],
                ];
                $params['body'][] = [
                  'attachment' => $attachments,
                ];
            }
        }

        if ($params) {
            $this->client->bulk($params);
        }

        // Yes, it may never happen but we can have an infinite loop if we got
        // only ONE node which exceed the total limit and throw the exception...
        if ($nids) {
            // Don't delete but update it only (in case other operations are
            // still needed).
            $this
              ->db
              ->update('ucms_search_status')
              ->fields(['needs_attachments_reindex' => 0])
              ->condition('nid', $nids)
              ->condition('index_key', $this->index)
              ->execute();
        }
    }
protected function bulkAttachmentUpsert(array $nodes)
    {
        $nids = [];
        $params = [];

        $this->totalSizeBytes = 0;  // Don't forgot to reset it!!
        foreach ($nodes as $node) {

            // First of all, try to get encoded files.
            try {
                $attachments = $this->getEncodedAttachments($node);
            } catch (MaxSizeAttachmentExceedException $e) {
                // Log any nodes which are no more indexed.
                watchdog(
                  'ucms_search_attachment',
                  '!nid attachments not indexed because max file size is exceed',
                  ['!nid' => $node->nid],
                  WATCHDOG_NOTICE
                );
                continue;
            }

            // Even if there is no attachment, mark it as treated.
            $nids[] = $node->id();

            if ($attachments) {
                $params['body'][] = [
                  'index' => [
                    '_index' => $this->indexRealname,
                    '_id' => $node->id(),
                    '_type' => 'node',
                  ],
                ];
                $params['body'][] = [
                  'attachment' => $attachments,
                ];
            }
        }

        if ($params) {
            $this->client->bulk($params);
        }

        // Yes, it may never happen but we can have an infinite loop if we got
        // only ONE node which exceed the total limit and throw the exception...
        if ($nids) {
            // Don't delete but update it only (in case other operations are
            // still needed).
            $this
              ->db
              ->update('ucms_search_status')
              ->fields(['needs_attachments_reindex' => 0])
              ->condition('nid', $nids)
              ->condition('index_key', $this->index)
              ->execute();
        }
    }
protected function bulkAttachmentUpsert ( array $ nodes ) { $ nids = [ ] ; $ params = [ ] ; $ this -> totalSizeBytes = 0 ; // Don't forgot to reset it!! foreach ( $ nodes as $ node ) { // First of all, try to get encoded files. try { $ attachments = $ this -> getEncodedAttachments ( $ node ) ; } catch ( MaxSizeAttachmentExceedException $ e ) { // Log any nodes which are no more indexed. watchdog ( 'ucms_search_attachment' , '!nid attachments not indexed because max file size is exceed' , [ '!nid' => $ node -> nid ] , WATCHDOG_NOTICE ) ; continue ; } // Even if there is no attachment, mark it as treated. $ nids [ ] = $ node -> id ( ) ; if ( $ attachments ) { $ params [ 'body' ] [ ] = [ 'index' => [ '_index' => $ this -> indexRealname , '_id' => $ node -> id ( ) , '_type' => 'node' , ] , ] ; $ params [ 'body' ] [ ] = [ 'attachment' => $ attachments , ] ; } } if ( $ params ) { $ this -> client -> bulk ( $ params ) ; } // Yes, it may never happen but we can have an infinite loop if we got // only ONE node which exceed the total limit and throw the exception... if ( $ nids ) { // Don't delete but update it only (in case other operations are // still needed). $ this -> db -> update ( 'ucms_search_status' ) -> fields ( [ 'needs_attachments_reindex' => 0 ] ) -> condition ( 'nid' , $ nids ) -> condition ( 'index_key' , $ this -> index ) -> execute ( ) ; } }
Update ES documents with attachments. Multiple attachments per document
is allowed but be careful with memory usage!

@param \Drupal\node\NodeInterface[] $nodes
Update ES documents with attachments . Multiple attachments per document is allowed but be careful with memory usage!