Skip to content

Commit be6ae7b

Browse files
committed
added note about removal mapping types and adapted indentation
1 parent 53b4cec commit be6ae7b

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

docs/crud.asciidoc

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

4+
IMPORTANT: Please note that mapping types will disappear from Elasticsearch, https://www.elastic.co/guide/en/elasticsearch/reference/7.x/removal-of-types.html[Link: read more].
5+
46
When you add documents to Elasticsearch, you index JSON documents. This maps naturally to PHP associative arrays, since
57
they can easily be encoded in JSON. Therefore, in Elasticsearch-PHP you create and pass associative arrays to the client
6-
for indexing. There are several methods of ingesting data into Elasticsearch, which we will cover here
8+
for indexing. There are several methods of ingesting data into Elasticsearch, which we will cover here.
79

810
=== Single document indexing
911

@@ -16,9 +18,9 @@ When indexing a document, you can either provide an ID or let elasticsearch gene
1618
----
1719
$params = [
1820
'index' => 'my_index',
19-
'type' => 'my_type',
20-
'id' => 'my_id',
21-
'body' => [ 'testField' => 'abc']
21+
'type' => 'my_type',
22+
'id' => 'my_id',
23+
'body' => [ 'testField' => 'abc']
2224
];
2325
2426
// Document will be indexed to my_index/my_type/my_id
@@ -31,8 +33,8 @@ $response = $client->index($params);
3133
----
3234
$params = [
3335
'index' => 'my_index',
34-
'type' => 'my_type',
35-
'body' => [ 'testField' => 'abc']
36+
'type' => 'my_type',
37+
'body' => [ 'testField' => 'abc']
3638
];
3739
3840
// Document will be indexed to my_index/my_type/<autogenerated ID>
@@ -47,12 +49,12 @@ If you need to set other parameters, such as a `routing` value, you specify thos
4749
[source,php]
4850
----
4951
$params = [
50-
'index' => 'my_index',
51-
'type' => 'my_type',
52-
'id' => 'my_id',
53-
'routing' => 'company_xyz',
52+
'index' => 'my_index',
53+
'type' => 'my_type',
54+
'id' => 'my_id',
55+
'routing' => 'company_xyz',
5456
'timestamp' => strtotime("-1d"),
55-
'body' => [ 'testField' => 'abc']
57+
'body' => [ 'testField' => 'abc']
5658
];
5759
5860
@@ -75,12 +77,12 @@ for($i = 0; $i < 100; $i++) {
7577
$params['body'][] = [
7678
'index' => [
7779
'_index' => 'my_index',
78-
'_type' => 'my_type',
80+
'_type' => 'my_type',
7981
]
8082
];
8183
8284
$params['body'][] = [
83-
'my_field' => 'my_value',
85+
'my_field' => 'my_value',
8486
'second_field' => 'some more values'
8587
];
8688
}
@@ -101,13 +103,13 @@ for ($i = 1; $i <= 1234567; $i++) {
101103
$params['body'][] = [
102104
'index' => [
103105
'_index' => 'my_index',
104-
'_type' => 'my_type',
105-
'_id' => $i
106+
'_type' => 'my_type',
107+
'_id' => $i
106108
]
107109
];
108110
109111
$params['body'][] = [
110-
'my_field' => 'my_value',
112+
'my_field' => 'my_value',
111113
'second_field' => 'some more values'
112114
];
113115
@@ -141,7 +143,7 @@ performed by requesting a document by it's full `index/type/id` path:
141143
$params = [
142144
'index' => 'my_index',
143145
'type' => 'my_type',
144-
'id' => 'my_id'
146+
'id' => 'my_id'
145147
];
146148
147149
// Get doc at /my_index/my_type/my_id
@@ -165,9 +167,9 @@ the `doc` in the `body` parameter. This will merge the fields in `doc` with the
165167
----
166168
$params = [
167169
'index' => 'my_index',
168-
'type' => 'my_type',
169-
'id' => 'my_id',
170-
'body' => [
170+
'type' => 'my_type',
171+
'id' => 'my_id',
172+
'body' => [
171173
'doc' => [
172174
'new_field' => 'abc'
173175
]
@@ -188,9 +190,9 @@ To perform a scripted update, you need to provide a script and (usually) a set o
188190
----
189191
$params = [
190192
'index' => 'my_index',
191-
'type' => 'my_type',
192-
'id' => 'my_id',
193-
'body' => [
193+
'type' => 'my_type',
194+
'id' => 'my_id',
195+
'body' => [
194196
'script' => 'ctx._source.counter += count',
195197
'params' => [
196198
'count' => 4
@@ -211,9 +213,9 @@ does not exist (or the field you are trying to update doesn't exist), default va
211213
----
212214
$params = [
213215
'index' => 'my_index',
214-
'type' => 'my_type',
215-
'id' => 'my_id',
216-
'body' => [
216+
'type' => 'my_type',
217+
'id' => 'my_id',
218+
'body' => [
217219
'script' => [
218220
'source' => 'ctx._source.counter += params.count',
219221
'params' => [
@@ -239,8 +241,8 @@ Finally, you can delete documents by specifying their full `/index/type/id` path
239241
----
240242
$params = [
241243
'index' => 'my_index',
242-
'type' => 'my_type',
243-
'id' => 'my_id'
244+
'type' => 'my_type',
245+
'id' => 'my_id'
244246
];
245247
246248
// Delete doc at /my_index/my_type/my_id

0 commit comments

Comments
 (0)