Wallmander\ElasticsearchIndexer\Model\Indexer::indexPosts PHP Method

indexPosts() public method

public indexPosts ( array $posts )
$posts array
    public function indexPosts(array $posts)
    {
        $indexName = $this->getIndexName();
        $body = [];
        foreach ($posts as $post) {
            $body[] = ['index' => ['_index' => $indexName, '_type' => 'post', '_id' => $post->ID]];
            $body[] = static::preparePost($post);
        }
        $responses = $this->bulk(['body' => $body]);
        if ($responses['errors']) {
            if ($responses['items']) {
                foreach ($responses['items'] as $item) {
                    if ($item['index']['status'] !== 201) {
                        Log::add('Failed to index post ' . $item['index']['_id'] . ' Message: ' . $item['index']['error']);
                    }
                }
            } else {
                //Failed for some other reason
                Log::add('indexer failed. Response: ' . print_r($responses['errors'], 1));
            }
        }
    }