|
| __construct (\Magento\Elasticsearch\SearchAdapter\ConnectionManager $connectionManager, DataMapperInterface $documentDataMapper, FieldMapperInterface $fieldMapper, \Magento\Elasticsearch\Model\Config $clientConfig, \Magento\Elasticsearch\Model\Adapter\Index\BuilderInterface $indexBuilder, \Psr\Log\LoggerInterface $logger, \Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver $indexNameResolver, $options=[], BatchDataMapperInterface $batchDocumentDataMapper=null) |
|
| ping () |
|
| prepareDocsPerStore (array $documentData, $storeId) |
|
| addDocs (array $documents, $storeId, $mappedIndexerId) |
|
| cleanIndex ($storeId, $mappedIndexerId) |
|
| deleteDocs (array $documentIds, $storeId, $mappedIndexerId) |
|
| checkIndex ( $storeId, $mappedIndexerId, $checkAlias=true) |
|
| updateAlias ($storeId, $mappedIndexerId) |
|
Elasticsearch adapter @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Definition at line 15 of file Elasticsearch.php.
◆ __construct()
Constructor for Elasticsearch adapter.
- Parameters
-
\Magento\Elasticsearch\SearchAdapter\ConnectionManager | $connectionManager | |
DataMapperInterface | $documentDataMapper | |
FieldMapperInterface | $fieldMapper | |
\Magento\Elasticsearch\Model\Config | $clientConfig | |
\Magento\Elasticsearch\Model\Adapter\Index\BuilderInterface | $indexBuilder | |
\Psr\Log\LoggerInterface | $logger | |
\Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver | $indexNameResolver | |
array | $options | |
BatchDataMapperInterface | $batchDocumentDataMapper | |
- Exceptions
-
Definition at line 94 of file Elasticsearch.php.
112 $this->batchDocumentDataMapper = $batchDocumentDataMapper ?:
116 $this->client = $this->connectionManager->getConnection(
$options);
117 }
catch (\Exception $e) {
118 $this->logger->critical($e);
119 throw new \Magento\Framework\Exception\LocalizedException(
120 __(
'The search failed because of a search engine misconfiguration.')
◆ addDocs()
addDocs |
( |
array |
$documents, |
|
|
|
$storeId, |
|
|
|
$mappedIndexerId |
|
) |
| |
Add prepared Elasticsearch documents to Elasticsearch index
- Parameters
-
array | $documents | |
int | $storeId | |
string | $mappedIndexerId | |
- Returns
- $this
- Exceptions
-
Definition at line 171 of file Elasticsearch.php.
173 if (count($documents)) {
175 $indexName = $this->indexNameResolver->getIndexName(
$storeId, $mappedIndexerId, $this->preparedIndex);
177 $this->client->bulkQuery($bulkIndexDocuments);
178 }
catch (\Exception $e) {
179 $this->logger->critical($e);
getDocsArrayInBulkIndexFormat( $documents, $indexName, $action=self::BULK_ACTION_INDEX)
◆ checkIndex()
checkIndex |
( |
|
$storeId, |
|
|
|
$mappedIndexerId, |
|
|
|
$checkAlias = true |
|
) |
| |
Checks whether Elasticsearch index and alias exists.
- Parameters
-
int | $storeId | |
string | $mappedIndexerId | |
bool | $checkAlias | |
- Returns
- $this
Definition at line 291 of file Elasticsearch.php.
297 $indexName = $this->indexNameResolver->getIndexName(
$storeId, $mappedIndexerId, $this->preparedIndex);
298 if (!$this->client->indexExists($indexName)) {
304 $namespace = $this->indexNameResolver->getIndexNameForAlias(
$storeId, $mappedIndexerId);
305 if (!$this->client->existsAlias($namespace, $indexName)) {
306 $this->client->updateAlias($namespace, $indexName);
prepareIndex($storeId, $indexName, $mappedIndexerId)
◆ cleanIndex()
cleanIndex |
( |
|
$storeId, |
|
|
|
$mappedIndexerId |
|
) |
| |
Removes all documents from Elasticsearch index
- Parameters
-
int | $storeId | |
string | $mappedIndexerId | |
- Returns
- $this
Definition at line 194 of file Elasticsearch.php.
197 $indexName = $this->indexNameResolver->getIndexName(
$storeId, $mappedIndexerId, $this->preparedIndex);
198 if ($this->client->isEmptyIndex($indexName)) {
204 $indexPattern = $this->indexNameResolver->getIndexPattern(
$storeId, $mappedIndexerId);
205 $version = intval(str_replace($indexPattern,
'', $indexName));
206 $newIndexName = $indexPattern . ++
$version;
209 if ($this->client->indexExists($newIndexName)) {
210 $this->client->deleteIndex($newIndexName);
checkIndex( $storeId, $mappedIndexerId, $checkAlias=true)
prepareIndex($storeId, $indexName, $mappedIndexerId)
◆ deleteDocs()
deleteDocs |
( |
array |
$documentIds, |
|
|
|
$storeId, |
|
|
|
$mappedIndexerId |
|
) |
| |
Delete documents from Elasticsearch index by Ids
- Parameters
-
array | $documentIds | |
int | $storeId | |
string | $mappedIndexerId | |
- Returns
- $this
- Exceptions
-
Definition at line 228 of file Elasticsearch.php.
232 $indexName = $this->indexNameResolver->getIndexName(
$storeId, $mappedIndexerId, $this->preparedIndex);
236 self::BULK_ACTION_DELETE
238 $this->client->bulkQuery($bulkDeleteDocuments);
239 }
catch (\Exception $e) {
240 $this->logger->critical($e);
checkIndex( $storeId, $mappedIndexerId, $checkAlias=true)
getDocsArrayInBulkIndexFormat( $documents, $indexName, $action=self::BULK_ACTION_INDEX)
◆ getDocsArrayInBulkIndexFormat()
getDocsArrayInBulkIndexFormat |
( |
|
$documents, |
|
|
|
$indexName, |
|
|
|
$action = self::BULK_ACTION_INDEX |
|
) |
| |
|
protected |
Reformat documents array to bulk format
- Parameters
-
array | $documents | |
string | $indexName | |
string | $action | |
- Returns
- array
Definition at line 255 of file Elasticsearch.php.
261 'index' => $indexName,
262 'type' => $this->clientConfig->getEntityType(),
267 foreach ($documents as
$id => $document) {
268 $bulkArray[
'body'][] = [
271 '_type' => $this->clientConfig->getEntityType(),
272 '_index' => $indexName
275 if ($action == self::BULK_ACTION_INDEX) {
276 $bulkArray[
'body'][] = $document;
◆ ping()
Retrieve Elasticsearch server status
- Returns
- bool
- Exceptions
-
Definition at line 131 of file Elasticsearch.php.
135 }
catch (\Exception $e) {
136 throw new \Magento\Framework\Exception\LocalizedException(
137 __(
'Could not ping search engine: %1', $e->getMessage())
◆ prepareDocsPerStore()
prepareDocsPerStore |
( |
array |
$documentData, |
|
|
|
$storeId |
|
) |
| |
Create Elasticsearch documents by specified data
- Parameters
-
array | $documentData | |
int | $storeId | |
- Returns
- array
Definition at line 150 of file Elasticsearch.php.
153 if (count($documentData)) {
154 $documents = $this->batchDocumentDataMapper->map(
◆ prepareIndex()
prepareIndex |
( |
|
$storeId, |
|
|
|
$indexName, |
|
|
|
$mappedIndexerId |
|
) |
| |
|
protected |
Create new index with mapping.
- Parameters
-
int | $storeId | |
string | $indexName | |
string | $mappedIndexerId | |
- Returns
- $this
Definition at line 352 of file Elasticsearch.php.
354 $this->indexBuilder->setStoreId(
$storeId);
355 $settings = $this->indexBuilder->build();
356 $allAttributeTypes = $this->fieldMapper->getAllAttributesTypes([
357 'entityType' => $mappedIndexerId,
362 $settings[
'index'][
'mapping'][
'total_fields'][
'limit'] = $this->getMappingTotalFieldsLimit($allAttributeTypes);
363 $this->client->createIndex($indexName, [
'settings' =>
$settings]);
364 $this->client->addFieldsMapping(
367 $this->clientConfig->getEntityType()
369 $this->preparedIndex[
$storeId] = $indexName;
◆ updateAlias()
updateAlias |
( |
|
$storeId, |
|
|
|
$mappedIndexerId |
|
) |
| |
Update Elasticsearch alias for new index.
- Parameters
-
int | $storeId | |
string | $mappedIndexerId | |
- Returns
- $this
Definition at line 319 of file Elasticsearch.php.
321 if (!isset($this->preparedIndex[
$storeId])) {
325 $oldIndex = $this->indexNameResolver->getIndexFromAlias(
$storeId, $mappedIndexerId);
326 if ($oldIndex == $this->preparedIndex[
$storeId]) {
330 $this->client->updateAlias(
331 $this->indexNameResolver->getIndexNameForAlias(
$storeId, $mappedIndexerId),
338 $this->client->deleteIndex($oldIndex);
◆ $client
◆ $clientConfig
◆ $connectionManager
◆ $documentDataMapper
◆ $fieldMapper
◆ $indexBuilder
◆ $indexNameResolver
◆ $logger
◆ $preparedIndex
◆ BULK_ACTION_CREATE
const BULK_ACTION_CREATE = 'create' |
◆ BULK_ACTION_DELETE
const BULK_ACTION_DELETE = 'delete' |
◆ BULK_ACTION_INDEX
const BULK_ACTION_INDEX = 'index' |
◆ BULK_ACTION_UPDATE
const BULK_ACTION_UPDATE = 'update' |
The documentation for this class was generated from the following file: