Skip to content
Snippets Groups Projects

Allow analyzers

Closed Michael Strelan requested to merge issue/data_pipelines-3402995:3402995-analyzers into 1.x
1 unresolved thread
3 files
+ 47
3
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -271,11 +271,13 @@ class ElasticSearchDestination extends DatasetDestinationPluginBase implements C
* The index ID.
* @param array $mappings
* The mapping information of the index.
* @param array $analysis
* The analysis information of the index.
*
* @throws \Drupal\data_pipelines_elasticsearch\Exception\CouldNotCreateIndexException
* When the index can't be created.
*/
protected function createIndex(string $index_id, array $mappings): void {
protected function createIndex(string $index_id, array $mappings, array $analysis): void {
$index_params = [];
$index_params_base = [];
$index_params_base['index'] = $index_id;
@@ -289,6 +291,9 @@ class ElasticSearchDestination extends DatasetDestinationPluginBase implements C
if (!empty($mappings)) {
$index_params['body']['mappings'] = $mappings;
}
if (!empty($analysis)) {
$index_params['body']['settings']['analysis'] = $analysis;
}
try {
if ($this->getClient()->indices()->exists($index_params_base)) {
return;
@@ -314,14 +319,16 @@ class ElasticSearchDestination extends DatasetDestinationPluginBase implements C
public function beginProcessing(DatasetInterface $dataset): bool {
parent::beginProcessing($dataset);
$mappings = [];
$analysis = [];
$pipeline_plugin_id = $dataset->getPipelineId();
if ($this->pipelineManager->hasDefinition($pipeline_plugin_id)) {
$pipeline_definition = $this->pipelineManager->getDefinition($pipeline_plugin_id);
$mappings = $pipeline_definition['mappings'] ?? [];
$analysis = $pipeline_definition['analysis'] ?? [];
}
$index_id = $this->configuration['prefix'] . $dataset->getMachineName();
try {
$this->createIndex($index_id, $mappings);
$this->createIndex($index_id, $mappings, $analysis);
return TRUE;
}
catch (\Exception $e) {
Loading