You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -555,29 +555,40 @@ res = index.get_objects(["myID1", "myID2"])
555
555
556
556
Each entry in an index has a unique identifier called `objectID`. There are two ways to add an entry to the index:
557
557
558
-
1.Using automatic `objectID` assignment. You will be able to access it in the answer.
559
-
2.Supplying your own `objectID`.
558
+
1.Supplying your own `objectID`.
559
+
2.Using automatic `objectID` assignment. You will be able to access it in the answer.
560
560
561
561
You don't need to explicitly create an index, it will be automatically created the first time you add an object.
562
562
Objects are schema less so you don't need any configuration to start indexing. If you wish to configure things, the settings section provides details about advanced settings.
563
563
564
-
Example with automatic `objectID`assignment:
564
+
Example with automatic `objectID`assignments:
565
565
566
566
```python
567
-
res = index.add_object({"firstname": "Jimmie",
568
-
"lastname": "Barninger"})
569
-
print"ObjectID=%s"% res["objectID"]
567
+
res = index.add_objects([{"firstname": "Jimmie",
568
+
"lastname": "Barninger"},
569
+
{"firstname": "Warren",
570
+
"lastname": "Speach"}])
571
+
```
572
+
573
+
Example with manual `objectID` assignments:
574
+
575
+
```python
576
+
res = index.add_objects([{"objectID": "1",
577
+
"firstname": "Jimmie",
578
+
"lastname": "Barninger"},
579
+
{"objectID": "2",
580
+
"firstname": "Warren",
581
+
"lastname": "Speach"}])
570
582
```
571
583
572
-
Example with manual `objectID` assignment:
584
+
To add a single object, use the `[Add object](#add-object---add_object)` method:
573
585
574
586
```python
575
587
res = index.add_object({"firstname": "Jimmie",
576
588
"lastname": "Barninger"}, "myID")
577
589
print"ObjectID=%s"% res["objectID"]
578
590
```
579
591
580
-
581
592
### Update objects - `save_objects`
582
593
583
594
You have three options when updating an existing object:
@@ -586,7 +597,18 @@ You have three options when updating an existing object:
586
597
2. Replace only some attributes.
587
598
3. Apply an operation to some attributes.
588
599
589
-
Example on how to replace all attributes of an existing object:
600
+
Example on how to replace all attributes existing objects:
601
+
602
+
```python
603
+
res = index.save_objects([{"firstname": "Jimmie",
604
+
"lastname": "Barninger",
605
+
"objectID": "myID1"},
606
+
{"firstname": "Warren",
607
+
"lastname": "Speach",
608
+
"objectID": "myID2"}])
609
+
```
610
+
611
+
To update a single object, you can use the `[Update object](#update-object---save_object) method:
Note: Here we are decrementing the value by `42`. To decrement just by one, put
655
678
`value:1`.
656
679
680
+
To partial update multiple objects using one API call, you can use the `[Partial update objects](#partial-update-objects---partial_update_objects)` method:
681
+
682
+
```python
683
+
res = index.partial_update_objects([{"firstname": "Jimmie",
684
+
"objectID": "myID1"},
685
+
{"firstname": "Warren",
686
+
"objectID": "myID2"}])
687
+
```
688
+
657
689
658
690
### Delete objects - `delete_objects`
659
691
660
-
You can delete an object using its `objectID`:
692
+
You can delete objects using their `objectID`:
693
+
694
+
```python
695
+
res = index.delete_objects(["myID1", "myID2"])
696
+
```
697
+
698
+
To delete a single object, you can use the `[Delete object](#delete-object---delete_object)` method:
You may want to perform multiple operations with one API call to reduce latency.
2233
-
We expose four methods to perform batch operations:
2234
-
2235
-
* Add objects - `add_objects`: Add an array of objects using automatic `objectID` assignment.
2236
-
* Update objects - `save_objects`: Add or update an array of objects that contains an `objectID` attribute.
2237
-
* Delete objects - `delete_objects`: Delete an array of objectIDs.
2238
-
* Partial update - `partial_update_objects`: Partially update an array of objects that contain an `objectID` attribute (only specified attributes will be updated).
2239
-
2240
-
Example using automatic `objectID` assignment:
2241
-
2242
-
```python
2243
-
res = index.add_objects([{"firstname": "Jimmie",
2244
-
"lastname": "Barninger"},
2245
-
{"firstname": "Warren",
2246
-
"lastname": "Speach"}])
2247
-
```
2248
-
2249
-
Example with user defined `objectID` (add or update):
2250
-
2251
-
```python
2252
-
res = index.save_objects([{"firstname": "Jimmie",
2253
-
"lastname": "Barninger",
2254
-
"objectID": "myID1"},
2255
-
{"firstname": "Warren",
2256
-
"lastname": "Speach",
2257
-
"objectID": "myID2"}])
2258
-
```
2259
-
2260
-
Example that deletes a set of records:
2261
-
2262
-
```python
2263
-
res = index.delete_objects(["myID1", "myID2"])
2264
-
```
2265
-
2266
-
Example that updates only the `firstname` attribute:
2267
-
2268
-
```python
2269
-
res = index.partial_update_objects([{"firstname": "Jimmie",
0 commit comments