We will make a few small changes to our API code. The code from the previous recipe has been copied into 09/04/api.py, with the few modifications made.
- First, we add an import for elasticsearch-py:
from elasticsearch import Elasticsearch
- Now we make a quick modification to the get method of the JobListing class (I've done the same in JobListingSkills, but it's omitted here for brevity):
class JobListing(Resource): def get(self, job_listing_id): print("Request for job listing with id: " + job_listing_id) listing = get_job_listing_info(job_listing_id) es = Elasticsearch() es.index(index='joblistings', doc_type='job-listing', id=job_listing_id, body=listing) print("Got the following listing as a response: " + listing) return ...