使用Python中的Elasticsearch进行批量更新



我成功地将我的文档推送到了我的Elasticsearch,并且已经在我的Kibana中进行了检查。

我当前的代码如下:

try:
res = helpers.bulk(es, my_function(df))
print("Working")
except Exception as e:
print(e)

这是";my_function";代码:

def my_function(df):
for c, line in enumerate(df):
yield {
'_index': 'my_index',
'_type': '_doc',
'_id': line.get("_id", None),
'_source': {
'field_A': line.get('field', "")
}
}
raise StopIteration

然后我想知道,如果我将来再次运行Python脚本,只将一些新文档推送到Elasticsearch会怎么样。有人知道怎么做吗?

它只取决于您发送的_id,如果它相同,则不会有任何重复,新版本将覆盖旧版本。

因此,无需担心,还不存在的新文档将被索引,现有文档的更新将覆盖其旧版本,前提是它们使用相同的_id发送。

最新更新