15

我正在尝试根据文档属性的状态更改进行批量更新。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...') 

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

4

1 回答 1

22

根据文档很难判断,但我发现了这个问题。如果要进行批量更新,则需要将源代码包装在字典中,键为“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']}

于 2016-02-03T17:47:20.467 回答