Skip to content

Commit 53a7bab

Browse files
committed
Merge remote-tracking branch 'elasticsearch-php/7.x' into 7.x
2 parents d8331a4 + 0484761 commit 53a7bab

File tree

4 files changed

+158
-96
lines changed

4 files changed

+158
-96
lines changed

docs/crud.asciidoc

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
[[indexing_documents]]
2-
== Indexing Documents
2+
== 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-7x}/removal-of-types.html[here]. If you migrated types from {es} 6 to 7,
6+
you 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
----

docs/namespaces.asciidoc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
== Namespaces
33

44
The client has a number of "namespaces", which generally expose administrative
5-
functionality. The namespaces correspond to the various administrative endpoints
6-
in Elasticsearch. This is a complete list of namespaces:
5+
functionality. The namespaces correspond to the various administrative endpoints
6+
in {es}. This is a complete list of namespaces:
77

88

99
[width="40%",options="header",frame="topbot"]
1010
|============================
11-
| Namespace | Functionality
11+
| Namespace | Functionality
1212
| `indices()` | Index-centric stats and info
1313
| `nodes()` | Node-centric stats and info
1414
| `cluster()` | Cluster-centric stats and info
1515
| `snapshot()` | Methods to snapshot/restore your cluster and indices
1616
| `cat()` | Access to the Cat API (which is generally used standalone from the command line
1717
|============================
1818

19-
Some methods are available in several different namespaces, which give you
20-
the same information but grouped into different contexts. To see how these
19+
Some methods are available in several different namespaces, which give you the
20+
same information but grouped into different contexts. To see how these
2121
namespaces work, let's look at the `_stats` output:
2222

2323

@@ -39,8 +39,8 @@ $response = $client->cluster()->stats();
3939
----
4040
{zwsp} +
4141

42-
As you can see, the same `stats()` call is made through three different
43-
namespaces. Sometimes the methods require parameters. These parameters work
42+
As you can see, the same `stats()` call is made through three different
43+
namespaces. Sometimes the methods require parameters. These parameters work
4444
just like any other method in the library.
4545

4646
For example, we can requests index stats about a specific index, or multiple
@@ -60,7 +60,7 @@ $response = $client->indices()->stats($params);
6060
----
6161
{zwsp} +
6262

63-
As another example, here is how you might add an alias to an existing index:
63+
The following example shows how you can add an alias to an existing index:
6464

6565
[source,php]
6666
----
@@ -77,6 +77,7 @@ $params['body'] = array(
7777
$client->indices()->updateAliases($params);
7878
----
7979

80-
Notice how both the `stats` calls and the updateAlias took a variety of parameters,
81-
each according to what the particular API requires. The `stats` API only requires
82-
an index name(s), while the `updateAlias` requires a body of actions.
80+
Notice how both the `stats` calls and the updateAlias took a variety of
81+
parameters, each according to what the particular API requires. The `stats` API
82+
only requires an index name(s), while the `updateAlias` requires a body of
83+
actions.

docs/search-operations.asciidoc

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
[[search_operations]]
2-
== Search Operations
2+
== Search operations
33

4-
Well...it isn't called elasticsearch for nothing! Let's talk about search operations in the client.
4+
Well...it isn't called {es} for nothing! Let's talk about search operations in
5+
the client.
56

6-
The client gives you full access to every query and parameter exposed by the REST API, following the naming scheme as
7-
much as possible. Let's look at a few examples so you can become familiar with the syntax.
7+
The client gives you full access to every query and parameter exposed by the
8+
REST API, following the naming scheme as much as possible. Let's look at a few
9+
examples so you can become familiar with the syntax.
810

9-
=== Match Query
1011

11-
Here is a standard curl for a Match query:
12+
=== Match query
13+
14+
Here is a standard curl for a match query:
1215

1316
[source,shell]
1417
----
@@ -22,6 +25,7 @@ curl -XGET 'localhost:9200/my_index/_search' -d '{
2225
----
2326
{zwsp} +
2427

28+
2529
And here is the same query constructed in the client:
2630

2731
[source,php]
@@ -41,9 +45,11 @@ $results = $client->search($params);
4145
----
4246
{zwsp} +
4347

44-
Notice how the structure and layout of the PHP array is identical to that of the JSON request body. This makes it very
45-
simple to convert JSON examples into PHP. A quick method to check your PHP array (for more complex examples) is to
46-
encode it back to JSON and check by eye:
48+
49+
Notice how the structure and layout of the PHP array is identical to that of the
50+
JSON request body. This makes it very simple to convert JSON examples into PHP.
51+
A quick method to check your PHP array (for more complex examples) is to encode
52+
it back to JSON and check it:
4753

4854
[source,php]
4955
----
@@ -68,8 +74,9 @@ print_r(json_encode($params['body']));
6874

6975
.Using Raw JSON
7076
****
71-
Sometimes it is convenient to use raw JSON for testing purposes, or when migrating from a different system. You can
72-
use raw JSON as a string in the body, and the client will detect this automatically:
77+
Sometimes it is convenient to use raw JSON for testing purposes, or when
78+
migrating from a different system. You can use raw JSON as a string in the body,
79+
and the client detects this automatically:
7380
7481
[source,php]
7582
----
@@ -91,8 +98,10 @@ $results = $client->search($params);
9198
****
9299
{zwsp} +
93100

94-
Search results follow the same format as Elasticsearch search response, the only difference is that the JSON response is
95-
serialized back into PHP arrays. Working with the search results is as simple as iterating over the array values:
101+
102+
Search results follow the same format as {es} search response, the only
103+
difference is that the JSON response is serialized back into PHP arrays. Working
104+
with the search results is as simple as iterating over the array values:
96105

97106
[source,php]
98107
----
@@ -117,9 +126,12 @@ $doc = $results['hits']['hits'][0]['_source'];
117126
----
118127
{zwsp} +
119128

129+
120130
=== Bool Queries
121131

122-
Bool queries can be easily constructed using the client. For example, this query:
132+
Bool queries can be easily constructed using the client. For example, this
133+
query:
134+
123135
[source,shell]
124136
----
125137
curl -XGET 'localhost:9200/my_index/_search' -d '{
@@ -139,7 +151,9 @@ curl -XGET 'localhost:9200/my_index/_search' -d '{
139151
----
140152
{zwsp} +
141153

142-
Would be structured like this (Note the position of the square brackets):
154+
155+
Would be structured like this (note the position of the square brackets):
156+
143157
[source,php]
144158
----
145159
$params = [
@@ -160,14 +174,18 @@ $results = $client->search($params);
160174
----
161175
{zwsp} +
162176

163-
Notice that the `must` clause accepts an array of arrays. This will be serialized into an array of JSON objects internally,
164-
so the final resulting output will be identical to the curl example. For more details about arrays vs objects in PHP,
177+
178+
Notice that the `must` clause accepts an array of arrays. This is serialized
179+
into an array of JSON objects internally, so the final resulting output is
180+
identical to the curl example. For more details about arrays and objects in PHP,
165181
see <<php_json_objects, Dealing with JSON Arrays and Objects in PHP>>.
166182

183+
167184
=== A more complicated example
168185

169-
Let's construct a slightly more complicated example: a boolean query that contains both a filter and a query.
170-
This is a very common activity in elasticsearch queries, so it will be a good demonstration.
186+
Let's construct a slightly more complicated example: a boolean query that
187+
contains both a filter and a query. This is a very common activity in {es}
188+
queries, so it will be a good demonstration.
171189

172190
The curl version of the query:
173191

@@ -188,6 +206,7 @@ curl -XGET 'localhost:9200/my_index/_search' -d '{
188206
----
189207
{zwsp} +
190208

209+
191210
And in PHP:
192211

193212
[source,php]
@@ -216,16 +235,19 @@ $results = $client->search($params);
216235

217236
=== Scrolling
218237

219-
The Scrolling functionality of Elasticsearch is used to paginate over many documents in a bulk manner, such as exporting
220-
all the documents belonging to a single user. It is more efficient than regular search because it doesn't need to maintain
221-
an expensive priority queue ordering the documents.
238+
The scrolling functionality of {es} is used to paginate over many documents in a
239+
bulk manner, such as exporting all the documents belonging to a single user. It
240+
is more efficient than regular search because it doesn't need to maintain an
241+
expensive priority queue ordering the documents.
222242

223-
Scrolling works by maintaining a "point in time" snapshot of the index which is then used to page over.
224-
This window allows consistent paging even if there is background indexing/updating/deleting. First, you execute a search
225-
request with `scroll` enabled. This returns a "page" of documents, and a scroll_id which is used to continue
226-
paginating through the hits.
243+
Scrolling works by maintaining a "point in time" snapshot of the index which is
244+
then used to page over. This window allows consistent paging even if there is
245+
background indexing/updating/deleting. First, you execute a search request with
246+
`scroll` enabled. This returns a "page" of documents, and a `scroll_id` which is
247+
used to continue paginating through the hits.
227248

228-
More details about scrolling can be found in the https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-scroll[Link: reference documentation].
249+
More details about scrolling can be found in the
250+
{ref-7x}/search-request-body.html#request-body-search-scroll[reference documentation].
229251

230252
This is an example which can be used as a template for more advanced operations:
231253

0 commit comments

Comments
 (0)