Skip to content

Commit a0aa70d

Browse files
committed
Fix update documents -- should be calling PATCH not POST.
1 parent 2996a75 commit a0aa70d

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

examples/collection_operations.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
# Add a book
5454

5555
hunger_games_book = {
56-
'id': '1', 'original_publication_year': 2008, 'authors': ['Suzanne Collins'], 'average_rating': 4.34,
56+
'id': '1', 'authors': ['Suzanne Collins'], 'average_rating': 4.34,
5757
'publication_year': 2008, 'title': 'The Hunger Games',
5858
'image_url': 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
5959
'ratings_count': 4780653
@@ -125,6 +125,10 @@
125125
schema_change = {"fields": [{"name": "in_stock", "optional": True, "type": "bool"}]}
126126
print(client.collections['books'].update(schema_change))
127127

128+
# Update value matching a filter
129+
updated_doc = {'publication_year': 2009}
130+
print(client.collections['books'].documents.update(updated_doc, {'filter_by': 'publication_year: 2008'}))
131+
128132
# Drop the field
129133
schema_change = {"fields": [{"name": "in_stock", "drop": True}]}
130134
print(client.collections['books'].update(schema_change))

typesense/documents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def upsert(self, document, params=None):
4646
def update(self, document, params=None):
4747
params = params or {}
4848
params['action'] = 'update'
49-
return self.api_call.post(self._endpoint_path(), document, params)
49+
return self.api_call.patch(self._endpoint_path(), document, params)
5050

5151
def import_jsonl(self, documents_jsonl):
5252
logger.warning('`import_jsonl` is deprecated: please use `import_`.')

0 commit comments

Comments
 (0)