【问题标题】:How to expose Python api for elasticsearch如何为弹性搜索公开 Python api
【发布时间】:2018-05-24 02:12:23
【问题描述】:

我在 EllasticSearch 中插入了大量数据(100 万)。现在我想创建一个 REST API 来从 EllasticSearch 获取数据。

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

我找到了以下博客https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask 这对我如何创建 REST API 有所帮助,但我无法理解如何为 ElasticSearch 扩展它。

【问题讨论】:

标签: python rest curl elasticsearch


【解决方案1】:

elasticsearch python API 非常方便地创建任何类型的操作(插入或获取)。你可以在这里找到文档:

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

只有一个提示,根据我的经验,python api 往往比从命令行创建直接 curl 请求要慢。总之,使用起来非常方便。查询就像下面的 sn-p 一样简单。

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

【讨论】:

    猜你喜欢
    • 2014-08-19
    • 2022-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 2021-05-13
    • 1970-01-01
    • 2019-11-08
    相关资源
    最近更新 更多