async , not conflict
This commit is contained in:
@@ -78,6 +78,10 @@ class ElasticHelper:
|
||||
|
||||
|
||||
|
||||
async def get_document(self, index_name, id):
|
||||
res = await self.es.get(index=index_name, id=id)
|
||||
return res
|
||||
|
||||
|
||||
# ----------------------------start---------------------------
|
||||
# متد importBulkList:
|
||||
@@ -89,7 +93,7 @@ class ElasticHelper:
|
||||
# - دادهها را به صورت bulk وارد میکند
|
||||
# - از helpers.bulk Elasticsearch استفاده میکند
|
||||
# -----------------------------end----------------------------
|
||||
async def data_pars(self, listData, index_name):
|
||||
async def data_pars_import(self, listData, index_name):
|
||||
for item in listData:
|
||||
yield(
|
||||
{
|
||||
@@ -99,11 +103,22 @@ class ElasticHelper:
|
||||
"_source": item["_source"],
|
||||
}
|
||||
)
|
||||
|
||||
async def data_pars_update(self, listData, index_name):
|
||||
for item in listData:
|
||||
yield(
|
||||
{
|
||||
"_op_type": "update",
|
||||
"_index": index_name,
|
||||
"_id": item["_id"],
|
||||
"doc": item["_source"],
|
||||
}
|
||||
)
|
||||
async def importBulkList(self, listData, index_name):
|
||||
try:
|
||||
await async_bulk(
|
||||
client=self.es,
|
||||
actions=self.data_pars(listData, index_name),
|
||||
actions=self.data_pars_import(listData, index_name),
|
||||
raise_on_error=True,
|
||||
raise_on_exception=True,
|
||||
)
|
||||
@@ -121,7 +136,7 @@ class ElasticHelper:
|
||||
try:
|
||||
await async_bulk(
|
||||
client=self.es,
|
||||
actions=self.data_pars(listData, index_name),
|
||||
actions=self.data_pars_update(listData, index_name),
|
||||
raise_on_error=raise_on_error,
|
||||
raise_on_exception=raise_on_exception,
|
||||
yield_ok=yield_ok,
|
||||
|
||||
Reference in New Issue
Block a user