From a37039a9b62793d66b6356b9c814ddd8aa4a4852 Mon Sep 17 00:00:00 2001 From: Anvit Srivastav Date: Mon, 18 Nov 2024 16:45:07 -0800 Subject: [PATCH] Add dummy type for ES index Add a dummy ElasticSearch index type since one is still required for ES 6.x, instead of having a seperate type name for each of the multiple indices. --- .../actions/autocompleteAction.class.php | 5 ++-- .../lib/arElasticSearchPlugin.class.php | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/apps/qubit/modules/search/actions/autocompleteAction.class.php b/apps/qubit/modules/search/actions/autocompleteAction.class.php index d462bb82bc..942afadfc4 100644 --- a/apps/qubit/modules/search/actions/autocompleteAction.class.php +++ b/apps/qubit/modules/search/actions/autocompleteAction.class.php @@ -77,10 +77,9 @@ public function execute($request) foreach ($items as $item) { $search = new \Elastica\Search($client); foreach ($indices as $type => $index) { - $itemType = QubitSearch::getInstance()->index->getIndexName($item['type']); + $itemType = QubitSearch::getInstance()::ES_TYPE; - // This will need to be updated in ES 7.x if it is updated to a dummy type, - // and then removed in ES 8.x when types are no longer required. + // This can be updated in ES 7.x when type params are optional $search->addIndex($index)->addType($index->getType($itemType)); } diff --git a/plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php b/plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php index e851786d0b..9450dc4b43 100644 --- a/plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php +++ b/plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php @@ -30,6 +30,14 @@ class arElasticSearchPlugin extends QubitSearchEngine */ public const MIN_VERSION = '1.3.0'; + /** + * Dummy type for the ElasticSearch index. + * This is required in ES 6.x but it is optional in + * ES 7.x and can be removed when ElasticSearch and + * Elastica are upgraded + */ + public const ES_TYPE = '_doc'; + /** * Elastic_Client object. * @@ -348,7 +356,10 @@ public function addDocument($data, $type) unset($data['id']); $document = new \Elastica\Document($id, $data); - $document->setType($this->index->getIndexName($type)); + + // Setting a dummy type since it is required in ES 6.x + // but it can be removed in 7.x when it becomes optional + $document->setType(self::ES_TYPE); if (!$this->currentBatchType) { $this->currentBatchType = $type; @@ -397,7 +408,10 @@ public function partialUpdate($object, $data) $type = get_class($object); $document = new \Elastica\Document($object->id, $data); - $document->setType($this->index->getIndexName($type)); + + // Setting a dummy type since it is required in ES 6.x + // but it can be removed in 7.x when it becomes optional + $document->setType(self::ES_TYPE); try { $this->index->getIndex($type)->updateDocuments([$document]); @@ -584,8 +598,9 @@ protected function initialize() // Define mapping in elasticsearch $mapping = new \Elastica\Type\Mapping(); - // This type will need to be changed to a dummy type like _doc in 7.x - $mapping->setType($index->getType($indexType)); + // Setting a dummy type since it is required in ES 6.x + // but it can be removed in 7.x when it becomes optional + $mapping->setType($index->getType(self::ES_TYPE)); $mapping->setProperties($typeProperties['properties']); // Parse other parameters @@ -596,8 +611,7 @@ protected function initialize() $this->log(sprintf('Defining mapping %s...', $typeName)); - // In ES 7.x, if the mapping types are updated to a dummy type, - // this should be changed to: + // In ES 7.x this should be changed to: // $mapping->send($index, [ 'include_type_name' => false ]) // which can be removed in 8.x since that is the default behaviour // and will have be removed by 9.x when it is discontinued