def get_by_age(age): es = elastic_instance(cloud_id, user, password) query = {"size": 10000, "query": {"match": {"age": age}}} response = es.search(index="accounts", body=query) dataframe = pd.DataFrame( [account["_source"] for account in response["hits"]["hits"]]) return dataframe
def state_df(): #Connecting to elasticsearch es = elastic_instance(cloud_id, user, password) query = {"query": {"match": {"state": "FL"}}} response = es.search(index="accounts", body=query) dataframe = pd.DataFrame( [account["_source"] for account in response["hits"]["hits"]]) return dataframe
def get_by_age_range(start, end): #start is inclusive end is exclusive es = elastic_instance(cloud_id, user, password) query = { "size": 10000, "query": { "range": { "age": { "gte": start, "lt": end } } } } response = es.search(index="accounts", body=query) dataframe = pd.DataFrame( [account["_source"] for account in response["hits"]["hits"]]) return dataframe
#Man I don't know how to import things from a parent directory in Python :s import sys sys.path.append("..") #-------------------------------------------------- from elastic.credentials import cloud_id, user, password from elastic.connection import elastic_instance #Read json file and clean the data we need f = open("../assets/accounts.json","r") lines = f.readlines() data = "" for line in lines: data += line f.close() #Connecting to elasticsearch es = elastic_instance(cloud_id, user, password) #Uploading all the data and printing the response response = es.bulk(index = "accounts", body = data) print(response["items"])