public function updateMapping(ContentType $contentType, $envs = false) { $contentType->setHavePipelines(FALSE); try { if (!empty($contentType->getFieldType())) { $pipelines = []; /**@var \AppBundle\Entity\FieldType $child */ foreach ($contentType->getFieldType()->getChildren() as $child) { if (!$child->getDeleted()) { /**@var \AppBundle\Form\DataField\DataFieldType $dataFieldType */ $dataFieldType = $this->formRegistry->getType($child->getType())->getInnerType(); $pipeline = $dataFieldType->generatePipeline($child); if ($pipeline) { $pipelines[] = $pipeline; } } } if (!empty($pipelines)) { $body = ["description" => "Extract attachment information for the content type " . $contentType->getName(), "processors" => $pipelines]; $this->client->ingest()->putPipeline(['id' => $this->instanceId . $contentType->getName(), 'body' => $body]); $contentType->setHavePipelines(TRUE); $this->session->getFlashBag()->add('notice', 'Pipelines updated/created for ' . $contentType->getName()); } } } catch (BadRequest400Exception $e) { $contentType->setHavePipelines(false); $message = json_decode($e->getPrevious()->getMessage(), true); $this->session->getFlashBag()->add('error', '<p><strong>We was not able to generate pipelines, they are disabled</strong> Please consider to update your elasticsearch cluster (>=5.0) and/or install the ingest attachment plugin (bin/elasticsearch-plugin install ingest-attachment)</p> <p>Message from Elasticsearch: <b>' . $message['error']['type'] . '</b>' . $message['error']['reason'] . '</p>'); } try { if (!$envs) { $envs = array_reduce($this->environmentService->getManagedEnvironement(), function ($envs, $item) { /**@var \AppBundle\Entity\Environment $item*/ if (isset($envs)) { $envs .= ',' . $item->getAlias(); } else { $envs = $item->getAlias(); } return $envs; }); } $body = $this->mappingService->generateMapping($contentType, $contentType->getHavePipelines()); $out = $this->client->indices()->putMapping(['index' => $envs, 'type' => $contentType->getName(), 'body' => $body]); if (isset($out['acknowledged']) && $out['acknowledged']) { $contentType->setDirty(false); if ($this->session->isStarted()) { $this->session->getFlashBag()->add('notice', 'Mappings successfully updated/created for ' . $contentType->getName() . ' in ' . $envs); } } else { $contentType->setDirty(true); $this->session->getFlashBag()->add('warning', '<p><strong>Something went wrong. Try again</strong></p> <p>Message from Elasticsearch: ' . print_r($out, true) . '</p>'); } $em = $this->doctrine->getManager(); $em->persist($contentType); $em->flush(); } catch (BadRequest400Exception $e) { $contentType->setDirty(true); $message = json_decode($e->getPrevious()->getMessage(), true); $this->session->getFlashBag()->add('error', '<p><strong>You should try to rebuild the indexes</strong></p> <p>Message from Elasticsearch: <b>' . $message['error']['type'] . '</b>' . $message['error']['reason'] . '</p>'); } }