Skip to content

Instantly share code, notes, and snippets.

@reaganscofield
Created August 23, 2019 11:22
Show Gist options
  • Select an option

  • Save reaganscofield/6d690a20cfa4c8b6792ec2d890b8e0d2 to your computer and use it in GitHub Desktop.

Select an option

Save reaganscofield/6d690a20cfa4c8b6792ec2d890b8e0d2 to your computer and use it in GitHub Desktop.
import json
import requests
import datetime
uri = 'http://docker:19200/article/_search'
open("total_output.txt","a")
class Query:
def search(uri):
output = open("total_output.txt","r+")
print("################# Last Run ###################")
print(output.read())
search_value = input("Enter a new elasticsearch value : ")
query = json.dumps({
"query": {
"wildcard": {
"url": {
"value": f"*{search_value}*"
}
}
}
})
headers = {
'Content-type': 'application/json',
'Accept': 'text/plain'
}
response = requests.get(uri, data=query, headers=headers)
results = json.loads(response.text)
print("total : {value} {name}".format(value=results['hits']['total'], name=search_value))
output.write(
f"""
Name: {search_value}
Total: {results['hits']['total']}
Date: {datetime.datetime.now():%Y-%m-%d %H:%M:%S%z}
"""
)
output.close()
data = [doc for doc in results['hits']['hits']]
for doc in data:
id = doc['_id']
Query.search(uri)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment