Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature data ingest #648

Merged
merged 19 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* @category Smile_Elasticsuite
* @package Smile\ElasticsuiteCore
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*
* @deprecated Use Smile\ElasticsuiteCore\Api\Client\ClientInterface instead.
*/
interface ClientFactoryInterface
{
Expand Down
162 changes: 162 additions & 0 deletions src/module-elasticsuite-core/Api/Client/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php
/**
* DISCLAIMER :
*
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile_Elasticsuite
* @package Smile\ElasticsuiteCore
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2016 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCore\Api\Client;

/**
* ElasticSearch injectable client.
*
* @category Smile_Elasticsuite
* @package Smile\ElasticsuiteCore
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*/
interface ClientInterface
{
/**
* Returns server information.
*
* @return array
*/
public function info();

/**
* Try to connect the server and returns :
* - true if succeed
* - false if failed
*
* @return boolean
*/
public function ping();

/**
* Create an index.
*
* @param string $indexName Index name.
* @param array $indexSettings Index settings.
*
* @return void
*/
public function createIndex($indexName, $indexSettings);

/**
* Delete an index.
*
* @param string $indexName Index name.
*
* @return void
*/
public function deleteIndex($indexName);

/**
* Check if an index exists.
*
* @param string $indexName Index name.
*
* @return boolean
*/
public function indexExists($indexName);

/**
* Update index settings.
*
* @param string $indexName Index name.
* @param array $indexSettings Index settings.
*
* @return void
*/
public function putIndexSettings($indexName, $indexSettings);

/**
* Update index mapping.
*
* @param string $indexName Index name.
* @param string $type Type.
* @param array $mapping Mapping definition.
*
* @return void
*/
public function putMapping($indexName, $type, $mapping);

/**
* Optimize an index (force segment merging).
*
* @param string $indexName Index name.
*
* @return void
*/
public function forceMerge($indexName);

/**
* Force index refresh.
*
* @param string $indexName Index name.
*
* @return void
*/
public function refreshIndex($indexName);

/**
* Retrieve the list of all index having a specified alias.
*
* @param string $indexAlias Index alias.
*
* @return string[]
*/
public function getIndicesNameByAlias($indexAlias);

/**
* Update alias definition.
*
* @param array $aliasActions Alias actions.
*
* @return void
*/
public function updateAliases($aliasActions);

/**
* Run a bulk request.
*
* @param array $bulkParams Bulk data.
*
* return array
*/
public function bulk($bulkParams);

/**
* Run a search request.
*
* @param array $params Search request params.
*
* @return array
*/
public function search($params);

/**
* Returns index stats.
*
* @param string $indexName Index name.
*
* @return array
*/
public function indexStats($indexName);

/**
* Run a termvectors request.
*
* @param array $params Term vectors request params.
*
* @return array
*/
public function termvectors($params);
}
171 changes: 171 additions & 0 deletions src/module-elasticsuite-core/Client/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php
/**
* DISCLAIMER :
*
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile_Elasticsuite
* @package Smile\ElasticsuiteCore
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2016 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCore\Client;

use Smile\ElasticsuiteCore\Api\Client\ClientInterface;

/**
* ElasticSearch client implementation.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*
* @SuppressWarnings(TooManyPublicMethods)
*/
class Client implements ClientInterface
{
/**
* @var \Elasticsearch\Client
*/
private $esClient;

/**
* Constructor.
*
* @param ClientFactory $esClientFactory ElasticSearch client factory.
*/
public function __construct(ClientFactory $esClientFactory)
{
$this->esClient = $esClientFactory->createClient();
}

/**
* {@inheritDoc}
*/
public function info()
{
return $this->esClient->info();
}

/**
* {@inheritDoc}
*/
public function ping()
{
return $this->esClient->ping();
}

/**
* {@inheritDoc}
*/
public function createIndex($indexName, $indexSettings)
{
$this->esClient->indices()->create(['index' => $indexName, 'body' => $indexSettings]);
}

/**
* {@inheritDoc}
*/
public function deleteIndex($indexName)
{
$this->esClient->indices()->delete(['index' => $indexName]);
}

/**
* {@inheritDoc}
*/
public function indexExists($indexName)
{
return $this->esClient->indices()->exists(['index' => $indexName]);
}

/**
* {@inheritDoc}
*/
public function putIndexSettings($indexName, $indexSettings)
{
$this->esClient->indices()->putSettings(['index' => $indexName, 'body' => $indexSettings]);
}

/**
* {@inheritDoc}
*/
public function putMapping($indexName, $type, $mapping)
{
$this->esClient->indices()->putMapping(['index' => $indexName, 'type' => $type, 'body' => [$type => $mapping]]);
}

/**
* {@inheritDoc}
*/
public function forceMerge($indexName)
{
$this->esClient->indices()->forceMerge(['index' => $indexName]);
}

/**
* {@inheritDoc}
*/
public function refreshIndex($indexName)
{
$this->esClient->indices()->refresh(['index' => $indexName]);
}

/**
* {@inheritDoc}
*/
public function getIndicesNameByAlias($indexAlias)
{
$indices = [];
try {
$indices = $this->esClient->indices()->getMapping(['index' => $indexAlias]);
} catch (\Elasticsearch\Common\Exceptions\Missing404Exception $e) {
;
}

return array_keys($indices);
}

/**
* {@inheritDoc}
*/
public function updateAliases($aliasActions)
{
$this->esClient->indices()->updateAliases(['body' => ['actions' => $aliasActions]]);
}

/**
* {@inheritDoc}
*/
public function bulk($bulkParams)
{
return $this->esClient->bulk($bulkParams);
}

/**
* {@inheritDoc}
*/
public function search($params)
{
return $this->esClient->search($params);
}

/**
* {@inheritDoc}
*/
public function indexStats($indexName)
{
return $this->esClient->indices()->stats(['index' => $indexName]);
}

/**
* {@inheritDoc}
*/
public function termvectors($params)
{
return $this->esClient->termvectors($params);
}
}
2 changes: 2 additions & 0 deletions src/module-elasticsuite-core/Client/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*
* @deprecated Use Smile\ElasticsuiteCore\Api\Client\ClientInterface instead.
*/
class ClientFactory implements ClientFactoryInterface
{
Expand Down
8 changes: 4 additions & 4 deletions src/module-elasticsuite-core/Cluster/ClusterInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class ClusterInfo implements ClusterInfoInterface
{
/**
* @var \Elasticsearch\Client
* @var \Smile\ElasticsuiteCore\Api\Client\ClientInterface
*/
private $client;

Expand All @@ -38,11 +38,11 @@ class ClusterInfo implements ClusterInfoInterface
/**
* Constructor.
*
* @param \Smile\ElasticsuiteCore\Api\Client\ClientFactoryInterface $clientFactory ElasticSearch client factory.
* @param \Smile\ElasticsuiteCore\Api\Client\ClientInterface $client ElasticSearch client.
*/
public function __construct(\Smile\ElasticsuiteCore\Api\Client\ClientFactoryInterface $clientFactory)
public function __construct(\Smile\ElasticsuiteCore\Api\Client\ClientInterface $client)
{
$this->client = $clientFactory->createClient();
$this->client = $client;
}

/**
Expand Down
Loading