我试图在没有objectID的情况下将新对象保存到我的Algolia索引,但由于某种原因它会返回此错误:
Traceback (most recent call last):
File "search.py", line 9, in <module>
"picture": "pic.jpg"})
File "C:\Python27\lib\site-packages\algoliasearch\index.py", line 212, in save_object
path = '/%s' % safe(obj['objectID'])
KeyError: 'objectID'
我使用的python代码(基于docs):
from algoliasearch import algoliasearch
client = algoliasearch.Client("***", "***")
algolia_var = client.init_index('*****')
res = algolia_var.save_object({"age": "new",
"categories": "new",
"picture": "pic.jpg"})
任何人都可以向我解释我做错了什么吗?它不应该自动生成objectID吗?
答案 0 :(得分:1)
save_object
更新现有对象。您需要方法add_object
将此对象添加到索引并生成id。
res = algolia_var.add_object({"age": "new",
"categories": "new",
"picture": "pic.jpg"})