Skip to content

Commit 1068434

Browse files
committed
Updated index docs + README + fixed getSource
1 parent 1bfea58 commit 1068434

File tree

3 files changed

+98
-97
lines changed

3 files changed

+98
-97
lines changed

README.md

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ The recommended method to install _Elasticsearch-PHP_ is through [Composer](http
8888

8989
$client = ClientBuilder::create()->build();
9090
```
91+
9192
You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at [getcomposer.org](http://getcomposer.org).
9293

9394
PHP Version Requirement
9495
----
95-
Version 7.0 of this library requires at least PHP version 7.1 to function. In addition, it requires the native JSON
96+
Version 7.0 of this library requires at least PHP version 7.1. In addition, it requires the native JSON
9697
extension to be version 1.3.7 or higher.
9798

9899
| Elasticsearch-PHP Branch | PHP Version |
@@ -110,16 +111,15 @@ Quickstart
110111

111112
### Index a document
112113

113-
In elasticsearch-php, almost everything is configured by associative arrays. The REST endpoint, document and optional parameters - everything is an associative array.
114+
In elasticsearch-php, almost everything is configured by associative arrays. The REST endpoint, document and optional parameters - everything is an associative array.
114115

115-
To index a document, we need to specify four pieces of information: index, type, id and a document body. This is done by
116+
To index a document, we need to specify four pieces of information: index, id and a document body. This is done by
116117
constructing an associative array of key:value pairs. The request body is itself an associative array with key:value pairs
117118
corresponding to the data in your document:
118119

119120
```php
120121
$params = [
121122
'index' => 'my_index',
122-
'type' => 'my_type',
123123
'id' => 'my_id',
124124
'body' => ['testField' => 'abc']
125125
];
@@ -135,12 +135,20 @@ associative array containing a decoded version of the JSON that Elasticsearch re
135135
Array
136136
(
137137
[_index] => my_index
138-
[_type] => my_type
138+
[_type] => _doc
139139
[_id] => my_id
140140
[_version] => 1
141-
[created] => 1
142-
)
141+
[result] => created
142+
[_shards] => Array
143+
(
144+
[total] => 1
145+
[successful] => 1
146+
[failed] => 0
147+
)
143148

149+
[_seq_no] => 0
150+
[_primary_term] => 1
151+
)
144152
```
145153

146154
### Get a document
@@ -150,24 +158,25 @@ Let's get the document that we just indexed. This will simply return the docume
150158
```php
151159
$params = [
152160
'index' => 'my_index',
153-
'type' => 'my_type',
154161
'id' => 'my_id'
155162
];
156163

157164
$response = $client->get($params);
158165
print_r($response);
159166
```
160167

161-
The response contains some metadata (index, type, etc.) as well as a `_source` field...this is the original document
168+
The response contains some metadata (index, version, etc.) as well as a `_source` field, this is the original document
162169
that you sent to Elasticsearch.
163170

164171
```php
165172
Array
166173
(
167174
[_index] => my_index
168-
[_type] => my_type
175+
[_type] => _doc
169176
[_id] => my_id
170177
[_version] => 1
178+
[_seq_no] => 0
179+
[_primary_term] => 1
171180
[found] => 1
172181
[_source] => Array
173182
(
@@ -182,12 +191,20 @@ If you want to retrieve the `_source` field directly, there is the `getSource` m
182191
```php
183192
$params = [
184193
'index' => 'my_index',
185-
'type' => 'my_type',
186194
'id' => 'my_id'
187195
];
188196

189197
$source = $client->getSource($params);
190-
doSomething($source);
198+
print_r($source);
199+
```
200+
201+
The response will be just the `_source` value:
202+
203+
```php
204+
Array
205+
(
206+
[testField] => abc
207+
)
191208
```
192209

193210
### Search for a document
@@ -197,7 +214,6 @@ Searching is a hallmark of Elasticsearch, so let's perform a search. We are goi
197214
```php
198215
$params = [
199216
'index' => 'my_index',
200-
'type' => 'my_type',
201217
'body' => [
202218
'query' => [
203219
'match' => [
@@ -218,34 +234,44 @@ individual search results:
218234
```php
219235
Array
220236
(
221-
[took] => 1
237+
[took] => 33
222238
[timed_out] =>
223239
[_shards] => Array
224240
(
225-
[total] => 5
226-
[successful] => 5
241+
[total] => 1
242+
[successful] => 1
243+
[skipped] => 0
227244
[failed] => 0
228245
)
229246

230247
[hits] => Array
231248
(
232-
[total] => 1
233-
[max_score] => 0.30685282
249+
[total] => Array
250+
(
251+
[value] => 1
252+
[relation] => eq
253+
)
254+
255+
[max_score] => 0.2876821
234256
[hits] => Array
235257
(
236258
[0] => Array
237259
(
238260
[_index] => my_index
239-
[_type] => my_type
261+
[_type] => _doc
240262
[_id] => my_id
241-
[_score] => 0.30685282
263+
[_score] => 0.2876821
242264
[_source] => Array
243265
(
244266
[testField] => abc
245267
)
268+
246269
)
270+
247271
)
272+
248273
)
274+
249275
)
250276
```
251277

@@ -256,7 +282,6 @@ Alright, let's go ahead and delete the document that we added previously:
256282
```php
257283
$params = [
258284
'index' => 'my_index',
259-
'type' => 'my_type',
260285
'id' => 'my_id'
261286
];
262287

@@ -270,11 +295,20 @@ You'll notice this is identical syntax to the `get` syntax. The only difference
270295
```php
271296
Array
272297
(
273-
[found] => 1
274298
[_index] => my_index
275-
[_type] => my_type
299+
[_type] => _doc
276300
[_id] => my_id
277301
[_version] => 2
302+
[result] => deleted
303+
[_shards] => Array
304+
(
305+
[total] => 1
306+
[successful] => 1
307+
[failed] => 0
308+
)
309+
310+
[_seq_no] => 1
311+
[_primary_term] => 1
278312
)
279313
```
280314

docs/index-operations.asciidoc

Lines changed: 40 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,15 @@ $params = [
3535
'number_of_replicas' => 2
3636
],
3737
'mappings' => [
38-
'my_type' => [
39-
'_source' => [
40-
'enabled' => true
38+
'_source' => [
39+
'enabled' => true
40+
],
41+
'properties' => [
42+
'first_name' => [
43+
'type' => 'keyword'
4144
],
42-
'properties' => [
43-
'first_name' => [
44-
'type' => 'keyword',
45-
'analyzer' => 'standard'
46-
],
47-
'age' => [
48-
'type' => 'integer'
49-
]
45+
'age' => [
46+
'type' => 'integer'
5047
]
5148
]
5249
]
@@ -101,40 +98,26 @@ $params = [
10198
]
10299
],
103100
'mappings' => [ <3>
104-
'_default_' => [ <4>
105-
'properties' => [
106-
'title' => [
107-
'type' => 'keyword',
108-
'analyzer' => 'reuters',
109-
'term_vector' => 'yes',
110-
'copy_to' => 'combined'
111-
],
112-
'body' => [
113-
'type' => 'keyword',
114-
'analyzer' => 'reuters',
115-
'term_vector' => 'yes',
116-
'copy_to' => 'combined'
117-
],
118-
'combined' => [
119-
'type' => 'keyword',
120-
'analyzer' => 'reuters',
121-
'term_vector' => 'yes'
122-
],
123-
'topics' => [
124-
'type' => 'keyword',
125-
'index' => 'not_analyzed'
126-
],
127-
'places' => [
128-
'type' => 'keyword',
129-
'index' => 'not_analyzed'
130-
]
131-
]
132-
],
133-
'my_type' => [ <5>
134-
'properties' => [
135-
'my_field' => [
136-
'type' => 'keyword'
137-
]
101+
'properties' => [
102+
'title' => [
103+
'type' => 'text',
104+
'analyzer' => 'reuters',
105+
'copy_to' => 'combined'
106+
],
107+
'body' => [
108+
'type' => 'text',
109+
'analyzer' => 'reuters',
110+
'copy_to' => 'combined'
111+
],
112+
'combined' => [
113+
'type' => 'text',
114+
'analyzer' => 'reuters'
115+
],
116+
'topics' => [
117+
'type' => 'keyword'
118+
],
119+
'places' => [
120+
'type' => 'keyword'
138121
]
139122
]
140123
]
@@ -145,8 +128,6 @@ $client->indices()->create($params);
145128
<1> The top level `settings` contains config about the index (# of shards, etc) as well as analyzers
146129
<2> `analysis` is nested inside of `settings`, and contains tokenizers, filters, char filters and analyzers
147130
<3> `mappings` is another element nested inside of `settings`, and contains the mappings for various types
148-
<4> The `_default_` type is a dynamic template that is applied to all fields that don't have an explicit mapping
149-
<5> The `my_type` type is an example of a user-defined type that holds a single field, `my_field`
150131

151132

152133
=== Delete an index
@@ -206,20 +187,17 @@ The Put Mappings API allows you to modify or add to an existing index's mapping.
206187
// Set the index and type
207188
$params = [
208189
'index' => 'my_index',
209-
'type' => 'my_type2',
210190
'body' => [
211-
'my_type2' => [
212-
'_source' => [
213-
'enabled' => true
191+
'_source' => [
192+
'enabled' => true
193+
],
194+
'properties' => [
195+
'first_name' => [
196+
'type' => 'text',
197+
'analyzer' => 'standard'
214198
],
215-
'properties' => [
216-
'first_name' => [
217-
'type' => 'keyword',
218-
'analyzer' => 'standard'
219-
],
220-
'age' => [
221-
'type' => 'integer'
222-
]
199+
'age' => [
200+
'type' => 'integer'
223201
]
224202
]
225203
]
@@ -232,28 +210,17 @@ $client->indices()->putMapping($params);
232210

233211
=== Get Mappings API
234212

235-
The Get Mappings API will return the mapping details about your indexes and types. Depending on the mappings that you wish to retrieve, you can specify a number of combinations of index and type:
213+
The Get Mappings API will return the mapping details about your indexes. Depending on the mappings that you wish to retrieve, you can specify one of more indexes:
236214

237215
[source,php]
238216
----
239-
// Get mappings for all indexes and types
217+
// Get mappings for all indexes
240218
$response = $client->indices()->getMapping();
241219
242-
// Get mappings for all types in 'my_index'
220+
// Get mappings in 'my_index'
243221
$params = ['index' => 'my_index'];
244222
$response = $client->indices()->getMapping($params);
245223
246-
// Get mappings for all types of 'my_type', regardless of index
247-
$params = ['type' => 'my_type' ];
248-
$response = $client->indices()->getMapping($params);
249-
250-
// Get mapping 'my_type' in 'my_index'
251-
$params = [
252-
'index' => 'my_index'
253-
'type' => 'my_type'
254-
];
255-
$response = $client->indices()->getMapping($params);
256-
257224
// Get mappings for two indexes
258225
$params = [
259226
'index' => [ 'my_index', 'my_index2' ]

src/Elasticsearch/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function getSource(array $params)
268268
/**
269269
* @var \Elasticsearch\Endpoints\Get $endpoint
270270
*/
271-
$endpoint = $endpointBuilder('Get');
271+
$endpoint = $endpointBuilder('Source\Get');
272272
$endpoint->setID($id)
273273
->setIndex($index)
274274
->setType($type);

0 commit comments

Comments
 (0)