Python 如何使用elasticsearch py在默认情况下批量设置空参数?
我目前正在尝试使用以下代码批量处理数据Python 如何使用elasticsearch py在默认情况下批量设置空参数?,python,
elasticsearch,bulk,Python,
elasticsearch,Bulk,我目前正在尝试使用以下代码批量处理数据 for i, entry in enumerate(result): aux = encode(entry) body.append({ "_index": "laborum_profiles", "_type": "profile", "_id": aux["id"], "_source": { "@timestamp": datetime.now()
for i, entry in enumerate(result):
aux = encode(entry)
body.append({
"_index": "laborum_profiles",
"_type": "profile",
"_id": aux["id"],
"_source": {
"@timestamp": datetime.now(),
"@version": "1",
"address": aux["location"] if "location" in aux else "",
# Here I'm using a function to calculate the age
"age": age_calculus(aux["birthDate"]) if "birthDate" in aux else 0,
"birthday": aux["birthDate"] if "birthDate" in aux else None,
"cellphone": aux["phones"] if "phones" in aux else [],
"country": aux["nationality"] if "nationality" in aux else "",
"creation_date": aux["createdAt"] if "createdAt" in aux else None,
}
})
helpers.bulk(es, body)
我想知道这是否是一个好的做法,如果不是,我还可以尝试什么?
我这样做是因为数据库中有大量空数据。您可以将其缩短为
aux.get(“location”),谢谢,先生,这是批量数据的好方法吗?如果没有,您能给我一些文档或示例吗?您可以将其缩短为aux.get(“location”),谢谢,先生,这是批量数据的好方法吗?如果没有,你能给我一些文件或一个例子吗?