import requests from elasticsearch import Elasticsearch es = Elasticsearch() # Return a response of the top 100 IAMA Reddit posts of all time response = requests.get("http://api.reddit.com/r/iama/top/?t=all&limit=100", headers={"User-Agent":"TrackMaven"}) fields = ['title', 'selftext', 'author', 'score', 'ups', 'downs', 'num_comments', 'url', 'created'] # Loop through results and add each data dictionary to the ES "reddit" index for i, iama in enumerate(response.json()['data']['children']): content = iama['data'] doc = {} for field in fields: doc[field] = content[field] es.index(index="reddit", doc_type='iama', id=i, body=doc)