config = $config; $this->dynamicTemplateMapper = $dynamicTemplateMapper; } public function execute(string $index, int $storeId, array $fields): array { $entityType = $this->config->getEntityType(); $params = [ 'index' => $index, 'type' => $entityType, 'body' => [ $entityType => [ 'properties' => [], 'dynamic_templates' => [ $this->dynamicTemplateMapper->map($storeId) ], 'numeric_detection' => false, ] ] ]; $isAllowSpecialChars = $this->config->allowSpecialChars($storeId); $hasStemming = $this->config->hasStemming($storeId); foreach ($fields as $field => $fieldInfo) { if ($fieldInfo['type'] === Product::ATTRIBUTE_TYPE_TEXT) { $fieldInfo['fielddata'] = true; if ($isAllowSpecialChars) { $fieldInfo['analyzer'] = 'allow_spec_chars'; } if ($hasStemming) { $fieldInfo['fields']['stemming'] = [ 'type' => Product::ATTRIBUTE_TYPE_TEXT, 'fielddata' => true, 'analyzer' => 'stem', 'index' => true ]; } } $params['body'][$entityType]['properties'][$field] = $fieldInfo; } $params['include_type_name'] = true; return $params; } }