提供一个api的flask蓝图,用于访问和搜索从源数据包创建的elasticsearch索引
apies的Python项目详细描述
蜂
apies是一个flask蓝图,提供了一个api,用于访问和搜索从源数据包创建的elasticsearch索引。
端点
待定
配置
此蓝图的烧瓶配置:
fromapiesimportapies_blueprintimportelasticsearchapp.register_blueprint(apies_blueprint(['path/to/datapackage.json',Package(),...],elasticsearch.Elasticsearch(...),'index-to-search-in',document_doctype='document',dont_highlight=['fields','not.to','highlight']),url_prefix='/search/')
地方发展
您可以按照以下步骤启动本地开发服务器:
安装依赖项:
a.在本地安装Docker
b.安装python依赖项:
$ pip install dataflows datapackage-pipelines-elasticsearch $ pip install -e .
转到
sample/
目录在本地启动ElasticSearch:
$ ./start_elasticsearch.sh
此脚本将等待并轮询服务器,直到它启动并运行。 您可以自己运行来测试:
$ curl -s http://localhost:9200 {"name" : "DTsRT6T", "cluster_name" : "elasticsearch", "cluster_uuid" : "QnLVHaOYTkmJZzkCG3Hong", "version" : {"number" : "5.5.2", "build_hash" : "b2f0c09", "build_date" : "2017-08-14T12:33:14.154Z", "build_snapshot" : false, "lucene_version" : "6.6.0"}, "tagline" : "You Know, for Search"}
将数据加载到数据库中
$ python load_fixtures.py
您可以测试数据是否已加载:
$ curl -s http://localhost:9200/jobs/_count?pretty {"count" : 3516, "_shards" : {"total" : 5, "successful" : 5, "failed" : 0}}
启动示例服务器
$ python server.py * Serving Flask app "server"(lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: off * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
现在您可以访问服务器的端点,例如:
$ curl -s 'localhost:5000/api/search/jobs?q=engineering&size=2'| jq 127.0.0.1 - - [26/Jun/2019 10:45:31]"GET /api/search/jobs?q=engineering&size=2 HTTP/1.1"200 - {"search_counts": {"_current": {"total_overall": 617}}, "search_results": [{"score": 18.812, "source": {"# Of Positions": "5", "Additional Information": "TO BE APPOINTED TO ANY CIVIL <em>ENGINEERING</em> POSITION IN BRIDGES, CANDIDATES MUST POSSESS ONE YEAR OF CIVIL <em>ENGINEERING</em> EXPERIENCE IN BRIDGE DESIGN, BRIDGE CONSTRUCTION, BRIDGE MAINTENANCE OR BRIDGE INSPECTION.", "Agency": "DEPARTMENT OF TRANSPORTATION", "Business Title": "Civil Engineer 2", "Civil Service Title": "CIVIL ENGINEER", "Division/Work Unit": "<em>Engineering</em> Review & Support", ... }