Advertisement
Typhoon

Simple Elasticsearch Search Perf Test

Jan 31st, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import requests
  5. import random
  6. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  7. requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  8.  
  9.  
  10. url = "https://my.elastic.co/elastic/year-2016/_search"
  11.  
  12. def es_get(word):
  13.     search_url = url + "?size=100" + "&q=post_content:" + word
  14.     content = requests.get(
  15.         search_url,
  16.         verify=False,
  17.         auth=("es_user", "es_pass")
  18.     )
  19.     return str(content.status_code)
  20.  
  21.  
  22. words = "Vedci v USA si myslia že imigračný a cestovný zákaz prezidenta Donalda Trumpa poškodí vedu a pokrok v oblasti výskumu Tisíce z nich preto podpísali petíciu proti Trumpovi"
  23. words = words.split(" ")
  24.  
  25. for word in words:
  26.     word = random.choice(words)
  27.     rand_string1 = word + " " + random.choice(words)
  28.     rand_string2 = word + " " + random.choice(words)
  29.     rand_string3 = word + " " + random.choice(words)
  30.     rand_string4 = random.choice(words) + random.choice(words)
  31.     print( es_get(rand_string1) + " 1 : " + rand_string1 )
  32.     print( es_get(rand_string2) + " 2 : " + rand_string2 )
  33.     print( es_get(rand_string3) + " 3 : " + rand_string3 )
  34.     print( es_get(rand_string4) + " 4 : " + rand_string4 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement