Skip to content

Commit bc54543

Browse files
committed
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.
1 parent 0e0d87d commit bc54543

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

apps/qubit/modules/search/actions/autocompleteAction.class.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ public function execute($request)
7777
foreach ($items as $item) {
7878
$search = new \Elastica\Search($client);
7979
foreach ($indices as $type => $index) {
80-
$itemType = QubitSearch::getInstance()->index->getIndexName($item['type']);
80+
$itemType = QubitSearch::getInstance()::ES_TYPE;
8181

82-
// This will need to be updated in ES 7.x if it is updated to a dummy type,
83-
// and then removed in ES 8.x when types are no longer required.
82+
// This can be updated in ES 7.x when type params are optional
8483
$search->addIndex($index)->addType($index->getType($itemType));
8584
}
8685

plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ class arElasticSearchPlugin extends QubitSearchEngine
3030
*/
3131
public const MIN_VERSION = '1.3.0';
3232

33+
/**
34+
* Dummy type for the ElasticSearch index.
35+
* This is required in ES 6.x but it is optional in
36+
* ES 7.x and can be removed when ElasticSearch and
37+
* Elastica are upgraded.
38+
*/
39+
public const ES_TYPE = '_doc';
40+
3341
/**
3442
* Elastic_Client object.
3543
*
@@ -348,7 +356,10 @@ public function addDocument($data, $type)
348356
unset($data['id']);
349357

350358
$document = new \Elastica\Document($id, $data);
351-
$document->setType($this->index->getIndexName($type));
359+
360+
// Setting a dummy type since it is required in ES 6.x
361+
// but it can be removed in 7.x when it becomes optional
362+
$document->setType(self::ES_TYPE);
352363

353364
if (!$this->currentBatchType) {
354365
$this->currentBatchType = $type;
@@ -397,7 +408,10 @@ public function partialUpdate($object, $data)
397408
$type = get_class($object);
398409

399410
$document = new \Elastica\Document($object->id, $data);
400-
$document->setType($this->index->getIndexName($type));
411+
412+
// Setting a dummy type since it is required in ES 6.x
413+
// but it can be removed in 7.x when it becomes optional
414+
$document->setType(self::ES_TYPE);
401415

402416
try {
403417
$this->index->getIndex($type)->updateDocuments([$document]);
@@ -456,7 +470,7 @@ public function delete($object)
456470
// the document to be deleted and add this document object to the batch delete
457471
// queue.
458472
$document = new \Elastica\Document($object->id);
459-
$document->setType($this->index->getIndexName($type));
473+
$document->setType(self::ES_TYPE);
460474

461475
if ($this->currentBatchType != $type) {
462476
$this->flushBatch();
@@ -584,8 +598,9 @@ protected function initialize()
584598
// Define mapping in elasticsearch
585599
$mapping = new \Elastica\Type\Mapping();
586600

587-
// This type will need to be changed to a dummy type like _doc in 7.x
588-
$mapping->setType($index->getType($indexType));
601+
// Setting a dummy type since it is required in ES 6.x
602+
// but it can be removed in 7.x when it becomes optional
603+
$mapping->setType($index->getType(self::ES_TYPE));
589604
$mapping->setProperties($typeProperties['properties']);
590605

591606
// Parse other parameters
@@ -596,8 +611,7 @@ protected function initialize()
596611

597612
$this->log(sprintf('Defining mapping %s...', $typeName));
598613

599-
// In ES 7.x, if the mapping types are updated to a dummy type,
600-
// this should be changed to:
614+
// In ES 7.x this should be changed to:
601615
// $mapping->send($index, [ 'include_type_name' => false ])
602616
// which can be removed in 8.x since that is the default behaviour
603617
// and will have be removed by 9.x when it is discontinued

0 commit comments

Comments
 (0)