dev.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import asyncio
  2. from applications.api import AsyncElasticSearchClient
  3. async def get_crawler_task():
  4. async with AsyncElasticSearchClient() as client:
  5. # await client.es.indices.put_mapping(
  6. # index="meta_articles_v1",
  7. # body={
  8. # "properties": {
  9. # "status": {
  10. # "type": "integer",
  11. # }
  12. # }
  13. # }
  14. # )
  15. await client.es.update_by_query(
  16. index="meta_articles_v1",
  17. body={
  18. "script": {
  19. "source": "ctx._source.status = params.default",
  20. "lang": "painless",
  21. "params": {"default": 1},
  22. },
  23. "query": { # 只改那些还没有 status 的
  24. "bool": {"must_not": [{"exists": {"field": "status"}}]}
  25. },
  26. "conflicts": "proceed",
  27. },
  28. )
  29. print("success")
  30. if __name__ == "__main__":
  31. asyncio.run(get_crawler_task())