Advertisement
yiorgos

loader.py

Oct 15th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. from datetime import datetime
  2. from faker import Faker
  3. from elasticsearch import Elasticsearch
  4. import random
  5.  
  6. fake = Faker()
  7. es = Elasticsearch()
  8.  
  9. tables = [ fake.first_name().lower() for i in range(5) ]
  10.  
  11. n = 0
  12. while True:
  13.     n += 1
  14.     doc = { 'name': fake.first_name(),
  15.         'surname': fake.last_name(),
  16.         'company': fake.company(),
  17.         'address': fake.address(),
  18.         'email': fake.ascii_safe_email(),
  19.         'timestamp': datetime.now(),
  20.     }
  21.  
  22.     t = random.choice(tables)
  23.     res = es.index(index=t, doc_type="faker", id=n, body=doc)
  24.     print("{} {}".format(n, res['result']))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement