簡體   English   中英

如何為Elasticsearch公開Python API

[英]How to expose Python api for elasticsearch

我在EllasticSearch中插入了大量數據(一百萬)。 現在,我想創建一個REST API來從EllasticSearch中獲取數據。

我想使用CURL命令(例如: curl -i http://localhost:5000/todo/api/v1.0/tasks/2 )來獲取having _id=2的json字段

我發現以下博客https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask幫助了我如何創建REST API,但是我不明白如何我應該將此擴展為ElasticSearch。

elasticsearch python API非常便於創建任何類型的操作(插入或提取)。 您可以在以下位置找到該文檔:

https://elasticsearch-py.readthedocs.io/en/master/

只是一個提示,以我的經驗, python api速度往往比從命令行創建直接curl請求的速度慢。 無論如何,使用起來非常方便。 查詢與以下代碼段一樣簡單。

from elasticsearch import Elasticsearch
es = Elasticsearch()
res = es.index(index="index-logstash")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM