1919use Magento \Framework \Exception \LocalizedException ;
2020use Magento \Framework \Stdlib \ArrayManager ;
2121use Psr \Log \LoggerInterface ;
22+ use Magento \AdvancedSearch \Helper \Data ;
2223
2324/**
2425 * Elasticsearch adapter
26+ * @SuppressWarnings(PHPMD.TooManyFields)
2527 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628 */
2729class Elasticsearch
@@ -110,6 +112,11 @@ class Elasticsearch
110112 */
111113 private $ arrayManager ;
112114
115+ /**
116+ * @var Data
117+ */
118+ protected $ helper ;
119+
113120 /**
114121 * @var array
115122 */
@@ -125,6 +132,7 @@ class Elasticsearch
125132 * @param LoggerInterface $logger
126133 * @param Index\IndexNameResolver $indexNameResolver
127134 * @param BatchDataMapperInterface $batchDocumentDataMapper
135+ * @param Data $helper
128136 * @param array $options
129137 * @param ProductAttributeRepositoryInterface|null $productAttributeRepository
130138 * @param StaticField|null $staticFieldProvider
@@ -141,6 +149,7 @@ public function __construct(
141149 LoggerInterface $ logger ,
142150 IndexNameResolver $ indexNameResolver ,
143151 BatchDataMapperInterface $ batchDocumentDataMapper ,
152+ Data $ helper ,
144153 $ options = [],
145154 ProductAttributeRepositoryInterface $ productAttributeRepository = null ,
146155 StaticField $ staticFieldProvider = null ,
@@ -154,6 +163,7 @@ public function __construct(
154163 $ this ->logger = $ logger ;
155164 $ this ->indexNameResolver = $ indexNameResolver ;
156165 $ this ->batchDocumentDataMapper = $ batchDocumentDataMapper ;
166+ $ this ->helper = $ helper ;
157167 $ this ->productAttributeRepository = $ productAttributeRepository ?:
158168 ObjectManager::getInstance ()->get (ProductAttributeRepositoryInterface::class);
159169 $ this ->staticFieldProvider = $ staticFieldProvider ?:
@@ -329,18 +339,30 @@ protected function getDocsArrayInBulkIndexFormat(
329339 ];
330340
331341 foreach ($ documents as $ id => $ document ) {
332- $ bulkArray ['body ' ][] = [
333- $ action => [
334- '_id ' => $ id ,
335- '_type ' => $ this ->clientConfig ->getEntityType (),
336- '_index ' => $ indexName
337- ]
338- ];
342+ if ($ this ->helper ->isClientOpenSearchV2 ()) {
343+ $ bulkArray ['body ' ][] = [
344+ $ action => [
345+ '_id ' => $ id ,
346+ '_index ' => $ indexName
347+ ]
348+ ];
349+ } else {
350+ $ bulkArray ['body ' ][] = [
351+ $ action => [
352+ '_id ' => $ id ,
353+ '_type ' => $ this ->clientConfig ->getEntityType (),
354+ '_index ' => $ indexName
355+ ]
356+ ];
357+ }
339358 if ($ action == self ::BULK_ACTION_INDEX ) {
340359 $ bulkArray ['body ' ][] = $ document ;
341360 }
342361 }
343362
363+ if ($ this ->helper ->isClientOpenSearchV2 ()) {
364+ unset($ bulkArray ['type ' ]);
365+ }
344366 return $ bulkArray ;
345367 }
346368
0 commit comments