繁体   English   中英

使用 Python 的 elasticsearch 客户端批量更新

[英]Bulk update with Python's elasticsearch client

我正在尝试根据文档属性的状态更改进行批量更新。 Create工作正常,但bulk吓坏了。 我收到“缺少脚本或文档”的错误提示,但一切看起来都不错。

这是我尝试批量更新的方式:

frequency_cleared = [
    {
        "_id": result['_id'], 
        "_type": "the-type", 
        "_index": "the-index", 
        "_source": result['_source'],
        "_op_type": 'update'
    } 
    for result in search_results['hits']['hits']
]

我迭代我的结果的原因是我在我的列表理解中使用了一个 if 但因为我能够看到结果我回来了我知道这不是问题。 我无法显示结果并且不得不更改属性名称,因为这是针对我工作的公司。

这是回溯:

Elasticsearch.exceptions.RequestError: 
TransportError(400, 'action_request_validation_exception',
  'Validation Failed: 1: script or doc is missing...') 

椭圆表示它对列表中的每个元素都显示相同的错误失败。

根据文档很难判断,但我发现了问题所在。 如果要进行批量更新,则需要将源代码包装在字典中,键为“doc”。 这是正确的例子,希望这有帮助!

frequency_cleared = [
    {
        '_id': result['_id'], 
        "_type": "the-type", 
        "_index": "the-index", 
        "_source": {'doc': result['_source']}, 
        '_op_type': 'update'
    } 
    for result in search_results['hits']['hits']
]

注意轻微的变化是“_source”到{'doc': result['_source']}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM