indices example

$this->newImplementation->updateIds($definition$ids);

            return;
        }

        if (!$this->helper->allowIndexing()) {
            return;
        }

        $alias = $this->helper->getIndexName($definition, Defaults::LANGUAGE_SYSTEM);

        if (!$this->client->indices()->existsAlias(['name' => $alias])) {
            $this->init();
        }

        $messages = $this->generateMessages($definition$ids);

        /** @var ElasticsearchIndexingMessage $message */
        foreach ($messages as $message) {
            $this->__invoke($message);
        }
    }

    
public function testExecuteWithInput(): void
    {
        $commandTester = new CommandTester($this->adminRefreshIndexCommand);
        $commandTester->execute([]);

        $message = $commandTester->getDisplay();

        static::assertStringContainsString('Are you sure you want to reset the Admin Elasticsearch indexing?', $message);
        static::assertStringContainsString('Admin Elasticsearch indices deleted and queue cleared', $message);

        $client = $this->getDiContainer()->get(Client::class);
        $client->indices()->get(['index' => EnvironmentHelper::getVariable('SHOPWARE_ADMIN_ES_INDEX_PREFIX') . '*']);

        $tasks = $this->connection->fetchAllAssociative('SELECT `index` FROM admin_elasticsearch_index_task');

        static::assertEmpty($tasks);
    }

    protected function getDiContainer(): ContainerInterface
    {
        return $this->getContainer();
    }
}

                    [
                        'name' => 'test_newly_created_field_text',
                        'type' => CustomFieldTypes::TEXT,
                    ],
                ],
            ],
        ], Context::createDefaultContext());

        $indexName = array_keys($this->indexDetector->getAllUsedIndices())[0];

        $indices = array_values($this->client->indices()->getMapping(['index' => $indexName]))[0];
        $properties = $indices['mappings']['properties']['customFields']['properties'] ?? [];

        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            static::assertArrayHasKey(Defaults::LANGUAGE_SYSTEM, $properties);
            $properties = $properties[Defaults::LANGUAGE_SYSTEM]['properties'];
            static::assertIsArray($properties);
            static::assertArrayHasKey('test_newly_created_field', $properties);
            static::assertSame('long', $properties['test_newly_created_field']['type']);

            static::assertArrayHasKey('test_newly_created_field_text', $properties);
            static::assertSame('text', $properties['test_newly_created_field_text']['type']);
        }
public function testIterate(): void
    {
        $c = $this->getContainer()->get(Connection::class);
        static::assertEmpty($c->fetchAllAssociative('SELECT `index` FROM `admin_elasticsearch_index_task`'));

        $this->registry->iterate(new AdminIndexingBehavior(true));

        $index = $c->fetchOne('SELECT `index` FROM `admin_elasticsearch_index_task`');

        static::assertNotFalse($index);

        static::assertTrue($this->client->indices()->exists(['index' => $index]));

        $indices = array_values($this->client->indices()->getMapping(['index' => $index]))[0];
        $properties = $indices['mappings']['properties'];

        $expectedProperties = [
            'id' => ['type' => 'keyword'],
            'text' => ['type' => 'text'],
            'entityName' => ['type' => 'keyword'],
            'parameters' => ['type' => 'keyword'],
            'textBoosted' => ['type' => 'text'],
        ];

        
$this->indexElasticSearch();

            $criteria = new Criteria();
            $criteria->addFilter(
                new NandFilter([new EqualsFilter('salesChannelDomains.id', null)])
            );

            if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
                $index = $this->helper->getIndexName($this->productDefinition);

                $exists = $this->client->indices()->exists(['index' => $index]);
                static::assertTrue($exists, 'Expected elasticsearch indices present');
            } else {
                $languages = $this->languageRepository->searchIds($criteria$context);

                foreach ($languages->getIds() as $languageId) {
                    \assert(\is_string($languageId));
                    $index = $this->helper->getIndexName($this->productDefinition, $languageId);

                    $exists = $this->client->indices()->exists(['index' => $index]);
                    static::assertTrue($exists, 'Expected elasticsearch indices present');
                }
            }


        if (!$enabled) {
            return;
        }

        foreach ($client->getCalledRequests() as $calledRequest) {
            $this->data['time'] += $calledRequest['time'];
        }

        $this->data['clusterInfo'] = $client->cluster()->health();
        $this->data['indices'] = $client->cat()->indices();
    }

    public function getName(): string
    {
        return 'elasticsearch';
    }

    public function reset(): void
    {
        $this->data = [];
        $this->client->resetRequests();
        
->get(ElasticsearchIndexingCommand::class)
            ->run(new ArrayInput([])new NullOutput());

        $this->runWorker();

        $this->refreshIndex();
    }

    public function refreshIndex(): void
    {
        $this->getDiContainer()->get(Client::class)
            ->indices()
            ->refresh(['index' => '_all']);
    }

    protected function createEntityAggregator(): ElasticsearchEntityAggregator
    {
        $decorated = $this->createMock(EntityAggregator::class);

        $decorated
            ->expects(static::never())
            ->method('aggregate');

        
$io->table(['Indices to be deleted:']array_map(static fn (string $name) => [$name]$indices));

        if (!$input->getOption('force')) {
            if (!$io->confirm(sprintf('Delete these %d indices?', \count($indices)), false)) {
                $io->writeln('Deletion aborted.');

                return self::FAILURE;
            }
        }

        foreach ($indices as $index) {
            $this->client->indices()->delete(['index' => $index]);
        }

        $io->writeln('Indices deleted.');

        return self::SUCCESS;
    }
}
$this->applyBacklog($shopIndex$lastBacklogId);
            $this->createAlias($configuration);
        }
    }

    /** * Removes unused indices */
    public function cleanupIndices()
    {
        $prefix = $this->indexFactory->getPrefix();
        $aliases = $this->client->indices()->getAliases();
        foreach ($aliases as $index => $indexAliases) {
            if (strpos($index$prefix) !== 0) {
                continue;
            }

            if (empty($indexAliases['aliases'])) {
                $this->client->indices()->delete(['index' => $index]);
            }
        }
    }

    
public function testExecuteWithInput(): void
    {
        $commandTester = new CommandTester($this->refreshIndexCommand);
        $commandTester->execute([]);

        $message = $commandTester->getDisplay();

        static::assertStringContainsString('Are you sure you want to reset the Elasticsearch indexing?', $message);
        static::assertStringContainsString('Elasticsearch indices deleted and queue cleared', $message);

        $client = $this->getDiContainer()->get(Client::class);
        $client->indices()->get(['index' => EnvironmentHelper::getVariable('SHOPWARE_ES_INDEX_PREFIX') . '*']);

        $tasks = $this->connection->fetchAllAssociative('SELECT `index` FROM elasticsearch_index_task');

        static::assertEmpty($tasks);
    }

    protected function getDiContainer(): ContainerInterface
    {
        return $this->getContainer();
    }
}
/** * @param array<string> $ids */
    public function updateIds(EntityDefinition $definition, array $ids): void
    {
        if (!$this->helper->allowIndexing()) {
            return;
        }

        $alias = $this->helper->getIndexName($definition);

        if (!$this->client->indices()->existsAlias(['name' => $alias])) {
            $this->init();
        }

        $this->__invoke($this->generateMessage($definition$ids));
    }

    /** * @param array<string> $ids */
    private function generateMessage(EntityDefinition $definition, array $ids): ElasticsearchIndexingMessage
    {
        
return $indexer;
        }

        throw new ElasticsearchIndexingException([\sprintf('Indexer for name %s not found', $name)]);
    }

    public function updateMappings(): void
    {
        foreach ($this->indexer as $indexer) {
            $mapping = $this->buildMapping($indexer);

            $this->client->indices()->putMapping([
                'index' => $this->adminEsHelper->getIndex($indexer->getName()),
                'body' => $mapping,
            ]);
        }
    }

    private function isIndexedEntityWritten(EntityWrittenContainerEvent $event): bool
    {
        foreach ($this->indexer as $indexer) {
            $ids = $event->getPrimaryKeys($indexer->getEntity());

            
return self::FAILURE;
        }

        $answer = $io->ask('Are you sure you want to reset the Admin Elasticsearch indexing?', 'yes');

        if ($answer !== 'yes') {
            $io->error('Canceled clearing indexing process');

            return self::SUCCESS;
        }

        $allIndices = $this->client->indices()->get(['index' => $this->adminEsHelper->getPrefix() . '*']);

        foreach ($allIndices as $index) {
            $this->client->indices()->delete(['index' => $index['settings']['index']['provided_name']]);
        }

        $this->connection->executeStatement('TRUNCATE admin_elasticsearch_index_task');

        try {
            $gateway = $this->gatewayRegistry->get(IncrementGatewayRegistry::MESSAGE_QUEUE_POOL);
            $gateway->reset('message_queue_stats', AdminSearchIndexingMessage::class);
        } catch (IncrementGatewayNotFoundException) {
            
$progressBar = new ProgressBar($output$totalProducts);
            $progressBar->advance($totalProducts - $indexTask['doc_count']);
            $output->writeln('');
        } else {
            $table->addRow(['Indexing', 'completed']);
            $table->render();
            $output->writeln('');
        }

        /** @var list<string> $usedIndices */
        $usedIndices = array_keys($this->client->indices()->getAlias(['name' => $indexTask['alias']]));

        $indexName = $indexTask['index'];
        \assert(\is_string($indexName));
        if (!\in_array($indexName$usedIndices, true)) {
            $io = new SymfonyStyle($input$output);
            $io->warning(sprintf('Alias will swap at the end of the indexing process from %s to %s', $usedIndices[0]$indexName));
        }

        return self::SUCCESS;
    }
}
->get(ElasticsearchAdminIndexingCommand::class)
            ->run(new ArrayInput([...$input, '--no-queue' => true])new NullOutput());

        $this->runWorker();

        $this->refreshIndex();
    }

    public function refreshIndex(): void
    {
        $this->getDiContainer()->get(Client::class)
            ->indices()
            ->refresh(['index' => '_all']);
    }

    abstract protected function getDiContainer(): ContainerInterface;

    abstract protected function runWorker(): void;

    protected function clearElasticsearch(): void
    {
        $c = $this->getDiContainer();

        
Home | Imprint | This part of the site doesn't use cookies.