【发布时间】:2017-12-21 01:50:31
【问题描述】:
我正在尝试将我的 django 模型批量索引到弹性搜索 6,我的计划是每天将其作为 cron 运行一次以更新索引。 导入请求
data = serialize('json', CapitalSheet.objects.all())
data += "\n"
r = requests.post("http://127.0.0.1:9200/capitalsheet/_bulk", json = data)
print(r.content)
我收到此错误:
b'{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\\n]"}],"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\\n]"},"status":400}'
如果你能提出更好的建议,我会很高兴。
【问题讨论】:
-
批量语法有点奇怪(至少对我来说)。您需要将每个对象作为单独的行发送。
-
你最好还是使用 python 库。
标签: django elasticsearch