Skip to content

Commit 1bfea58

Browse files
committed
removed type from params and adjusted array key indentation
1 parent d43251f commit 1bfea58

File tree

5 files changed

+68
-105
lines changed

5 files changed

+68
-105
lines changed

docs/crud.asciidoc

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[indexing_documents]]
22
== Indexing Documents
33

4-
IMPORTANT: Please note that mapping types will disappear from Elasticsearch, read more https://www.elastic.co/guide/en/elasticsearch/reference/7.x/removal-of-types.html[here].
4+
IMPORTANT: Please note that mapping types will disappear from Elasticsearch, read more https://www.elastic.co/guide/en/elasticsearch/reference/7.x/removal-of-types.html[here]. If you migrated types from Elasticsearch 6 to 7, you can address these with the `type` param.
55

66
When you add documents to Elasticsearch, you index JSON documents. This maps naturally to PHP associative arrays, since
77
they can easily be encoded in JSON. Therefore, in Elasticsearch-PHP you create and pass associative arrays to the client
@@ -18,12 +18,11 @@ When indexing a document, you can either provide an ID or let elasticsearch gene
1818
----
1919
$params = [
2020
'index' => 'my_index',
21-
'type' => 'my_type',
2221
'id' => 'my_id',
2322
'body' => [ 'testField' => 'abc']
2423
];
2524
26-
// Document will be indexed to my_index/my_type/my_id
25+
// Document will be indexed to my_index/_doc/my_id
2726
$response = $client->index($params);
2827
----
2928
{zwsp} +
@@ -33,24 +32,21 @@ $response = $client->index($params);
3332
----
3433
$params = [
3534
'index' => 'my_index',
36-
'type' => 'my_type',
3735
'body' => [ 'testField' => 'abc']
3836
];
3937
40-
// Document will be indexed to my_index/my_type/<autogenerated ID>
38+
// Document will be indexed to my_index/_doc/<autogenerated ID>
4139
$response = $client->index($params);
4240
----
4341
{zwsp} +
4442

45-
If you need to set other parameters, such as a `routing` value, you specify those in the array alongside the `index`,
46-
`type`, etc. For example, let's set the routing and timestamp of this new document:
43+
If you need to set other parameters, such as a `routing` value, you specify those in the array alongside the `index`, etc. For example, let's set the routing and timestamp of this new document:
4744

4845
.Additional parameters
4946
[source,php]
5047
----
5148
$params = [
5249
'index' => 'my_index',
53-
'type' => 'my_type',
5450
'id' => 'my_id',
5551
'routing' => 'company_xyz',
5652
'timestamp' => strtotime("-1d"),
@@ -77,8 +73,7 @@ for($i = 0; $i < 100; $i++) {
7773
$params['body'][] = [
7874
'index' => [
7975
'_index' => 'my_index',
80-
'_type' => 'my_type',
81-
]
76+
]
8277
];
8378
8479
$params['body'][] = [
@@ -103,7 +98,6 @@ for ($i = 1; $i <= 1234567; $i++) {
10398
$params['body'][] = [
10499
'index' => [
105100
'_index' => 'my_index',
106-
'_type' => 'my_type',
107101
'_id' => $i
108102
]
109103
];
@@ -142,11 +136,10 @@ performed by requesting a document by it's full `index/type/id` path:
142136
----
143137
$params = [
144138
'index' => 'my_index',
145-
'type' => 'my_type',
146-
'id' => 'my_id'
139+
'id' => 'my_id'
147140
];
148141
149-
// Get doc at /my_index/my_type/my_id
142+
// Get doc at /my_index/_doc/my_id
150143
$response = $client->get($params);
151144
----
152145
{zwsp} +
@@ -167,7 +160,6 @@ the `doc` in the `body` parameter. This will merge the fields in `doc` with the
167160
----
168161
$params = [
169162
'index' => 'my_index',
170-
'type' => 'my_type',
171163
'id' => 'my_id',
172164
'body' => [
173165
'doc' => [
@@ -176,7 +168,7 @@ $params = [
176168
]
177169
];
178170
179-
// Update doc at /my_index/my_type/my_id
171+
// Update doc at /my_index/_doc/my_id
180172
$response = $client->update($params);
181173
----
182174
{zwsp} +
@@ -190,7 +182,6 @@ To perform a scripted update, you need to provide a script and (usually) a set o
190182
----
191183
$params = [
192184
'index' => 'my_index',
193-
'type' => 'my_type',
194185
'id' => 'my_id',
195186
'body' => [
196187
'script' => 'ctx._source.counter += count',
@@ -213,7 +204,6 @@ does not exist (or the field you are trying to update doesn't exist), default va
213204
----
214205
$params = [
215206
'index' => 'my_index',
216-
'type' => 'my_type',
217207
'id' => 'my_id',
218208
'body' => [
219209
'script' => [
@@ -235,17 +225,16 @@ $response = $client->update($params);
235225
[[deleting_documents]]
236226
== Deleting documents
237227

238-
Finally, you can delete documents by specifying their full `/index/type/id` path:
228+
Finally, you can delete documents by specifying their full `/index/_doc_/id` path:
239229

240230
[source,php]
241231
----
242232
$params = [
243233
'index' => 'my_index',
244-
'type' => 'my_type',
245234
'id' => 'my_id'
246235
];
247236
248-
// Delete doc at /my_index/my_type/my_id
237+
// Delete doc at /my_index/_doc_/my_id
249238
$response = $client->delete($params);
250239
----
251240
{zwsp} +

docs/futures.asciidoc

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ future mode, set the `future` flag in the client options to `'lazy'`:
2525
$client = ClientBuilder::create()->build();
2626
2727
$params = [
28-
'index' => 'test',
29-
'type' => 'test',
30-
'id' => 1,
28+
'index' => 'test',
29+
'id' => 1,
3130
'client' => [
3231
'future' => 'lazy'
3332
]
@@ -53,9 +52,8 @@ act like a simple associative array. For example:
5352
$client = ClientBuilder::create()->build();
5453
5554
$params = [
56-
'index' => 'test',
57-
'type' => 'test',
58-
'id' => 1,
55+
'index' => 'test',
56+
'id' => 1,
5957
'client' => [
6058
'future' => 'lazy'
6159
]
@@ -76,9 +74,8 @@ $futures = [];
7674
7775
for ($i = 0; $i < 1000; $i++) {
7876
$params = [
79-
'index' => 'test',
80-
'type' => 'test',
81-
'id' => $i,
77+
'index' => 'test',
78+
'id' => $i,
8279
'client' => [
8380
'future' => 'lazy'
8481
]
@@ -107,9 +104,8 @@ $futures = [];
107104
108105
for ($i = 0; $i < 1000; $i++) {
109106
$params = [
110-
'index' => 'test',
111-
'type' => 'test',
112-
'id' => $i,
107+
'index' => 'test',
108+
'id' => $i,
113109
'client' => [
114110
'future' => 'lazy'
115111
]
@@ -162,9 +158,8 @@ $futures = [];
162158
163159
for ($i = 0; $i < 499; $i++) {
164160
$params = [
165-
'index' => 'test',
166-
'type' => 'test',
167-
'id' => $i,
161+
'index' => 'test',
162+
'id' => $i,
168163
'client' => [
169164
'future' => 'lazy'
170165
]
@@ -188,9 +183,8 @@ $client = ClientBuilder::create()->build();
188183
$futures = [];
189184
190185
$params = [
191-
'index' => 'test',
192-
'type' => 'test',
193-
'id' => 1,
186+
'index' => 'test',
187+
'id' => 1,
194188
'client' => [
195189
'future' => 'lazy'
196190
]
@@ -200,9 +194,8 @@ $futures['getRequest'] = $client->get($params); // First request
200194
201195
$params = [
202196
'index' => 'test',
203-
'type' => 'test',
204-
'id' => 2,
205-
'body' => [
197+
'id' => 2,
198+
'body' => [
206199
'field' => 'value'
207200
],
208201
'client' => [
@@ -214,8 +207,7 @@ $futures['indexRequest'] = $client->index($params); // Second request
214207
215208
$params = [
216209
'index' => 'test',
217-
'type' => 'test',
218-
'body' => [
210+
'body' => [
219211
'query' => [
220212
'match' => [
221213
'field' => 'value'

docs/per-request-configuration.asciidoc

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ $client = ClientBuilder::create()->build();
2323
2424
$params = [
2525
'index' => 'test_missing',
26-
'type' => 'test',
2726
'id' => 1,
2827
'client' => [ 'ignore' => 404 ] <1>
2928
];
3029
echo $client->get($params);
3130
32-
> {"_index":"test_missing","_type":"test","_id":"1","found":false}
31+
> {"_index":"test_missing","_type":"_doc","_id":"1","found":false}
3332
----
3433
<1> This will ignore just the 404 missing exception
3534

@@ -41,7 +40,6 @@ $client = ClientBuilder::create()->build();
4140
4241
$params = [
4342
'index' => 'test_missing',
44-
'type' => 'test',
4543
'client' => [ 'ignore' => [400, 404] ] <1>
4644
];
4745
echo $client->get($params);
@@ -72,14 +70,13 @@ parameter as an array of values:
7270
$client = ClientBuilder::create()->build();
7371
7472
$params = [
75-
'index' => 'test',
76-
'type' => 'test',
77-
'id' => 1,
73+
'index' => 'test',
74+
'id' => 1,
7875
'parent' => 'abc', // white-listed Elasticsearch parameter
7976
'client' => [
8077
'custom' => [
8178
'customToken' => 'abc', // user-defined, not white listed, not checked
82-
'otherToken' => 123
79+
'otherToken' => 123
8380
]
8481
]
8582
];
@@ -101,8 +98,7 @@ $client = ClientBuilder::create()->build();
10198
10299
$params = [
103100
'index' => 'test',
104-
'type' => 'test',
105-
'id' => 1
101+
'id' => 1
106102
];
107103
$response = $client->get($params);
108104
print_r($response);
@@ -111,7 +107,7 @@ print_r($response);
111107
Array
112108
(
113109
[_index] => test
114-
[_type] => test
110+
[_type] => _doc
115111
[_id] => 1
116112
[_version] => 1
117113
[found] => 1
@@ -130,9 +126,8 @@ With verbosity turned on, you will see all of the transfer stats:
130126
$client = ClientBuilder::create()->build();
131127
132128
$params = [
133-
'index' => 'test',
134-
'type' => 'test',
135-
'id' => 1,
129+
'index' => 'test',
130+
'id' => 1,
136131
'client' => [
137132
'verbose' => true
138133
]
@@ -202,7 +197,7 @@ Array
202197
[body] => Array
203198
(
204199
[_index] => test
205-
[_type] => test
200+
[_type] => _doc
206201
[_id] => 1
207202
[_version] => 1
208203
[found] => 1
@@ -236,9 +231,8 @@ client. In these situations, you will see the appropriate threadpool queue grow
236231
$client = ClientBuilder::create()->build();
237232
238233
$params = [
239-
'index' => 'test',
240-
'type' => 'test',
241-
'id' => 1,
234+
'index' => 'test',
235+
'id' => 1,
242236
'client' => [
243237
'timeout' => 10, // ten second timeout
244238
'connect_timeout' => 10
@@ -257,9 +251,8 @@ a per-request basis via the `future` parameter in the client options:
257251
$client = ClientBuilder::create()->build();
258252
259253
$params = [
260-
'index' => 'test',
261-
'type' => 'test',
262-
'id' => 1,
254+
'index' => 'test',
255+
'id' => 1,
263256
'client' => [
264257
'future' => 'lazy'
265258
]
@@ -285,9 +278,8 @@ in the client options:
285278
$client = ClientBuilder::create()->build();
286279
287280
$params = [
288-
'index' => 'test',
289-
'type' => 'test',
290-
'id' => 1,
281+
'index' => 'test',
282+
'id' => 1,
291283
'client' => [
292284
'verify' => 'path/to/cacert.pem' //Use a self-signed certificate
293285
]

0 commit comments

Comments
 (0)