Skip to content

Commit fb5c8b2

Browse files
committed
[DOCS] Revises search-operations.asciidoc.
1 parent e7a4c4e commit fb5c8b2

File tree

1 file changed

+49
-27
lines changed

1 file changed

+49
-27
lines changed

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}/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)