Python 在elasticsearch中更新索引时发生RequestError
我在elasticsearch中索引了一条记录,带有特定的时间戳。我正在尝试使用以下代码(python)更新记录: 我得到了以下错误:Python 在elasticsearch中更新索引时发生RequestError,python,
elasticsearch,Python,
elasticsearch,我在elasticsearch中索引了一条记录,带有特定的时间戳。我正在尝试使用以下代码(python)更新记录: 我得到了以下错误: RequestError: TransportError(400, u'ActionRequestValidationException[Validation Failed: 1: script or doc is missing;]') 原因可能是什么?消息编号400表示您有一个“错误的请求”。请求正文/URL不是预期的内容 在这种情况下,这是因为您没有在正
RequestError: TransportError(400, u'ActionRequestValidationException[Validation Failed: 1: script or doc is missing;]')
原因可能是什么?消息编号400表示您有一个“错误的请求”。请求正文/URL不是预期的内容 在这种情况下,这是因为您没有在正文中使用脚本或文档。有关更多信息,请查看 以下代码解决了您的问题:
from elasticsearch import Elasticsearch
from datetime import datetime
import pytz
es = Elasticsearch()
time = datetime.utcnow().replace(tzinfo=pytz.utc)
msg = {'_id': 1, 'text': 'Hello World'}
es.index(index='idx', doc_type='dtype', id=msg['_id'], body=msg, timestamp=time, ttl='30d')
msg2 = '''{"doc": {"text": "New Message"}}'''
es.update(index='idx', doc_type='dtype', id=msg['_id'], body=msg2, timestamp=time, ttl='30d')
通过用
doc
标记包围您想要更改的信息,您告诉ElasticSearch您想要用部分文档的值替换这些值。Hey@mirchi,我希望我的回答对您有所帮助。如果是这样,请不要忘记接受:)谢谢@heschoon。我不知道如何接受相同的答案。要接受问题,您必须单击答案左侧向上/向下投票箭头下的大绿色“V”。它“关闭”问题,将问题标记为已解决。
from elasticsearch import Elasticsearch
from datetime import datetime
import pytz
es = Elasticsearch()
time = datetime.utcnow().replace(tzinfo=pytz.utc)
msg = {'_id': 1, 'text': 'Hello World'}
es.index(index='idx', doc_type='dtype', id=msg['_id'], body=msg, timestamp=time, ttl='30d')
msg2 = '''{"doc": {"text": "New Message"}}'''
es.update(index='idx', doc_type='dtype', id=msg['_id'], body=msg2, timestamp=time, ttl='30d')