Skip to content

Commit

Permalink
Integrated Elasticsearch 8 and deprecated Elasticsearch 7 integration (
Browse files Browse the repository at this point in the history
…pimcore#13410)

* integrated pimcore/elasticsearch-client and elasticsearch 8, deprecated elasticsearch 7

* updated docs and phpstan

* updated dependencies

* added upgrade notes

* updated dependencies

* phpstan fixes

* phpstan fixes

* phpstan fixes

* phpstan fixes

* phpstan fixes

* phpstan fixes

* phpstan fixes

* phpstan fixes

* phpstan fixes

* phpstan fixes

* phpstan fixes

* phpstan fixes
  • Loading branch information
fashxp authored Dec 7, 2022
1 parent a2ea7bd commit 107bdcc
Show file tree
Hide file tree
Showing 12 changed files with 719 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceSystemLocator;
use Pimcore\Bundle\EcommerceFrameworkBundle\PricingManager\PricingManagerLocator;
use Pimcore\Bundle\EcommerceFrameworkBundle\PricingManager\PricingManagerLocatorInterface;
use Pimcore\Bundle\ElasticsearchClientBundle\DependencyInjection\PimcoreElasticsearchClientExtension;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ChildDefinition;
Expand Down Expand Up @@ -465,6 +466,13 @@ private function registerIndexServiceConfig(ContainerBuilder $container, array $
$worker->setArgument('$tenantConfig', new Reference($configId));
$worker->addTag('pimcore_ecommerce.index_service.worker', ['tenant' => $tenant]);

if(!empty($tenantConfig['config_options']['es_client_name'])) {
$worker->addMethodCall(
'setElasticSearchClient',
[new Reference(PimcoreElasticsearchClientExtension::CLIENT_SERVICE_PREFIX . $tenantConfig['config_options']['es_client_name'])]
);
}

$container->setDefinition($configId, $config);
$container->setDefinition($workerId, $worker);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ protected function configureOptionsResolver(string $resolverName, OptionsResolve

$resolver->setDefault('store', true);
$resolver->setAllowedTypes('store', 'bool');

$resolver->setDefined('es_client_name');
$resolver->setAllowedTypes('es_client_name', 'string');

//set options to deprecated
$resolver->setDeprecated('es_client_params');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

namespace Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ElasticSearch;

/**
* @deprecated
*/
class DefaultElasticSearch7 extends AbstractElasticSearch
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ElasticSearch;

use Elastic\Elasticsearch\Client;

class DefaultElasticSearch8 extends AbstractElasticSearch
{

/**
* send a request to elasticsearch
*
* @param array $params
*
* @return array
*/
protected function sendRequest(array $params)
{
/**
* @var Client $esClient
*/
$esClient = $this->tenantConfig->getTenantWorker()->getElasticSearchClient();
$result = [];

if ($esClient instanceof Client) {
if ($this->doScrollRequest) {
$params = array_merge(['scroll' => $this->scrollRequestKeepAlive], $params);
//kind of dirty hack :/
$params['body']['size'] = $this->getLimit();
}

$result = $esClient->search($params)->asArray();

if ($this->doScrollRequest) {
$additionalHits = [];
$scrollId = $result['_scroll_id'];

while (true) {
$additionalResult = $esClient->scroll(['scroll_id' => $scrollId, 'scroll' => $this->scrollRequestKeepAlive])->asArray();

if (count($additionalResult['hits']['hits'])) {
$additionalHits = array_merge($additionalHits, $additionalResult['hits']['hits']);
$scrollId = $additionalResult['_scroll_id'];
} else {
break;
}
}
$result['hits']['hits'] = array_merge($result['hits']['hits'], $additionalHits);
}
}

return $result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
namespace Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\Worker\ElasticSearch;

/**
* Use this for ES Version >= 7
* Use this for ES Version = 7
* @deprecated
*/
class DefaultElasticSearch7 extends AbstractElasticSearch
{
Expand Down
Loading

0 comments on commit 107bdcc

Please sign in to comment.