简体   繁体   中英

How to expose Python api for elasticsearch

I have inserted large amount of data(1 million) in EllasticSearch . Now i want to create a REST API to fetch the data from EllasticSearch .

I want to use CURL commands (eg: curl -i http://localhost:5000/todo/api/v1.0/tasks/2 ) for being able to get the json fields having _id=2

I found the following blog https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask that helped me on how to create REST API, but i am not able to understand how do i extend this for ElasticSearch.

The elasticsearch python API is very convenient to create any kind of operation (inserting or fetching). You can find the doc's here:

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

Just one hint, in my experience the python api tended to be slower then creating direct curl requests from the command line. Anyhow, it is very convenient to work with. A query is as easy as the following snippet.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM