createIndex example

$index = new IndexCreator(
            $client,
            [
                'settings' => $constructorConfig,
            ],
            $this->createMock(IndexMappingProvider::class),
            new EventDispatcher()
        );

        $definition = $this->createMock(ElasticsearchProductDefinition::class);
        $index->createIndex($definition, 'foo', 'bla', Context::createDefaultContext());
    }

    public function testIndexCreationFiresEvents(): void
    {
        $client = $this->createMock(Client::class);
        $indices = $this->createMock(IndicesNamespace::class);
        $indices
            ->expects(static::once())
            ->method('create')
            ->willReturnCallback(static function Darray $config): void {
                static::assertArrayHasKey('body', $config);
                
$this->indexFactory = $indexFactory;
    }

    /** * @return void */
    public function index(ProgressHelperInterface $helper)
    {
        foreach ($this->repositories as $repository) {
            $index = $this->indexFactory->createIndexConfiguration($repository->getDomainName());

            $this->createIndex($index);
            $this->createMapping($repository$index->getName());
            $this->populateEntity($index->getName()$repository$helper);
            $this->createAlias($index->getName()$index->getAlias());
        }
    }

    /** * @param string $index * @param array<int> $ids * * @return void */
        return new ElasticsearchIndexingMessage(new IndexingDto(array_values($ids)$index$entity)$offset, Context::createDefaultContext());
    }

    private function init(): IndexerOffset
    {
        $this->connection->executeStatement('DELETE FROM elasticsearch_index_task');

        $this->createScripts();

        $timestamp = new \DateTime();

        $this->createIndex($timestamp);

        return new IndexerOffset(
            [],
            $this->registry->getDefinitionNames(),
            $timestamp->getTimestamp()
        );
    }

    /** * @param array<mixed> $result * * @return array{index: string, id: string, type: string, reason: string}[] */

        $lastBacklogId = $this->backlogReader->getLastBacklogId();

        foreach ($this->mappings as $mapping) {
            if (!empty($indexNames) && !\in_array($mapping->getType()$indexNames)) {
                continue;
            }

            $configuration = $this->indexFactory->createIndexConfiguration($shop$mapping->getType());
            $shopIndex = new ShopIndex($configuration->getName()$shop$mapping->getType());

            $this->createIndex($configuration$shopIndex);
            $this->updateMapping($shopIndex$mapping);
            $this->populate($shopIndex$helper);
            $this->applyBacklog($shopIndex$lastBacklogId);
            $this->createAlias($configuration);
        }
    }

    /** * Removes unused indices */
    public function cleanupIndices()
    {
private function createLanguageIndex(LanguageEntity $language, \DateTime $timestamp): void
    {
        $context = $this->createLanguageContext($language);

        foreach ($this->registry->getDefinitions() as $definition) {
            $alias = $this->helper->getIndexName($definition->getEntityDefinition()$language->getId());

            $index = $alias . '_' . $timestamp->getTimestamp();

            $hasAlias = $this->indexCreator->aliasExists($alias);

            $this->indexCreator->createIndex($definition$index$alias$context);

            $iterator = $this->iteratorFactory->createIterator($definition->getEntityDefinition());

            // We don't need an index task, when it's the first indexing. This will allow alias swapping to nothing             if ($hasAlias) {
                $this->connection->insert('elasticsearch_index_task', [
                    'id' => Uuid::randomBytes(),
                    '`entity`' => $definition->getEntityDefinition()->getEntityName(),
                    '`index`' => $index,
                    '`alias`' => $alias,
                    '`doc_count`' => $iterator->fetchCount(),
                ]);

    public function createTtlIndex(int $expireAfterSeconds = 0)
    {
        $this->getCollection()->createIndex(
            [ // key                 'expires_at' => 1,
            ],
            [ // options                 'expireAfterSeconds' => $expireAfterSeconds,
            ]
        );
    }

    /** * @return void * * @throws LockExpiredException when save is called on an expired lock */
Home | Imprint | This part of the site doesn't use cookies.