getIndexName example

private readonly IndexMappingProvider $indexMappingProvider
    ) {
    }

    public function update(Context $context): void
    {
        if (!Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            $languages = $this->languageProvider->getLanguages($context);

            foreach ($this->registry->getDefinitions() as $definition) {
                foreach ($languages as $language) {
                    $indexName = $this->elasticsearchHelper->getIndexName($definition->getEntityDefinition()$language->getId());

                    $this->client->indices()->putMapping([
                        'index' => $indexName,
                        'body' => $this->indexMappingProvider->build($definition$context),
                    ]);
                }
            }

            return;
        }

        
$search,
                $definition,
                $criteria,
                $context
            )
        );

        $search = $this->convertSearch($criteria$definition$context$search);

        try {
            $result = $this->client->search([
                'index' => $this->helper->getIndexName($definition$this->helper->enabledMultilingualIndex() ? null : $context->getLanguageId()),
                'track_total_hits' => true,
                'body' => $search,
            ]);
        } catch (\Throwable $e) {
            $this->helper->logAndThrowException($e);

            return $this->decorated->search($definition$criteria$context);
        }

        $result = $this->hydrator->hydrate($definition$criteria$context$result);

        

        if ($this->helper->enabledMultilingualIndex()) {
            $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);
        }
    }
$repository = $registry->getRepository($criteria);

            if (!$repository instanceof EsAwareRepository) {
                continue;
            }

            $output->writeln(sprintf('Sync %s with id %s', $backlog['entity']$backlog['entity_id']));

            if ($backlog['entity'] === Article::class) {
                $this->indexArticle($backlog['entity_id']);
            } else {
                $index = $this->getIndexName($repository->getDomainName());
                $indexer->indexEntities($index$repository[$backlog['entity_id']]);
            }
        }

        $ids = array_column($backlogs, 'id');

        $backlogService->cleanup($ids);

        return 0;
    }

    
true,
            'prefix',
            true,
            $this->createMock(Client::class),
            $this->createMock(ElasticsearchRegistry::class),
            $this->createMock(CriteriaParser::class),
            $this->createMock(LoggerInterface::class),
            $storage
        );

        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            static::assertSame('prefix_product', $helper->getIndexName(new ProductDefinition()));
        } else {
            static::assertSame('prefix_product_foo', $helper->getIndexName(new ProductDefinition(), 'foo'));
        }
    }

    public function testAllowSearch(): void
    {
        $registry = $this->createMock(ElasticsearchRegistry::class);
        $registry->method('has')->willReturnMap([
            ['product', true],
            ['category', false],
        ]);
$search = $this->createSearch($definition$criteria$context);

        $this->eventDispatcher->dispatch(
            new ElasticsearchEntityAggregatorSearchEvent($search$definition$criteria$context)
        );

        $searchArray = $search->toArray();
        $searchArray['timeout'] = $this->timeout;

        try {
            $result = $this->client->search([
                'index' => $this->helper->getIndexName($definition$this->helper->enabledMultilingualIndex() ? null : $context->getLanguageId()),
                'body' => $searchArray,
            ]);
        } catch (\Throwable $e) {
            $this->helper->logAndThrowException($e);

            return $this->decorated->aggregate($definition$criteria$context);
        }

        $result = $this->hydrator->hydrate($definition$criteria$context$result);
        $result->addState(self::RESULT_STATE);

        
/** * @internal * * @covers \Shopware\Elasticsearch\Framework\Indexing\Event\ElasticsearchIndexConfigEvent */
class ElasticsearchIndexConfigEventTest extends TestCase
{
    public function testEvent(): void
    {
        $event = new ElasticsearchIndexConfigEvent('index', ['config' => 'value']$this->createMock(AbstractElasticsearchDefinition::class), Context::createDefaultContext());
        static::assertSame('index', $event->getIndexName());
        static::assertSame(['config' => 'value']$event->getConfig());
        static::assertInstanceOf(AbstractElasticsearchDefinition::class$event->getDefinition());
        static::assertInstanceOf(Context::class$event->getContext());

        $event->setConfig(['config' => 'value2']);

        static::assertSame(['config' => 'value2']$event->getConfig());
    }
}


    /** * @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 */
    
if (!$this->elasticsearchHelper->allowIndexing()) {
            return;
        }

        foreach ($event->getWriteResults() as $writeResult) {
            if ($writeResult->getOperation() !== EntityWriteResult::OPERATION_INSERT) {
                continue;
            }

            $languageId = $writeResult->getProperty('languageId');

            $esIndex = $this->elasticsearchHelper->getIndexName($this->productDefinition, $languageId);

            // index exists, don't need to do anything             if ($this->client->indices()->exists(['index' => $esIndex])) {
                continue;
            }

            $this->bus->dispatch(new ElasticsearchLanguageIndexIteratorMessage($languageId));
        }
    }

    public function onLanguageWritten(EntityWrittenEvent $event): void
    {
$client,
            [
                'settings' => [],
            ],
            $this->createMock(IndexMappingProvider::class),
            $eventDispatcher
        );

        $calledCreateEvent = false;
        $eventDispatcher->addListener(ElasticsearchIndexCreatedEvent::classstatic function DElasticsearchIndexCreatedEvent $event) use (&$calledCreateEvent): void {
            $calledCreateEvent = true;
            static::assertSame('foo', $event->getIndexName());
            static::assertInstanceOf(ElasticsearchProductDefinition::class$event->getDefinition());
        });

        $calledConfigEvent = false;
        $eventDispatcher->addListener(ElasticsearchIndexConfigEvent::classfunction DElasticsearchIndexConfigEvent $event) use (&$calledConfigEvent): void {
            $calledConfigEvent = true;

            $event->setConfig($event->getConfig() + ['event' => true]);
        });

        $definition = $this->createMock(ElasticsearchProductDefinition::class);
        
private $indexConfig;

    public function __construct(string $prefix, array $indexConfig)
    {
        $this->prefix = $prefix;
        $this->indexConfig = $indexConfig;
    }

    public function createIndexConfiguration(string $name): IndexConfiguration
    {
        return new IndexConfiguration(
            $this->getIndexName($name),
            $this->getAlias($name),
            null,
            null,
            null,
            null,
            $this->indexConfig
        );
    }

    public function getPrefix(): string
    {
        
$this->createData();

            $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]);
                    
/** * @return array<string> */
    private function getPrefixes(): array
    {
        $definitions = $this->registry->getDefinitions();

        $prefixes = [];

        if ($this->helper->enabledMultilingualIndex()) {
            foreach ($definitions as $definition) {
                $prefixes[] = sprintf('%s_*', $this->helper->getIndexName($definition->getEntityDefinition()));
            }

            return $prefixes;
        }

        $languages = $this->languageProvider->getLanguages(Context::createDefaultContext());

        foreach ($languages as $language) {
            foreach ($definitions as $definition) {
                $prefixes[] = sprintf('%s_*', $this->helper->getIndexName($definition->getEntityDefinition()$language->getId()));
            }
        }
/** * @internal * * @covers \Shopware\Elasticsearch\Framework\Indexing\Event\ElasticsearchIndexCreatedEvent */
class ElasticsearchIndexCreatedEventTest extends TestCase
{
    public function testEvent(): void
    {
        $event = new ElasticsearchIndexCreatedEvent('index', $this->createMock(AbstractElasticsearchDefinition::class));
        static::assertSame('index', $event->getIndexName());
        static::assertInstanceOf(AbstractElasticsearchDefinition::class$event->getDefinition());
    }
}
$this->indexConfig = $indexConfig;
    }

    /** * @param string $mappingType * * @return IndexConfiguration */
    public function createIndexConfiguration(Shop $shop$mappingType)
    {
        return new IndexConfiguration(
            $this->getIndexName($shop$mappingType) . '_' . $this->getTimestamp(),
            $this->getIndexName($shop$mappingType),
            null,
            null,
            null,
            null,
            $this->indexConfig
        );
    }

    /** * @param string $mappingType * * @return ShopIndex */
Home | Imprint | This part of the site doesn't use cookies.