Skip to content

Commit e7a4c4e

Browse files
committed
[DOCS] Revises crud.asciidoc.
1 parent 3193c51 commit e7a4c4e

File tree

1 file changed

+46
-26
lines changed

1 file changed

+46
-26
lines changed

docs/crud.asciidoc

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
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]. If you migrated types from Elasticsearch 6 to 7, you can address these with the `type` param.
4+
IMPORTANT: Please note that mapping types will disappear from {es}, read more
5+
{ref}/removal-of-types.html[here]. If you migrated types from {es} 6 to 7, you
6+
can address these with the `type` param.
7+
8+
When you add documents to {es}, you index JSON documents. This maps naturally to
9+
PHP associative arrays, since they can easily be encoded in JSON. Therefore, in
10+
Elasticsearch-PHP you create and pass associative arrays to the client for
11+
indexing. There are several methods of ingesting data into {es} which we cover
12+
here.
513

6-
When you add documents to Elasticsearch, you index JSON documents. This maps naturally to PHP associative arrays, since
7-
they can easily be encoded in JSON. Therefore, in Elasticsearch-PHP you create and pass associative arrays to the client
8-
for indexing. There are several methods of ingesting data into Elasticsearch, which we will cover here.
914

1015
=== Single document indexing
1116

12-
When indexing a document, you can either provide an ID or let elasticsearch generate one for you.
17+
When indexing a document, you can either provide an ID or let {es} generate one
18+
for you.
1319

1420
{zwsp} +
1521

@@ -40,7 +46,9 @@ $response = $client->index($params);
4046
----
4147
{zwsp} +
4248

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:
49+
If you need to set other parameters, such as a `routing` value, you specify
50+
those in the array alongside the `index`, and others. For example, let's set the
51+
routing and timestamp of this new document:
4452

4553
.Additional parameters
4654
[source,php]
@@ -58,11 +66,14 @@ $response = $client->index($params);
5866
----
5967
{zwsp} +
6068

69+
6170
=== Bulk Indexing
6271

63-
Elasticsearch also supports bulk indexing of documents. The bulk API expects JSON action/metadata pairs, separated by
64-
newlines. When constructing your documents in PHP, the process is similar. You first create an action array object
65-
(e.g. `index` object), then you create a document body object. This process repeats for all your documents.
72+
{es} also supports bulk indexing of documents. The bulk API expects JSON
73+
action/metadata pairs, separated by newlines. When constructing your documents
74+
in PHP, the process is similar. You first create an action array object (for
75+
example, an `index` object), then you create a document body object. This
76+
process repeats for all your documents.
6677

6778
A simple example might look like this:
6879

@@ -85,9 +96,9 @@ for($i = 0; $i < 100; $i++) {
8596
$responses = $client->bulk($params);
8697
----
8798

88-
In practice, you'll likely have more documents than you want to send in a single bulk request. In that case, you need
89-
to batch up the requests and periodically send them:
90-
99+
In practice, you'll likely have more documents than you want to send in a single
100+
bulk request. In that case, you need to batch up the requests and periodically
101+
send them:
91102

92103
.Bulk indexing with batches
93104
[source,php]
@@ -126,11 +137,12 @@ if (!empty($params['body'])) {
126137
----
127138

128139
[[getting_documents]]
129-
== Getting Documents
140+
== Getting documents
130141

131-
Elasticsearch provides realtime GETs of documents. This means that as soon as the document has been indexed and your
132-
client receives an acknowledgement, you can immediately retrieve the document from any shard. Get operations are
133-
performed by requesting a document by it's full `index/type/id` path:
142+
{es} provides realtime GETs of documents. This means that as soon as the
143+
document is indexed and your client receives an acknowledgement, you can
144+
immediately retrieve the document from any shard. Get operations are performed
145+
by requesting a document by its full `index/type/id` path:
134146

135147
[source,php]
136148
----
@@ -145,15 +157,17 @@ $response = $client->get($params);
145157
{zwsp} +
146158

147159
[[updating_documents]]
148-
== Updating Documents
160+
== Updating documents
149161

150-
Updating a document allows you to either completely replace the contents of the existing document, or perform a partial
151-
update to just some fields (either changing an existing field, or adding new fields).
162+
Updating a document allows you to either completely replace the contents of the
163+
existing document, or perform a partial update to just some fields (either
164+
changing an existing field or adding new fields).
152165

153166
=== Partial document update
154167

155-
If you want to partially update a document (e.g. change an existing field, or add a new one) you can do so by specifying
156-
the `doc` in the `body` parameter. This will merge the fields in `doc` with the existing document
168+
If you want to partially update a document (for example, change an existing
169+
field or add a new one) you can do so by specifying the `doc` in the `body`
170+
parameter. This merges the fields in `doc` with the existing document.
157171

158172

159173
[source,php]
@@ -173,10 +187,12 @@ $response = $client->update($params);
173187
----
174188
{zwsp} +
175189

190+
176191
=== Scripted document update
177192

178-
Sometimes you need to perform a scripted update, such as incrementing a counter or appending a new value to an array.
179-
To perform a scripted update, you need to provide a script and (usually) a set of parameters:
193+
Sometimes you need to perform a scripted update, such as incrementing a counter
194+
or appending a new value to an array. To perform a scripted update, you need to
195+
provide a script and usually a set of parameters:
180196

181197
[source,php]
182198
----
@@ -195,10 +211,12 @@ $response = $client->update($params);
195211
----
196212
{zwsp} +
197213

214+
198215
=== Upserts
199216

200-
Upserts are "Update or Insert" operations. This means an upsert will attempt to run your update script, but if the document
201-
does not exist (or the field you are trying to update doesn't exist), default values will be inserted instead.
217+
Upserts are "Update or Insert" operations. This means an upsert attempts to run
218+
your update script, but if the document does not exist (or the field you are
219+
trying to update doesn't exist), default values are inserted instead.
202220

203221
[source,php]
204222
----
@@ -222,10 +240,12 @@ $response = $client->update($params);
222240
----
223241
{zwsp} +
224242

243+
225244
[[deleting_documents]]
226245
== Deleting documents
227246

228-
Finally, you can delete documents by specifying their full `/index/_doc_/id` path:
247+
Finally, you can delete documents by specifying their full `/index/_doc_/id`
248+
path:
229249

230250
[source,php]
231251
----

0 commit comments

Comments
 (0)