python - 当使用python更新文档时,Elasticsearch抛出异常 `index_failed_engine_exception`

标签 python elasticsearch

我正在尝试借助python脚本更新我的elasticsearch文档,但是在进行了一些文档更新后,出现了以下异常:

TransportError(500, u'index_failed_engine_exception', {u'status': 500, 
u'error': {u'index': u'catalog', u'root_cause': [{u'index': u'catalog', 
u'reason': u'Index failed for [variant#5a61e925ae8bdc45df6939fa]', 
u'type': u'index_failed_engine_exception', u'shard': u'3'}], 
u'caused_by': {u'reason': u'translog is already closed', u'type': 
u'already_closed_exception'}, u'shard': u'3', u'reason': u'Index failed 
for [variant#5a61e925ae8bdc45df6939fa]', u'type': 
u'index_failed_engine_exception'}})

请帮助我了解为什么会发生?

这是我的python代码:
def updateElasticDoc(sku, facilityId, reason, comment, replaceVariant):
    if sku and  replaceVariant:
        docs = getElasticSearchDoc1(sku, facilityId)
        for doc in docs:
            docC = doc['_source']
            flag = es.update(doc_type='variant', index='catalog',id=docC['facility_variant_id'],
                body={"doc": {"replaced_variant": {"pack_type" : replaceVariant['pack_type'], 
                                                    "pack_size" : replaceVariant['pack_size'], 
                                                    "drug_strength" : replaceVariant['drug_strength'],
                                                    "variant_id" : str(replaceVariant['_id']),
                                                    "name" : replaceVariant['name'], 
                                                    "sku" : replaceVariant['sku']
                                                  },
                 "status": "Retired", "variant_status" : "Retired", "reason" : reason, "variant_reason" : reason, "comment" : comment,
                 "is_retired" : True, "retired": True}})
            if flag:
                print (flag)

enter image description here

最佳答案

在elasticsearch.yml中更改设置 index.translog.sync_interval : 10s 。如果10秒不起作用,请增加尝试。

有关更多信息,请引用Translog settings

您可以按照以下步骤为索引动态更新此设置:

1)关闭索引:

POST my_index/_close

2)更新设置:
PUT my_index/_settings
{
  "index.translog.sync_interval" : "10s"
}

3)再次打开索引:
POST my_index/_open

关于python - 当使用python更新文档时,Elasticsearch抛出异常 `index_failed_engine_exception`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51338710/

相关文章:

python - Tensorflow:gradient_override_map 无法覆盖 op tf.stack 的反向梯度

python - Biopython 从变量而不是文件解析

python - 从字典绘制直方图时出错

python - 如何使用 Bulk API 通过 Python 将关键字存储在 ES 中

elasticsearch - 使用 docker compose 时使用空格传递 ES_JAVA_OPTS 变量

elasticsearch - 如果我的索引进一步增长,是否可以自动对索引进行分区

elasticsearch - ES节点失败,并出现java.lang.AssertionError:java.text.ParseException

python - pickle 剥削

python - matplotlib:调整图形窗口大小而不缩放图形内容

ubuntu - 如何在 Linux 中使用命令 systemctl restart elasticsearch?