datadabllp

Python script for migrating data

Jul 8th, 2024
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. from elasticsearch import Elasticsearch as ES
  2.  
  3. # Connect to Elasticsearch
  4. es_client = ES(["http://elasticsearch:9200"])
  5.  
  6. # Connect to OpenSearch
  7. os_client = ES(["http://opensearch:9200"])
  8.  
  9. # Fetch all documents from Elasticsearch
  10. query = {"query": {"match_all": {}}}
  11. es_docs = es_client.search(index="my_index", body=query, size=10000)
  12.  
  13. # Index documents in OpenSearch
  14. for doc in es_docs["hits"]["hits"]:
  15.     os_client.index(index="my_index", body=doc["_source"])
  16.  
Advertisement
Add Comment
Please, Sign In to add comment