@@ -42,6 +42,9 @@ Index and type names setted in query will override values the configuration file
42
42
43
43
#### Available methods:
44
44
45
+ ##### Getting document by id
46
+
47
+ $documents = ES::_id(3)->get();
45
48
46
49
##### Sorting
47
50
@@ -79,11 +82,29 @@ Index and type names setted in query will override values the configuration file
79
82
##### Where not clause
80
83
81
84
ES::whereNot("id", 150)->get(); or ES::where("id", "=", 150)->get();
85
+
86
+ ##### Where greater than
87
+
82
88
ES::whereNot("id", ">", 150)->get();
89
+
90
+ ##### Where greater than or equal
91
+
83
92
ES::whereNot("id", ">=", 150)->get();
93
+
94
+ ##### Where less than
95
+
84
96
ES::whereNot("id", "<", 150)->get();
97
+
98
+ ##### Where less than or equal
99
+
85
100
ES::whereNot("id", "<=", 150)->get();
101
+
102
+ ##### Where like
103
+
86
104
ES::whereNot("title", "like", "foo")->get();
105
+
106
+ ##### Where field exists
107
+
87
108
ES::whereNot("hobbies", "exists", true)->get(); or ES::whereExists("hobbies", true)->get();
88
109
89
110
##### Where not in clause
@@ -99,8 +120,12 @@ Index and type names setted in query will override values the configuration file
99
120
100
121
##### Search the entire document
101
122
123
+
102
124
ES::search("bar")->get();
103
125
126
+ # search with Boost = 2
127
+
128
+ ES::search("bar", 2)->get();
104
129
105
130
>
106
131
@@ -120,7 +145,7 @@ Index and type names setted in query will override values the configuration file
120
145
121
146
$documents = ES::search("bar")->paginate(5);
122
147
123
- // getting pagination links
148
+ # getting pagination links
124
149
125
150
$documents->links();
126
151
@@ -133,26 +158,26 @@ Index and type names setted in query will override values the configuration file
133
158
"index" => "my_index",
134
159
"type" => "my_type",
135
160
"body" => [
136
- "query": [
137
- "bool": [
138
- "must": [
139
- [ "match": [ "address": "mill" ] ],
140
- [ "match": [ "address": "lane" ] ]
141
- ]
142
- ]
143
- ]
144
- ]
145
- ]);
161
+ "query": [
162
+ "bool": [
163
+ "must": [
164
+ [ "match": [ "address": "mill" ] ],
165
+ [ "match": [ "address": "lane" ] ]
166
+ ]
167
+ ]
168
+ ]
169
+ ]
170
+ ]);
146
171
147
172
148
173
>
149
174
150
175
##### Insert a new document
151
176
152
- ES::insert([
177
+ ES::_id(3)-> insert([
153
178
"title" => "Test document",
154
- "content" => "sample content"
155
- ], 3 );
179
+ "content" => "Sample content"
180
+ ]);
156
181
157
182
158
183
A new document will be inserted with _id = 3.
@@ -167,11 +192,11 @@ Index and type names setted in query will override values the configuration file
167
192
ES::bulk(
168
193
10 => [
169
194
"title" => "Test document 1",
170
- "content" => "sample content 1"
195
+ "content" => "Sample content 1"
171
196
],
172
197
11 => [
173
198
"title" => "Test document 2",
174
- "content" => "sample content 2"
199
+ "content" => "Sample content 2"
175
200
],
176
201
);
177
202
@@ -181,21 +206,74 @@ Index and type names setted in query will override values the configuration file
181
206
182
207
##### Update an existing document
183
208
184
- ES::update([
209
+ ES::_id(3)-> update([
185
210
"title" => "Test document",
186
211
"content" => "sample content"
187
- ], 3);
188
-
212
+ ]);
189
213
190
214
Document has _id = 3 will be updated.
191
215
192
216
[id is required]
193
217
194
218
>
195
219
220
+ ##### Incrementing field
221
+
222
+ ES::_id(3)->increment("views");
223
+
224
+ Document has _id = 3 will be incremented by 1.
225
+
226
+ ES::_id(3)->increment("views", 3);
227
+
228
+ Document has _id = 3 will be incremented by 3.
229
+
230
+ [id is required]
231
+
232
+ >
233
+
234
+ ##### Decrementing field
235
+
236
+ ES::_id(3)->decrement("views");
237
+
238
+ Document has _id = 3 will be decremented by 1.
239
+
240
+ ES::_id(3)->decrement("views", 3);
241
+
242
+ Document has _id = 3 will be decremented by 3.
243
+
244
+ [id is required]
245
+
246
+ >
247
+
248
+ ##### Update using script
249
+
250
+
251
+ # icrement field by script
252
+
253
+ ES::_id(3)->script(
254
+ "ctx._source.$field -= params.count",
255
+ ["count" => 1]
256
+ );
257
+
258
+ # add php tag to tags array list
259
+
260
+ ES::_id(3)->script(
261
+ "ctx._source.tags.add(params.tag)",
262
+ ["tag" => "php"]
263
+ );
264
+
265
+ # delete the doc if the tags field contain mongodb, otherwise it does nothing (noop)
266
+
267
+ ES::_id(3)->script(
268
+ "if (ctx._source.tags.contains(params.tag)) { ctx.op = \"delete\" } else { ctx.op = \"none\" }",
269
+ ["tag" => "mongodb"]
270
+ );
271
+
272
+ >
273
+
196
274
##### Delete a document
197
275
198
- ES::delete(3 );
276
+ ES::_id(3)->delete( );
199
277
200
278
Document has _id = 3 will be deleted.
201
279
0 commit comments