@@ -30,6 +30,14 @@ class arElasticSearchPlugin extends QubitSearchEngine
30
30
*/
31
31
public const MIN_VERSION = '1.3.0 ' ;
32
32
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
+
33
41
/**
34
42
* Elastic_Client object.
35
43
*
@@ -348,7 +356,10 @@ public function addDocument($data, $type)
348
356
unset($ data ['id ' ]);
349
357
350
358
$ 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 );
352
363
353
364
if (!$ this ->currentBatchType ) {
354
365
$ this ->currentBatchType = $ type ;
@@ -397,7 +408,10 @@ public function partialUpdate($object, $data)
397
408
$ type = get_class ($ object );
398
409
399
410
$ 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 );
401
415
402
416
try {
403
417
$ this ->index ->getIndex ($ type )->updateDocuments ([$ document ]);
@@ -456,7 +470,7 @@ public function delete($object)
456
470
// the document to be deleted and add this document object to the batch delete
457
471
// queue.
458
472
$ document = new \Elastica \Document ($ object ->id );
459
- $ document ->setType ($ this -> index -> getIndexName ( $ type ) );
473
+ $ document ->setType (self :: ES_TYPE );
460
474
461
475
if ($ this ->currentBatchType != $ type ) {
462
476
$ this ->flushBatch ();
@@ -584,8 +598,9 @@ protected function initialize()
584
598
// Define mapping in elasticsearch
585
599
$ mapping = new \Elastica \Type \Mapping ();
586
600
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 ));
589
604
$ mapping ->setProperties ($ typeProperties ['properties ' ]);
590
605
591
606
// Parse other parameters
@@ -596,8 +611,7 @@ protected function initialize()
596
611
597
612
$ this ->log (sprintf ('Defining mapping %s... ' , $ typeName ));
598
613
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:
601
615
// $mapping->send($index, [ 'include_type_name' => false ])
602
616
// which can be removed in 8.x since that is the default behaviour
603
617
// and will have be removed by 9.x when it is discontinued
0 commit comments