How it works

This works by adding another Flask-RESTful class implementation:

class JobSearch(Resource):    def post(self):        skills = request.form['skills']        print("Request for jobs with the following skills: " + skills)        host = 'localhost'        if os.environ.get('ES_HOST'):            host = os.environ.get('ES_HOST')        print("ElasticSearch host: " + host)        es = Elasticsearch(hosts=[host])        search_definition = {            "query": {                "match": {                    "JSON.skills": {                        "query": skills,                        "operator": "AND"                    }                }            },            "_source": ["ID"]        }        try:            result = es.search(index="joblistings", doc_type="job-listing", body=search_definition)            print(result)            return result        except:            return sys.exc_info()[0]api.add_resource(JobSearch, '/', '/joblistings/search')

This class implements a post method as a resource ...

Get Python Web Scraping Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.