Skip to content

Commit 9979894

Browse files
thePanzruflin
authored andcommitted
ES-7: remove type (#1666)
- [x] Remove mapping's include_type_name (from #1654 ) - [x] Deprecate usage of Type object - [x] copy `setMapping()` from `Type` to `Index` - [x] copy `getDocument()` from `Type` to `Index` - [x] copy `deleteById() from `Type` to `Index` - [x] copy more methods from `Type` to `Index` - [x] Cleanup `Client` methods requiring `Type` #1668 - [x] Remove `Type` class (<== needs clarification) - [x] Cleanup `Search->addType()` #1669 - [x] Cleanup `Search->addTypes()` #1669 - [x] Cleanup `Bulk` class from `Type` #1670 - [x] Fix tests
1 parent aee63ec commit 9979894

File tree

157 files changed

+1258
-4364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+1258
-4364
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ All notable changes to this project will be documented in this file based on the
66

77
### Backward Compatibility Breaks
88
* The `\Elastica\Query::$_suggest` property has been renamed to `$hasSuggest` and is now private, it should not be used from extending classes [#1679](https://github.com/ruflin/Elastica/pull/1679)
9+
* `\Elastica\Document` expects a string as ID, not an int [#1672](https://github.com/ruflin/Elastica/pull/1672).
910
* Removed `\Elastica\Query\GeohashCell` query, use `\Elastica\Query\GeoBoundingBox` instead [#1672](https://github.com/ruflin/Elastica/pull/1672).
11+
* Deprecated usage of `\Elastica\Type` class, `\Elastica\Index` class must be used instead [#1666](https://github.com/ruflin/Elastica/pull/1666)
12+
* Removed `\Elastica\Type` class, `\Elastica\Index` class must be used instead [#1666](https://github.com/ruflin/Elastica/pull/1666)
13+
* Forced index names to string in `\Elastica\Index::__construct()` [#1666](https://github.com/ruflin/Elastica/pull/1666)
14+
* Removed Type query `\Elastica\Query\Type` [#1666](https://github.com/ruflin/Elastica/pull/1666)
15+
* Removed `Elastica\Type` class, `Elastica\Index` class must be used instead [#1666](https://github.com/ruflin/Elastica/pull/1666)
16+
* Removed `type` handling from `Elastica\Search` class [#1666](https://github.com/ruflin/Elastica/pull/1666)
17+
* Removed `type` handling from `Elastica\Bulk` and `Elastica\Bulk\Action` classes [#1666](https://github.com/ruflin/Elastica/pull/1666)
18+
* Forced index names to string in `Elastica\Index::__construct()` [#1666](https://github.com/ruflin/Elastica/pull/1666)
19+
* Removed Type query `Elastica\Query\Type` [#1666](https://github.com/ruflin/Elastica/pull/1666)
1020
* Dropped support for PHP 7.0
1121
* \Elastica\AbstractUpdateAction::getOptions( $fields ) no longer supports the $underscore parameter, option names must match what elasticsearch expects.
1222
* Removed no longer supported \Elastica\Query\QueryString::setAutoGeneratePhraseQueries( $bool ) [#1622](https://github.com/ruflin/Elastica/pull/1622)

lib/Elastica/AbstractUpdateAction.php

+9-47
Original file line numberDiff line numberDiff line change
@@ -11,77 +11,39 @@
1111
class AbstractUpdateAction extends Param
1212
{
1313
/**
14-
* @var \Elastica\Document
14+
* @var Document
1515
*/
1616
protected $_upsert;
1717

1818
/**
1919
* Sets the id of the document.
20-
*
21-
* @param string|int $id
22-
*
23-
* @return $this
2420
*/
25-
public function setId($id)
21+
public function setId(string $id = null): self
2622
{
2723
return $this->setParam('_id', $id);
2824
}
2925

3026
/**
3127
* Returns document id.
3228
*
33-
* @return string|int Document id
29+
* @return string|null Document id
3430
*/
35-
public function getId()
31+
public function getId(): ?string
3632
{
3733
return $this->hasParam('_id') ? $this->getParam('_id') : null;
3834
}
3935

40-
/**
41-
* @return bool
42-
*/
43-
public function hasId()
44-
{
45-
return '' !== (string) $this->getId();
46-
}
47-
48-
/**
49-
* Sets the document type name.
50-
*
51-
* @param Type|string $type Type name
52-
*
53-
* @return $this
54-
*/
55-
public function setType($type)
56-
{
57-
if ($type instanceof Type) {
58-
$this->setIndex($type->getIndex());
59-
$type = $type->getName();
60-
}
61-
62-
return $this->setParam('_type', $type);
63-
}
64-
65-
/**
66-
* Return document type name.
67-
*
68-
* @throws \Elastica\Exception\InvalidException
69-
*
70-
* @return string Document type name
71-
*/
72-
public function getType()
36+
public function hasId(): bool
7337
{
74-
return $this->getParam('_type');
38+
return null !== $this->getId();
7539
}
7640

7741
/**
7842
* Sets the document index name.
7943
*
8044
* @param Index|string $index Index name
81-
*
82-
* @return $this
8345
*/
84-
public function setIndex($index)
46+
public function setIndex($index): self
8547
{
8648
if ($index instanceof Index) {
8749
$index = $index->getName();
@@ -394,7 +356,7 @@ public function hasReplication()
394356
}
395357

396358
/**
397-
* @param \Elastica\Document|array $data
359+
* @param Document|array $data
398360
*
399361
* @return $this
400362
*/
@@ -407,7 +369,7 @@ public function setUpsert($data)
407369
}
408370

409371
/**
410-
* @return \Elastica\Document
372+
* @return Document
411373
*/
412374
public function getUpsert()
413375
{

lib/Elastica/Aggregation/Children.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
/**
66
* Class Children.
77
*
8-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-aggregations-bucket-children-aggregation.html
8+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html
99
*/
1010
class Children extends AbstractAggregation
1111
{
1212
/**
1313
* Set the type for this aggregation.
1414
*
15-
* @param string $field the child type the buckets in the parent space should be mapped to
15+
* @param string $type the child type the buckets in the parent space should be mapped to
1616
*
1717
* @return $this
1818
*/

lib/Elastica/Aggregation/DateHistogram.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function setOffset(string $offset): self
5050
/**
5151
* Set the format for returned bucket key_as_string values.
5252
*
53-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern
53+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern
5454
*
5555
* @param string $format see link for formatting options
5656
*

lib/Elastica/Aggregation/ParentAggregation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ protected function _getBaseName()
1717
/**
1818
* Set the child type for this aggregation.
1919
*
20-
* @param string $field the child type that should be selected
20+
* @param string $type the child type that should be selected
2121
*
2222
* @return $this
2323
*/
24-
public function setType($type)
24+
public function setType($type): self
2525
{
2626
return $this->setParam('type', $type);
2727
}

lib/Elastica/Bulk.php

-36
Original file line numberDiff line numberDiff line change
@@ -80,39 +80,6 @@ public function hasIndex(): bool
8080
return null !== $this->getIndex() && '' !== $this->getIndex();
8181
}
8282

83-
/**
84-
* @param string|Type $type
85-
*
86-
* @return $this
87-
*/
88-
public function setType($type): self
89-
{
90-
if ($type instanceof Type) {
91-
$this->setIndex($type->getIndex()->getName());
92-
$type = $type->getName();
93-
}
94-
95-
$this->_type = (string) $type;
96-
97-
return $this;
98-
}
99-
100-
/**
101-
* @return string|null
102-
*/
103-
public function getType()
104-
{
105-
return $this->_type;
106-
}
107-
108-
/**
109-
* @return bool
110-
*/
111-
public function hasType(): bool
112-
{
113-
return null !== $this->getType() && '' !== $this->getType();
114-
}
115-
11683
/**
11784
* @return string
11885
*/
@@ -121,9 +88,6 @@ public function getPath(): string
12188
$path = '';
12289
if ($this->hasIndex()) {
12390
$path .= $this->getIndex().'/';
124-
if ($this->hasType()) {
125-
$path .= $this->getType().'/';
126-
}
12791
}
12892
$path .= '_bulk';
12993

lib/Elastica/Bulk/Action.php

+2-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Elastica\Bulk;
66
use Elastica\Index;
77
use Elastica\JSON;
8-
use Elastica\Type;
98

109
class Action
1110
{
@@ -143,27 +142,11 @@ public function setIndex($index): self
143142
}
144143

145144
/**
146-
* @param string|Type $type
145+
* @param string $id
147146
*
148147
* @return $this
149148
*/
150-
public function setType($type): self
151-
{
152-
if ($type instanceof Type) {
153-
$this->setIndex($type->getIndex()->getName());
154-
$type = $type->getName();
155-
}
156-
$this->_metadata['_type'] = $type;
157-
158-
return $this;
159-
}
160-
161-
/**
162-
* @param string|int $id
163-
*
164-
* @return $this
165-
*/
166-
public function setId($id): self
149+
public function setId(string $id): self
167150
{
168151
$this->_metadata['_id'] = $id;
169152

lib/Elastica/Bulk/Action/DeleteDocument.php

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ protected function _getMetadata(AbstractUpdateAction $action): array
1818
{
1919
return $action->getOptions([
2020
'_index',
21-
'_type',
2221
'_id',
2322
'version',
2423
'version_type',

lib/Elastica/Bulk/Action/IndexDocument.php

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ protected function _getMetadata(AbstractUpdateAction $action): array
3131
{
3232
return $action->getOptions([
3333
'_index',
34-
'_type',
3534
'_id',
3635
'version',
3736
'version_type',

lib/Elastica/Client.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function getConfigValue($keys, $default = null)
226226
*
227227
* @return \Elastica\Index Index for the given name
228228
*/
229-
public function getIndex($name)
229+
public function getIndex(string $name)
230230
{
231231
return new Index($this, $name);
232232
}
@@ -285,9 +285,9 @@ public function removeHeader($header)
285285
/**
286286
* Uses _bulk to send documents to the server.
287287
*
288-
* Array of \Elastica\Document as input. Index and type has to be
289-
* set inside the document, because for bulk settings documents,
290-
* documents can belong to any type and index
288+
* Array of \Elastica\Document as input. Index has to be set inside the
289+
* document, because for bulk settings documents, documents can belong to
290+
* any index
291291
*
292292
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
293293
*
@@ -317,9 +317,9 @@ public function updateDocuments(array $docs, array $requestParams = [])
317317
/**
318318
* Uses _bulk to send documents to the server.
319319
*
320-
* Array of \Elastica\Document as input. Index and type has to be
321-
* set inside the document, because for bulk settings documents,
322-
* documents can belong to any type and index
320+
* Array of \Elastica\Document as input. Index has to be set inside the
321+
* document, because for bulk settings documents, documents can belong to
322+
* any index
323323
*
324324
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
325325
*
@@ -353,19 +353,17 @@ public function addDocuments(array $docs, array $requestParams = [])
353353
* @param int|string $id document id
354354
* @param array|\Elastica\Script\AbstractScript|\Elastica\Document $data raw data for request body
355355
* @param string $index index to update
356-
* @param string $type type of index to update
357356
* @param array $options array of query params to use for query. For possible options check es api
358357
*
359358
* @return \Elastica\Response
360359
*
361360
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
362361
*/
363-
public function updateDocument($id, $data, $index, $type, array $options = [])
362+
public function updateDocument($id, $data, $index, array $options = [])
364363
{
365364
$endpoint = new Update();
366365
$endpoint->setID($id);
367366
$endpoint->setIndex($index);
368-
$endpoint->setType($type);
369367

370368
if ($data instanceof AbstractScript) {
371369
$requestData = $data->toArray();
@@ -541,22 +539,20 @@ public function setConnections(array $connections)
541539
*
542540
* @param array $ids Document ids
543541
* @param string|\Elastica\Index $index Index name
544-
* @param string|\Elastica\Type $type Type of documents
545542
* @param string|bool $routing Optional routing key for all ids
546543
*
547544
* @throws \Elastica\Exception\InvalidException
548545
*
549546
* @return \Elastica\Bulk\ResponseSet Response object
550547
*/
551-
public function deleteIds(array $ids, $index, $type, $routing = false)
548+
public function deleteIds(array $ids, $index, $routing = false)
552549
{
553550
if (empty($ids)) {
554551
throw new InvalidException('Array has to consist of at least one id');
555552
}
556553

557554
$bulk = new Bulk($this);
558555
$bulk->setIndex($index);
559-
$bulk->setType($type);
560556

561557
foreach ($ids as $id) {
562558
$action = new Action(Action::OP_TYPE_DELETE);
@@ -579,9 +575,13 @@ public function deleteIds(array $ids, $index, $type, $routing = false)
579575
* of the bulk operation. An example param array would be:
580576
*
581577
* array(
582-
* array('index' => array('_index' => 'test', '_type' => 'user', '_id' => '1')),
583-
* array('user' => array('name' => 'hans')),
584-
* array('delete' => array('_index' => 'test', '_type' => 'user', '_id' => '2'))
578+
* array('index' => array('_index' => 'test', '_id' => '1')),
579+
* array('field1' => 'value1'),
580+
* array('delete' => array('_index' => 'test', '_id' => '2')),
581+
* array('create' => array('_index' => 'test', '_id' => '3')),
582+
* array('field1' => 'value3'),
583+
* array('update' => array('_id' => '1', '_index' => 'test')),
584+
* array('doc' => array('field2' => 'value2')),
585585
* );
586586
*
587587
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html

0 commit comments

Comments
 (0)