diff --git a/config/services/search-index-adapter/open-search.yaml b/config/services/search-index-adapter/open-search.yaml index 314f1d5b..0b7dec71 100644 --- a/config/services/search-index-adapter/open-search.yaml +++ b/config/services/search-index-adapter/open-search.yaml @@ -46,6 +46,8 @@ services: Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\IndexStatsServiceInterface: class: Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\IndexStatsService + arguments: + $openSearchClient: '@generic-data-index.opensearch-client' Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\IndexMappingServiceInterface: class: Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\IndexMappingService diff --git a/config/services/search/data-object/field-definition-adapters.yml b/config/services/search/data-object/field-definition-adapters.yml index 6d9389d7..787860fe 100644 --- a/config/services/search/data-object/field-definition-adapters.yml +++ b/config/services/search/data-object/field-definition-adapters.yml @@ -48,6 +48,10 @@ services: shared: false tags: - { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "quantityValue" } + + Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\DataObject\FieldDefinitionAdapter\InputQuantityValueAdapter: + shared: false + tags: - { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "inputQuantityValue" } Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\DataObject\FieldDefinitionAdapter\BooleanAdapter: diff --git a/src/SearchIndexAdapter/OpenSearch/DataObject/FieldDefinitionAdapter/InputQuantityValueAdapter.php b/src/SearchIndexAdapter/OpenSearch/DataObject/FieldDefinitionAdapter/InputQuantityValueAdapter.php new file mode 100644 index 00000000..9ddfd686 --- /dev/null +++ b/src/SearchIndexAdapter/OpenSearch/DataObject/FieldDefinitionAdapter/InputQuantityValueAdapter.php @@ -0,0 +1,39 @@ + [ + 'value' => [ + 'type' => AttributeType::KEYWORD->value, + ], + 'unitId' => [ + 'type' => AttributeType::TEXT->value, + ], + ], + ]; + } +} diff --git a/src/SearchIndexAdapter/OpenSearch/IndexStatsService.php b/src/SearchIndexAdapter/OpenSearch/IndexStatsService.php index dcaa71d4..04bc100c 100644 --- a/src/SearchIndexAdapter/OpenSearch/IndexStatsService.php +++ b/src/SearchIndexAdapter/OpenSearch/IndexStatsService.php @@ -17,6 +17,7 @@ namespace Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch; use Exception; +use OpenSearch\Client; use Pimcore\Bundle\GenericDataIndexBundle\Model\Stats\IndexStats; use Pimcore\Bundle\GenericDataIndexBundle\Model\Stats\IndexStatsIndex; use Pimcore\Bundle\GenericDataIndexBundle\Repository\IndexQueueRepository; @@ -30,9 +31,10 @@ final class IndexStatsService implements IndexStatsServiceInterface use LoggerAwareTrait; public function __construct( - protected readonly SearchIndexConfigServiceInterface $searchIndexConfigService, - protected readonly IndexQueueRepository $indexQueueRepository, - protected readonly SearchIndexServiceInterface $openSearchService, + private readonly SearchIndexConfigServiceInterface $searchIndexConfigService, + private readonly IndexQueueRepository $indexQueueRepository, + private readonly SearchIndexServiceInterface $openSearchService, + private readonly Client $openSearchClient, ) { } @@ -43,12 +45,31 @@ public function getStats(): IndexStats $this->searchIndexConfigService->getIndexPrefix() . '*' ); + $aggregationResult = $this->openSearchClient->search([ + 'index' => $this->searchIndexConfigService->getIndexPrefix() . '*', + 'body' => [ + 'size' => 0, + 'aggs' => [ + 'indices' => [ + 'terms' => [ + 'field' => '_index', + 'size' => 10000, + 'order' => [ + '_key' => 'asc', + ], + ], + ], + ], + ], + ]); + $indices = []; - foreach ($allStats['indices'] as $indexName => $index) { + foreach ($aggregationResult['aggregations']['indices']['buckets'] as $bucket) { + $sizeInBytes = (int)($allStats['indices'][$bucket['key']]['total']['store']['size_in_bytes'] ?? 0); $indices[] = new IndexStatsIndex( - indexName: $indexName, - itemsCount: $index['total']['docs']['count'], - sizeInKb: round(((int)$index['total']['store']['size_in_bytes'] / 1024), 2) + indexName: $bucket['key'], + itemsCount: $bucket['doc_count'], + sizeInKb: round(($sizeInBytes / 1024), 2) ); }